1Test::File::Contents(3)User Contributed Perl DocumentatioTnest::File::Contents(3)
2
3
4

NAME

6       Test::File::Contents - Test routines for examining the contents of
7       files
8

SYNOPSIS

10         use Test::File::Contents;
11
12         file_contents_eq         $file,  $string,  $description;
13         file_contents_eq_or_diff $file,  $string,  $description;
14         file_contents_like       $file,  qr/foo/,  $description;
15         file_md5sum_is           $file,  $md5sum,  $description;
16         files_eq                 $file1, $file2,   $description;
17         files_eq_or_diff         $file1, $file2,   $description;
18

DESCRIPTION

20       Got an app that generates files? Then you need to test those files to
21       make sure that their contents are correct. This module makes that easy.
22       Use its test functions to make sure that the contents of files are
23       exactly what you expect them to be.
24

INTERFACE

26   Options
27       These test functions take an optional hash reference of options which
28       may include one or more of these options:
29
30       "encoding"
31           The encoding in which the file is encoded. This will be used in an
32           I/O layer to read in the file, so that it can be properly decoded
33           to Perl's internal representation. Examples include "UTF-8",
34           "iso-8859-3", and "cp1252". See Encode::Supported for a list of
35           supported encodings. May also be specified as a layer, such as
36           ":utf8" or ":raw". See perlio for a complete list of layers.
37
38           Note that it's important to specify the encoding if you have non-
39           ASCII characters in your file. And the value to be compared against
40           (the string argument to file_contents_eq() and the regular
41           expression argument to file_contents_like(), for example, must be
42           decoded to Perl's internal form. The simplest way to do so use to
43           put
44
45             use utf8;
46
47           In your test file and write it all in "UTF-8". For example:
48
49             use utf8;
50             use Test::More tests => 1;
51             use Test::File::Contents;
52
53             file_contents_eq('utf8.txt',   'ååå', { encoding => 'UTF-8' });
54             file_contents_eq('latin1.txt', 'ååå', { encoding => 'UTF-8' });
55
56       "style"
57           The style of diff to output in the diagnostics in the case of a
58           failure in "file_contents_eq_or_diff". The possible values are:
59
60           Unified
61           Context
62           OldStyle
63           Table
64       "context"
65           Determines the amount of context displayed in diagnostic diff
66           output. If you need to seem more of the area surrounding different
67           lines, pass this option to determine how many more links you'd like
68           to see.
69
70   Test Functions
71       file_contents_eq
72
73         file_contents_eq $file, $string, $description;
74         file_contents_eq $file, $string, { encoding => 'UTF-8' };
75         file_contents_eq $file, $string, { encoding => ':bytes' }, $description;
76
77       Checks that the file's contents are equal to a string. Pass in a Unix-
78       style file name and it will be converted for the local file system.
79       Supported options:
80
81       "encoding"
82
83       The old name for this function, "file_contents_is", remains as an
84       alias.
85
86       file_contents_eq_or_diff
87
88         file_contents_eq_or_diff $file, $string, $description;
89         file_contents_eq_or_diff $file, $string, { encoding => 'UTF-8' };
90         file_contents_eq_or_diff $file, $string, { style    => 'context' }, $description;
91
92       Like file_contents_eq(), only in the event of failure, the diagnostics
93       will contain a diff instead of the full contents of the file. This can
94       make it easier to test the contents of very large text files, and where
95       only a subset of the lines are different. Supported options:
96
97       "encoding"
98       "style"
99       "context"
100
101       file_contents_ne
102
103         file_contents_ne $file, $string, $description;
104         file_contents_ne $file, $string, { encoding => 'UTF-8' };
105         file_contents_ne $file, $string, { encoding => ':bytes' }, $description;
106
107       Checks that the file's contents do not equal a string. Pass in a Unix-
108       style file name and it will be converted for the local file system.
109       Supported options:
110
111       "encoding"
112
113       The old name for this function, "file_contents_isnt", remains as an
114       alias.
115
116       file_contents_like
117
118         file_contents_like $file, qr/foo/, $description;
119         file_contents_like $file, qr/foo/, { encoding => 'UTF-8' };
120         file_contents_like $file, qr/foo/, { encoding => ':bytes' }, $description;
121
122       Checks that the contents of a file match a regular expression. The
123       regular expression must be passed as a regular expression object
124       created by "qr//".  Supported options:
125
126       "encoding"
127
128       file_contents_unlike
129
130         file_contents_unlike $file, qr/foo/, $description;
131         file_contents_unlike $file, qr/foo/, { encoding => 'UTF-8' };
132         file_contents_unlike $file, qr/foo/, { encoding => ':bytes' }, $description;
133
134       Checks that the contents of a file do not match a regular expression.
135       The regular expression must be passed as a regular expression object
136       created by "qr//". Supported options:
137
138       "encoding"
139
140       file_md5sum_is
141
142         file_md5sum_is $file, $md5sum, $description;
143         file_md5sum_is $file, $md5sum, { encoding => 'UTF-8' };
144         file_md5sum_is $file, $md5sum, { encoding => ':bytes' }, $description;
145
146       Checks whether a file matches a given MD5 checksum. The checksum should
147       be provided as a hex string, for example,
148       "6df23dc03f9b54cc38a0fc1483df6e21".  Pass in a Unix-style file name and
149       it will be converted for the local file system. Supported options:
150
151       "encoding"
152           Probably not useful unless left unset or set to ":raw".
153
154       The old name for this function, "file_md5sum", remains as an alias.
155
156       files_eq
157
158         files_eq $file1, $file2, $description;
159         files_eq $file1, $file2, { encoding => 'UTF-8' };
160         files_eq $file1, $file2, { encoding => ':bytes' }, $description;
161
162       Tests that the contents of two files are the same. Pass in a Unix-style
163       file name and it will be converted for the local file system. Supported
164       options:
165
166       "encoding"
167
168       The old name for this function, "file_contents_identical", remains as
169       an alias.
170
171       files_eq_or_diff
172
173         files_eq_or_diff $file1, $file2, $description;
174         files_eq_or_diff $file1, $file2, { encoding => 'UTF-8' };
175         files_eq_or_diff $file1, $file2, { style    => 'context' }, $description;
176
177       Like files_eq(), this function tests that the contents of two files are
178       the same. Unlike files_eq(), on failure this function outputs a diff of
179       the two files in the diagnostics. Supported options:
180
181       "encoding"
182       "style"
183       "context"
184

AUTHOR

186       Kirrily Robert
187
188       David E. Wheeler
189
191       This software is copyright (c) 2016 by David E. Wheeler.
192
193       This is free software; you can redistribute it and/or modify it under
194       the same terms as the Perl 5 programming language system itself.
195
196
197
198perl v5.36.0                      2023-01-20           Test::File::Contents(3)
Impressum