1File(3)               User Contributed Perl Documentation              File(3)
2
3
4

NAME

6       Test::File -- test file attributes
7

SYNOPSIS

9       use Test::File;
10

DESCRIPTION

12       This modules provides a collection of test utilities for file
13       attributes.
14
15       Some file attributes depend on the owner of the process testing the
16       file in the same way the file test operators do.  For instance, root
17       (or super-user or Administrator) may always be able to read files no
18       matter the permissions.
19
20       Some attributes don't make sense outside of Unix, either, so some tests
21       automatically skip if they think they won't work on the platform.  If
22       you have a way to make these functions work on Windows, for instance,
23       please send me a patch. :)
24
25   Functions
26       file_exists_ok( FILENAME [, NAME ] )
27           Ok if the file exists, and not ok otherwise.
28
29       file_not_exists_ok( FILENAME [, NAME ] )
30           Ok if the file does not exist, and not okay if it does exist.
31
32       file_empty_ok( FILENAME [, NAME ] )
33           Ok if the file exists and has empty size, not ok if the file does
34           not exist or exists with non-zero size.
35
36       file_not_empty_ok( FILENAME [, NAME ] )
37           Ok if the file exists and has non-zero size, not ok if the file
38           does not exist or exists with zero size.
39
40       file_size_ok( FILENAME, SIZE [, NAME ]  )
41           Ok if the file exists and has SIZE size in bytes (exactly), not ok
42           if the file does not exist or exists with size other than SIZE.
43
44       file_max_size_ok( FILENAME, MAX [, NAME ] )
45           Ok if the file exists and has size less than or equal to MAX bytes,
46           not ok if the file does not exist or exists with size greater than
47           MAX bytes.
48
49       file_min_size_ok( FILENAME, MIN [, NAME ] )
50           Ok if the file exists and has size greater than or equal to MIN
51           bytes, not ok if the file does not exist or exists with size less
52           than MIN bytes.
53
54       file_line_count_is( FILENAME, COUNT [, NAME ]  )
55           Ok if the file exists and has COUNT lines (exactly), not ok if the
56           file does not exist or exists with a line count than COUNT.
57
58           This function using the current value of $/ as the line ending and
59           counts the lines by reading them and counting how many it read.
60
61       file_line_count_isnt( FILENAME, COUNT [, NAME ]  )
62           Ok if the file exists and doesn't have exactly COUNT lines, not ok
63           if the file does not exist or exists with a line count of COUNT.
64           Read that carefully: the file must exist for this test to pass!
65
66           This function using the current value of $/ as the line ending and
67           counts the lines by reading them and counting how many it read.
68
69       file_line_count_between( FILENAME, MIN, MAX, [, NAME ]  )
70           Ok if the file exists and has a line count between MIN and MAX,
71           inclusively.
72
73           This function using the current value of $/ as the line ending and
74           counts the lines by reading them and counting how many it read.
75
76       file_readable_ok( FILENAME [, NAME ] )
77           Ok if the file exists and is readable, not ok if the file does not
78           exist or is not readable.
79
80       file_not_readable_ok( FILENAME [, NAME ] )
81           Ok if the file exists and is not readable, not ok if the file does
82           not exist or is readable.
83
84       file_writeable_ok( FILENAME [, NAME ] )
85           Ok if the file exists and is writeable, not ok if the file does not
86           exist or is not writeable.
87
88       file_not_writeable_ok( FILENAME [, NAME ] )
89           Ok if the file exists and is not writeable, not ok if the file does
90           not exist or is writeable.
91
92       file_executable_ok( FILENAME [, NAME ] )
93           Ok if the file exists and is executable, not ok if the file does
94           not exist or is not executable.
95
96           This test automatically skips if it thinks it is on a Windows
97           platform.
98
99       file_not_executable_ok( FILENAME [, NAME ] )
100           Ok if the file exists and is not executable, not ok if the file
101           does not exist or is executable.
102
103           This test automatically skips if it thinks it is on a Windows
104           platform.
105
106       file_mode_is( FILENAME, MODE [, NAME ] )
107           Ok if the file exists and the mode matches, not ok if the file does
108           not exist or the mode does not match.
109
110           This test automatically skips if it thinks it is on a Windows
111           platform.
112
113           Contributed by Shawn Sorichetti "<ssoriche@coloredblocks.net>"
114
115       file_mode_isnt( FILENAME, MODE [, NAME ] )
116           Ok if the file exists and mode does not match, not ok if the file
117           does not exist or mode does match.
118
119           This test automatically skips if it thinks it is on a Windows
120           platform.
121
122           Contributed by Shawn Sorichetti "<ssoriche@coloredblocks.net>"
123
124       file_is_symlink_ok( FILENAME [, NAME] )
125           Ok is FILENAME is a symlink, even if it points to a non-existent
126           file. This test automatically skips if the operating system does
127           not support symlinks. If the file does not exist, the test fails.
128
129           The optional NAME parameter is the name of the test.
130
131       symlink_target_exists_ok( SYMLINK [, TARGET] [, NAME] )
132           Ok is FILENAME is a symlink and it points to a existing file. With
133           the optional TARGET argument, the test fails if SYMLINK's target is
134           not TARGET. This test automatically skips if the operating system
135           does not support symlinks. If the file does not exist, the test
136           fails.
137
138           The optional NAME parameter is the name of the test.
139
140       symlink_target_dangles_ok( SYMLINK [, NAME] )
141           Ok if FILENAME is a symlink and if it doesn't point to a existing
142           file. This test automatically skips if the operating system does
143           not support symlinks. If the file does not exist, the test fails.
144
145           The optional NAME parameter is the name of the test.
146
147       symlink_target_is( SYMLINK, TARGET [, NAME] )
148           Ok if FILENAME is a symlink and if points to TARGET. This test
149           automatically skips if the operating system does not support
150           symlinks.  If the file does not exist, the test fails.
151
152           The optional NAME parameter is the name of the test.
153
154       symlink_target_is_absolute_ok( SYMLINK [, NAME] )
155           Ok if FILENAME is a symlink and if its target is an absolute path.
156           This test automatically skips if the operating system does not
157           support symlinks. If the file does not exist, the test fails.
158
159           The optional NAME parameter is the name of the test.
160
161           sub symlink_target_is_absolute_ok      {      if(
162           _no_symlinks_here() )           {           $Test->skip(
163                          "symlink_target_exists_ok doesn't work on systems
164           without symlinks" );           return;           }
165
166                   my $file = shift;
167                   my $name = shift || "symlink $file points to an absolute path";
168
169           my ($from, $from_base, $to, $to_base, $name) = @_; my $link   =
170           readlink( $from ); my $link_err = defined( $link ) ? '' : $!; # $!
171           doesn't always get reset my $link_abs = abs_path( rel2abs($link,
172           $from_base) ); my $to_abs  = abs_path( rel2abs($to, $to_base) );
173
174           if (defined( $link_abs ) && defined( $to_abs ) && $link_abs eq
175           $to_abs) {
176            $Test->ok( 1, $name ); } else {
177            $Test->ok( 0, $name );
178            $link   ||= 'undefined';
179            $link_abs ||= 'undefined';
180            $to_abs  ||= 'undefined';
181            $Test->diag("    link: $from");
182            $Test->diag("     got: $link");
183            $Test->diag("    (abs): $link_abs");
184            $Test->diag("  expected: $to");
185            $Test->diag("    (abs): $to_abs");
186            $Test->diag("  readlink() error: $link_err") if ($link_err); } }
187
188       link_count_is_ok( FILE, LINK_COUNT [, NAME] )
189           Ok if the link count to FILE is LINK_COUNT. LINK_COUNT is
190           interpreted as an integer. A LINK_COUNT that evaluates to 0 returns
191           Ok if the file does not exist.
192
193           The optional NAME parameter is the name of the test.
194
195       link_count_gt_ok( FILE, LINK_COUNT [, NAME] )
196           Ok if the link count to FILE is greater than LINK_COUNT. LINK_COUNT
197           is interpreted as an integer. A LINK_COUNT that evaluates to 0
198           returns Ok if the file has at least one link.
199
200           The optional NAME parameter is the name of the test.
201
202       link_count_lt_ok( FILE, LINK_COUNT [, NAME] )
203           Ok if the link count to FILE is less than LINK_COUNT. LINK_COUNT is
204           interpreted as an integer. A LINK_COUNT that evaluates to 0 returns
205           Ok if the file has at least one link.
206
207           The optional NAME parameter is the name of the test.
208
209       owner_is( FILE , OWNER [, NAME] )
210           Ok if FILE's owner is the same as OWNER.  OWNER may be a text user
211           name or a numeric userid.  Test skips on Dos, and Mac OS <= 9.  If
212           the file does not exist, the test fails.
213
214           The optional NAME parameter is the name of the test.
215
216           Contributed by Dylan Martin
217
218       owner_isnt( FILE, OWNER [, NAME] )
219           Ok if FILE's owner is not the same as OWNER.  OWNER may be a text
220           user name or a numeric userid.  Test skips on Dos and Mac OS <= 9.
221           If the file does not exist, the test fails.
222
223           The optional NAME parameter is the name of the test.
224
225           Contributed by Dylan Martin
226
227       group_is( FILE , GROUP [, NAME] )
228           Ok if FILE's group is the same as GROUP.  GROUP may be a text group
229           name or a numeric group id.  Test skips on Dos, Mac OS <= 9 and any
230           other operating systems that do not support getpwuid() and friends.
231           If the file does not exist, the test fails.
232
233           The optional NAME parameter is the name of the test.
234
235           Contributed by Dylan Martin
236
237       group_isnt( FILE , GROUP [, NAME] )
238           Ok if FILE's group is not the same as GROUP.  GROUP may be a text
239           group name or a numeric group id.  Test skips on Dos, Mac OS <= 9
240           and any other operating systems that do not support getpwuid() and
241           friends.  If the file does not exist, the test fails.
242
243           The optional NAME parameter is the name of the test.
244
245           Contributed by Dylan Martin
246

TO DO

248       * check properties for other users (readable_by_root, for instance)
249
250       * check times
251
252       * check number of links to file
253
254       * check path parts (directory, filename, extension)
255

SEE ALSO

257       Test::Builder, Test::More
258

SOURCE AVAILABILITY

260       This module is in Github:
261
262               git://github.com/briandfoy/test-file.git
263

AUTHOR

265       brian d foy, "<bdfoy@cpan.org>"
266

CREDITS

268       Shawn Sorichetti "<ssoriche@coloredblocks.net>" provided some
269       functions.
270
271       Tom Metro helped me figure out some Windows capabilities.
272
273       Dylan Martin added "owner_is" and "owner_isnt"
274
275       David Wheeler added "file_line_count_is".
276
278       Copyright (c) 2002-2009 brian d foy.  All rights reserved.
279
280       This program is free software; you can redistribute it and/or modify it
281       under the same terms as Perl itself.
282
283
284
285perl v5.12.1                      2009-06-10                           File(3)
Impressum