File Coverage

blib/lib/Test/File/Contents.pm
Criterion Covered Total %
statement 81 84 96.4
branch 25 32 78.1
condition 18 33 54.5
subroutine 27 27 100.0
pod 8 8 100.0
total 159 184 86.4


line stmt bran cond sub pod time code
1             package Test::File::Contents;
2              
3 1     1   61730 use 5.008003;
  1         3  
4 1     1   5 use warnings;
  1         2  
  1         24  
5 1     1   4 use strict;
  1         3  
  1         38  
6              
7             =encoding utf8
8              
9             =head1 NAME
10              
11             Test::File::Contents - Test routines for examining the contents of files
12              
13             =cut
14              
15             our $VERSION = '0.240';
16              
17 1     1   5 use Test::Builder;
  1         2  
  1         22  
18 1     1   5 use Digest::MD5;
  1         2  
  1         27  
19 1     1   4 use File::Spec;
  1         2  
  1         23  
20 1     1   431 use Text::Diff;
  1         7210  
  1         1346  
21              
22             require Exporter;
23             our @ISA = qw(Exporter);
24             our @EXPORT = qw(
25             file_contents_eq
26             file_contents_eq_or_diff
27             file_contents_ne
28             file_contents_like
29             file_contents_unlike
30             file_md5sum_is
31             files_eq
32             files_eq_or_diff
33              
34             file_contents_is
35             file_contents_isnt
36             file_md5sum
37             file_contents_identical
38             );
39              
40             my $Test = Test::Builder->new;
41              
42             =head1 SYNOPSIS
43              
44             use Test::File::Contents;
45              
46             file_contents_eq $file, $string, $description;
47             file_contents_eq_or_diff $file, $string, $description;
48             file_contents_like $file, qr/foo/, $description;
49             file_md5sum_is $file, $md5sum, $description;
50             files_eq $file1, $file2, $description;
51             files_eq_or_diff $file1, $file2, $description;
52              
53             =head1 DESCRIPTION
54              
55             Got an app that generates files? Then you need to test those files to make
56             sure that their contents are correct. This module makes that easy. Use its
57             test functions to make sure that the contents of files are exactly what you
58             expect them to be.
59              
60             =head1 INTERFACE
61              
62             =head2 Options
63              
64             These test functions take an optional hash reference of options which may
65             include one or more of these options:
66              
67             =over
68              
69             =item C
70              
71             The encoding in which the file is encoded. This will be used in an I/O layer
72             to read in the file, so that it can be properly decoded to Perl's internal
73             representation. Examples include C, C, and C. See
74             L for a list of supported encodings. May also be specified
75             as a layer, such as ":utf8" or ":raw". See L for a complete list of
76             layers.
77              
78             Note that it's important to specify the encoding if you have non-ASCII
79             characters in your file. And the value to be compared against (the string
80             argument to C and the regular expression argument to
81             C, for example, must be decoded to Perl's internal
82             form. The simplest way to do so use to put
83              
84             use utf8;
85              
86             In your test file and write it all in C. For example:
87              
88             use utf8;
89             use Test::More tests => 1;
90             use Test::File::Contents;
91              
92             file_contents_eq('utf8.txt', 'ååå', { encoding => 'UTF-8' });
93             file_contents_eq('latin1.txt', 'ååå', { encoding => 'UTF-8' });
94              
95             =item C