package Test::File::Contents; use 5.008003; use warnings; use strict; =encoding utf8 =head1 NAME Test::File::Contents - Test routines for examining the contents of files =cut our $VERSION = '0.242'; use Test::Builder; use Digest::MD5; use File::Spec; use Text::Diff; BEGIN { require Exporter; *import = \&Exporter::import } our @EXPORT = qw( file_contents_eq file_contents_eq_or_diff file_contents_ne file_contents_like file_contents_unlike file_md5sum_is files_eq files_eq_or_diff file_contents_is file_contents_isnt file_md5sum file_contents_identical ); my $Test = Test::Builder->new; =head1 SYNOPSIS use Test::File::Contents; file_contents_eq $file, $string, $description; file_contents_eq_or_diff $file, $string, $description; file_contents_like $file, qr/foo/, $description; file_md5sum_is $file, $md5sum, $description; files_eq $file1, $file2, $description; files_eq_or_diff $file1, $file2, $description; =head1 DESCRIPTION Got an app that generates files? Then you need to test those files to make sure that their contents are correct. This module makes that easy. Use its test functions to make sure that the contents of files are exactly what you expect them to be. =head1 INTERFACE =head2 Options These test functions take an optional hash reference of options which may include one or more of these options: =over =item C The encoding in which the file is encoded. This will be used in an I/O layer to read in the file, so that it can be properly decoded to Perl's internal representation. Examples include C, C, and C. See L for a list of supported encodings. May also be specified as a layer, such as ":utf8" or ":raw". See L for a complete list of layers. Note that it's important to specify the encoding if you have non-ASCII characters in your file. And the value to be compared against (the string argument to C and the regular expression argument to C, for example, must be decoded to Perl's internal form. The simplest way to do so use to put use utf8; In your test file and write it all in C. For example: use utf8; use Test::More tests => 1; use Test::File::Contents; file_contents_eq('utf8.txt', 'ååå', { encoding => 'UTF-8' }); file_contents_eq('latin1.txt', 'ååå', { encoding => 'UTF-8' }); =item C