Commit | Line | Data |
---|---|---|
3fa6e24b | 1 | #!./perl |
81793b90 GS |
2 | |
3 | ||
3fa6e24b TW |
4 | my %Expect_File = (); # what we expect for $_ |
5 | my %Expect_Name = (); # what we expect for $File::Find::name/fullname | |
6 | my %Expect_Dir = (); # what we expect for $File::Find::dir | |
81793b90 | 7 | my $symlink_exists = eval { symlink("",""); 1 }; |
7e47e6ff | 8 | my $warn_msg; |
3fa6e24b | 9 | |
1a3850a5 GA |
10 | |
11 | BEGIN { | |
12 | chdir 't' if -d 't'; | |
9f826d6a | 13 | unshift @INC => '../lib'; |
7e47e6ff | 14 | |
3fa6e24b | 15 | $SIG{'__WARN__'} = sub { $warn_msg = $_[0]; warn "# $_[0]"; } |
1a3850a5 GA |
16 | } |
17 | ||
bc125c03 NC |
18 | if ( $symlink_exists ) { print "1..195\n"; } |
19 | else { print "1..85\n"; } | |
1a3850a5 | 20 | |
7dc9aaa5 MS |
21 | # Uncomment this to see where File::Find is chdir'ing to. Helpful for |
22 | # debugging its little jaunts around the filesystem. | |
23 | # BEGIN { | |
24 | # use Cwd; | |
25 | # *CORE::GLOBAL::chdir = sub ($) { | |
26 | # my($file, $line) = (caller)[1,2]; | |
27 | # | |
28 | # printf "# cwd: %s\n", cwd(); | |
29 | # print "# chdir: @_ from $file at $line\n"; | |
30 | # my($return) = CORE::chdir($_[0]); | |
31 | # printf "# newcwd: %s\n", cwd(); | |
32 | # | |
33 | # return $return; | |
34 | # }; | |
35 | # } | |
36 | ||
37 | ||
ea05ec2d CL |
38 | BEGIN { |
39 | use File::Spec; | |
40 | if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'VMS') | |
41 | { | |
42 | # This is a hack - at present File::Find does not produce native names on | |
43 | # Win32 or VMS, so force File::Spec to use Unix names. | |
44 | # must be set *before* importing File::Find | |
45 | require File::Spec::Unix; | |
46 | @File::Spec::ISA = 'File::Spec::Unix'; | |
47 | } | |
48 | require File::Find; | |
49 | import File::Find; | |
50 | } | |
6455dd3b | 51 | |
c80f55d1 JH |
52 | cleanup(); |
53 | ||
912440be NC |
54 | $::count_commonsense = 0; |
55 | find({wanted => sub { ++$::count_commonsense if $_ eq 'commonsense.t'; } }, | |
bb7dc48b | 56 | File::Spec->curdir); |
912440be NC |
57 | if ($::count_commonsense == 1) { |
58 | print "ok 1\n"; | |
59 | } else { | |
60 | print "not ok 1 # found $::count_commonsense files named 'commonsense.t'\n"; | |
61 | } | |
3fa6e24b | 62 | |
912440be NC |
63 | $::count_commonsense = 0; |
64 | finddepth({wanted => sub { ++$::count_commonsense if $_ eq 'commonsense.t'; } }, | |
bb7dc48b | 65 | File::Spec->curdir); |
912440be NC |
66 | if ($::count_commonsense == 1) { |
67 | print "ok 2\n"; | |
68 | } else { | |
69 | print "not ok 2 # found $::count_commonsense files named 'commonsense.t'\n"; | |
70 | } | |
6455dd3b | 71 | |
81793b90 | 72 | my $case = 2; |
5eb85357 | 73 | my $FastFileTests_OK = 0; |
81793b90 | 74 | |
c80f55d1 | 75 | sub cleanup { |
3fa6e24b TW |
76 | if (-d dir_path('for_find')) { |
77 | chdir(dir_path('for_find')); | |
6fecce66 RGS |
78 | } |
79 | if (-d dir_path('fa')) { | |
80 | unlink file_path('fa', 'fa_ord'), | |
81 | file_path('fa', 'fsl'), | |
82 | file_path('fa', 'faa', 'faa_ord'), | |
83 | file_path('fa', 'fab', 'fab_ord'), | |
84 | file_path('fa', 'fab', 'faba', 'faba_ord'), | |
85 | file_path('fb', 'fb_ord'), | |
86 | file_path('fb', 'fba', 'fba_ord'); | |
87 | rmdir dir_path('fa', 'faa'); | |
88 | rmdir dir_path('fa', 'fab', 'faba'); | |
89 | rmdir dir_path('fa', 'fab'); | |
90 | rmdir dir_path('fa'); | |
91 | rmdir dir_path('fb', 'fba'); | |
92 | rmdir dir_path('fb'); | |
93 | } | |
94 | chdir(File::Spec->updir); | |
95 | if (-d dir_path('for_find')) { | |
96 | rmdir dir_path('for_find') or print "# Can't rmdir for_find: $!\n"; | |
c80f55d1 JH |
97 | } |
98 | } | |
99 | ||
81793b90 | 100 | END { |
c80f55d1 | 101 | cleanup(); |
81793b90 GS |
102 | } |
103 | ||
104 | sub Check($) { | |
3fa6e24b TW |
105 | $case++; |
106 | if ($_[0]) { print "ok $case\n"; } | |
107 | else { print "not ok $case\n"; } | |
81793b90 GS |
108 | } |
109 | ||
110 | sub CheckDie($) { | |
3fa6e24b TW |
111 | $case++; |
112 | if ($_[0]) { print "ok $case\n"; } | |
113 | else { print "not ok $case\n $!\n"; exit 0; } | |
81793b90 GS |
114 | } |
115 | ||
116 | sub touch { | |
3fa6e24b | 117 | CheckDie( open(my $T,'>',$_[0]) ); |
81793b90 GS |
118 | } |
119 | ||
120 | sub MkDir($$) { | |
3fa6e24b | 121 | CheckDie( mkdir($_[0],$_[1]) ); |
81793b90 GS |
122 | } |
123 | ||
3fa6e24b TW |
124 | sub wanted_File_Dir { |
125 | print "# \$File::Find::dir => '$File::Find::dir'\n"; | |
126 | print "# \$_ => '$_'\n"; | |
127 | s#\.$## if ($^O eq 'VMS' && $_ ne '.'); | |
128 | Check( $Expect_File{$_} ); | |
129 | if ( $FastFileTests_OK ) { | |
130 | delete $Expect_File{ $_} | |
131 | unless ( $Expect_Dir{$_} && ! -d _ ); | |
132 | } else { | |
133 | delete $Expect_File{$_} | |
134 | unless ( $Expect_Dir{$_} && ! -d $_ ); | |
135 | } | |
136 | } | |
7e47e6ff | 137 | |
3fa6e24b TW |
138 | sub wanted_File_Dir_prune { |
139 | &wanted_File_Dir; | |
140 | $File::Find::prune=1 if $_ eq 'faba'; | |
81793b90 GS |
141 | } |
142 | ||
3fa6e24b TW |
143 | sub wanted_Name { |
144 | my $n = $File::Find::name; | |
145 | $n =~ s#\.$## if ($^O eq 'VMS' && $n ne '.'); | |
146 | print "# \$File::Find::name => '$n'\n"; | |
147 | my $i = rindex($n,'/'); | |
148 | my $OK = exists($Expect_Name{$n}); | |
149 | unless ($^O eq 'MacOS') { | |
150 | if ( $OK ) { | |
151 | $OK= exists($Expect_Name{substr($n,0,$i)}) if $i >= 0; | |
152 | } | |
7e47e6ff | 153 | } |
3fa6e24b TW |
154 | Check($OK); |
155 | delete $Expect_Name{$n}; | |
57907763 GS |
156 | } |
157 | ||
3fa6e24b TW |
158 | sub wanted_File { |
159 | print "# \$_ => '$_'\n"; | |
160 | s#\.$## if ($^O eq 'VMS' && $_ ne '.'); | |
161 | my $i = rindex($_,'/'); | |
162 | my $OK = exists($Expect_File{ $_}); | |
163 | unless ($^O eq 'MacOS') { | |
164 | if ( $OK ) { | |
165 | $OK= exists($Expect_File{ substr($_,0,$i)}) if $i >= 0; | |
166 | } | |
7e47e6ff | 167 | } |
3fa6e24b TW |
168 | Check($OK); |
169 | delete $Expect_File{ $_}; | |
57907763 GS |
170 | } |
171 | ||
7e47e6ff | 172 | sub simple_wanted { |
3fa6e24b TW |
173 | print "# \$File::Find::dir => '$File::Find::dir'\n"; |
174 | print "# \$_ => '$_'\n"; | |
7e47e6ff JH |
175 | } |
176 | ||
177 | sub noop_wanted {} | |
78eac027 | 178 | |
7e47e6ff | 179 | sub my_preprocess { |
3fa6e24b TW |
180 | @files = @_; |
181 | print "# --preprocess--\n"; | |
182 | print "# \$File::Find::dir => '$File::Find::dir' \n"; | |
183 | foreach $file (@files) { | |
30db15be | 184 | $file =~ s/\.(dir)?$// if $^O eq 'VMS'; |
3fa6e24b TW |
185 | print "# $file \n"; |
186 | delete $Expect_Dir{ $File::Find::dir }->{$file}; | |
187 | } | |
188 | print "# --end preprocess--\n"; | |
189 | Check(scalar(keys %{$Expect_Dir{ $File::Find::dir }}) == 0); | |
190 | if (scalar(keys %{$Expect_Dir{ $File::Find::dir }}) == 0) { | |
191 | delete $Expect_Dir{ $File::Find::dir } | |
192 | } | |
193 | return @files; | |
7e47e6ff JH |
194 | } |
195 | ||
196 | sub my_postprocess { | |
3fa6e24b TW |
197 | print "# postprocess: \$File::Find::dir => '$File::Find::dir' \n"; |
198 | delete $Expect_Dir{ $File::Find::dir}; | |
7e47e6ff JH |
199 | } |
200 | ||
201 | ||
bb7dc48b JH |
202 | # Use dir_path() to specify a directory path that's expected for |
203 | # $File::Find::dir (%Expect_Dir). Also use it in file operations like | |
204 | # chdir, rmdir etc. | |
3fa6e24b | 205 | # |
2586ba89 | 206 | # dir_path() concatenates directory names to form a *relative* |
30db15be | 207 | # directory path, independent from the platform it's run on, although |
2586ba89 | 208 | # there are limitations. Don't try to create an absolute path, |
bb7dc48b | 209 | # because that may fail on operating systems that have the concept of |
2586ba89 JH |
210 | # volume names (e.g. Mac OS). As a special case, you can pass it a "." |
211 | # as first argument, to create a directory path like "./fa/dir" on | |
bb7dc48b JH |
212 | # operating systems other than Mac OS (actually, Mac OS will ignore |
213 | # the ".", if it's the first argument). If there's no second argument, | |
214 | # this function will return the empty string on Mac OS and the string | |
215 | # "./" otherwise. | |
3fa6e24b TW |
216 | |
217 | sub dir_path { | |
2586ba89 | 218 | my $first_arg = shift @_; |
3fa6e24b | 219 | |
2586ba89 | 220 | if ($first_arg eq '.') { |
3fa6e24b TW |
221 | if ($^O eq 'MacOS') { |
222 | return '' unless @_; | |
223 | # ignore first argument; return a relative path | |
224 | # with leading ":" and with trailing ":" | |
2586ba89 | 225 | return File::Spec->catdir(@_); |
3fa6e24b TW |
226 | } else { # other OS |
227 | return './' unless @_; | |
228 | my $path = File::Spec->catdir(@_); | |
229 | # add leading "./" | |
230 | $path = "./$path"; | |
231 | return $path; | |
232 | } | |
233 | ||
2586ba89 JH |
234 | } else { # $first_arg ne '.' |
235 | return $first_arg unless @_; # return plain filename | |
236 | return File::Spec->catdir($first_arg, @_); # relative path | |
3fa6e24b TW |
237 | } |
238 | } | |
7e47e6ff | 239 | |
7e47e6ff | 240 | |
bb7dc48b | 241 | # Use topdir() to specify a directory path that you want to pass to |
2586ba89 JH |
242 | # find/finddepth. Basically, topdir() does the same as dir_path() (see |
243 | # above), except that there's no trailing ":" on Mac OS. | |
7e47e6ff | 244 | |
3fa6e24b TW |
245 | sub topdir { |
246 | my $path = dir_path(@_); | |
247 | $path =~ s/:$// if ($^O eq 'MacOS'); | |
248 | return $path; | |
249 | } | |
7e47e6ff | 250 | |
7e47e6ff | 251 | |
bb7dc48b | 252 | # Use file_path() to specify a file path that's expected for $_ |
2586ba89 | 253 | # (%Expect_File). Also suitable for file operations like unlink etc. |
3fa6e24b | 254 | # |
bb7dc48b | 255 | # file_path() concatenates directory names (if any) and a filename to |
2586ba89 | 256 | # form a *relative* file path (the last argument is assumed to be a |
30db15be | 257 | # file). It's independent from the platform it's run on, although |
2586ba89 JH |
258 | # there are limitations. As a special case, you can pass it a "." as |
259 | # first argument, to create a file path like "./fa/file" on operating | |
260 | # systems other than Mac OS (actually, Mac OS will ignore the ".", if | |
261 | # it's the first argument). If there's no second argument, this | |
262 | # function will return the empty string on Mac OS and the string "./" | |
263 | # otherwise. | |
3fa6e24b TW |
264 | |
265 | sub file_path { | |
2586ba89 | 266 | my $first_arg = shift @_; |
3fa6e24b | 267 | |
2586ba89 | 268 | if ($first_arg eq '.') { |
3fa6e24b TW |
269 | if ($^O eq 'MacOS') { |
270 | return '' unless @_; | |
271 | # ignore first argument; return a relative path | |
272 | # with leading ":", but without trailing ":" | |
2586ba89 | 273 | return File::Spec->catfile(@_); |
3fa6e24b TW |
274 | } else { # other OS |
275 | return './' unless @_; | |
276 | my $path = File::Spec->catfile(@_); | |
277 | # add leading "./" | |
278 | $path = "./$path"; | |
279 | return $path; | |
280 | } | |
281 | ||
2586ba89 JH |
282 | } else { # $first_arg ne '.' |
283 | return $first_arg unless @_; # return plain filename | |
284 | return File::Spec->catfile($first_arg, @_); # relative path | |
7e47e6ff | 285 | } |
3fa6e24b TW |
286 | } |
287 | ||
288 | ||
bb7dc48b JH |
289 | # Use file_path_name() to specify a file path that's expected for |
290 | # $File::Find::Name (%Expect_Name). Note: When the no_chdir => 1 | |
291 | # option is in effect, $_ is the same as $File::Find::Name. In that | |
292 | # case, also use this function to specify a file path that's expected | |
293 | # for $_. | |
3fa6e24b | 294 | # |
bb7dc48b JH |
295 | # Basically, file_path_name() does the same as file_path() (see |
296 | # above), except that there's always a leading ":" on Mac OS, even for | |
297 | # plain file/directory names. | |
3fa6e24b TW |
298 | |
299 | sub file_path_name { | |
300 | my $path = file_path(@_); | |
301 | $path = ":$path" if (($^O eq 'MacOS') && ($path !~ /:/)); | |
302 | return $path; | |
303 | } | |
304 | ||
7e47e6ff | 305 | |
3fa6e24b TW |
306 | |
307 | MkDir( dir_path('for_find'), 0770 ); | |
308 | CheckDie(chdir( dir_path('for_find'))); | |
309 | MkDir( dir_path('fa'), 0770 ); | |
310 | MkDir( dir_path('fb'), 0770 ); | |
311 | touch( file_path('fb', 'fb_ord') ); | |
312 | MkDir( dir_path('fb', 'fba'), 0770 ); | |
313 | touch( file_path('fb', 'fba', 'fba_ord') ); | |
314 | if ($^O eq 'MacOS') { | |
315 | CheckDie( symlink(':fb',':fa:fsl') ) if $symlink_exists; | |
7e47e6ff | 316 | } else { |
3fa6e24b TW |
317 | CheckDie( symlink('../fb','fa/fsl') ) if $symlink_exists; |
318 | } | |
319 | touch( file_path('fa', 'fa_ord') ); | |
320 | ||
321 | MkDir( dir_path('fa', 'faa'), 0770 ); | |
322 | touch( file_path('fa', 'faa', 'faa_ord') ); | |
323 | MkDir( dir_path('fa', 'fab'), 0770 ); | |
324 | touch( file_path('fa', 'fab', 'fab_ord') ); | |
325 | MkDir( dir_path('fa', 'fab', 'faba'), 0770 ); | |
326 | touch( file_path('fa', 'fab', 'faba', 'faba_ord') ); | |
327 | ||
328 | ||
bb7dc48b JH |
329 | %Expect_File = (File::Spec->curdir => 1, file_path('fsl') => 1, |
330 | file_path('fa_ord') => 1, file_path('fab') => 1, | |
331 | file_path('fab_ord') => 1, file_path('faba') => 1, | |
3fa6e24b | 332 | file_path('faa') => 1, file_path('faa_ord') => 1); |
bb7dc48b | 333 | |
3fa6e24b TW |
334 | delete $Expect_File{ file_path('fsl') } unless $symlink_exists; |
335 | %Expect_Name = (); | |
bb7dc48b JH |
336 | |
337 | %Expect_Dir = ( dir_path('fa') => 1, dir_path('faa') => 1, | |
338 | dir_path('fab') => 1, dir_path('faba') => 1, | |
3fa6e24b | 339 | dir_path('fb') => 1, dir_path('fba') => 1); |
bb7dc48b | 340 | |
3fa6e24b TW |
341 | delete @Expect_Dir{ dir_path('fb'), dir_path('fba') } unless $symlink_exists; |
342 | File::Find::find( {wanted => \&wanted_File_Dir_prune}, topdir('fa') ); | |
343 | Check( scalar(keys %Expect_File) == 0 ); | |
344 | ||
345 | ||
346 | print "# check re-entrancy\n"; | |
bb7dc48b JH |
347 | |
348 | %Expect_File = (File::Spec->curdir => 1, file_path('fsl') => 1, | |
349 | file_path('fa_ord') => 1, file_path('fab') => 1, | |
350 | file_path('fab_ord') => 1, file_path('faba') => 1, | |
3fa6e24b | 351 | file_path('faa') => 1, file_path('faa_ord') => 1); |
bb7dc48b | 352 | |
3fa6e24b TW |
353 | delete $Expect_File{ file_path('fsl') } unless $symlink_exists; |
354 | %Expect_Name = (); | |
bb7dc48b JH |
355 | |
356 | %Expect_Dir = ( dir_path('fa') => 1, dir_path('faa') => 1, | |
357 | dir_path('fab') => 1, dir_path('faba') => 1, | |
3fa6e24b | 358 | dir_path('fb') => 1, dir_path('fba') => 1); |
bb7dc48b | 359 | |
3fa6e24b | 360 | delete @Expect_Dir{ dir_path('fb'), dir_path('fba') } unless $symlink_exists; |
bb7dc48b JH |
361 | |
362 | File::Find::find( {wanted => sub { wanted_File_Dir_prune(); | |
363 | File::Find::find( {wanted => sub | |
364 | {} }, File::Spec->curdir ); } }, | |
365 | topdir('fa') ); | |
366 | ||
3fa6e24b TW |
367 | Check( scalar(keys %Expect_File) == 0 ); |
368 | ||
369 | ||
370 | # no_chdir is in effect, hence we use file_path_name to specify the expected paths for %Expect_File | |
bb7dc48b JH |
371 | |
372 | %Expect_File = (file_path_name('fa') => 1, | |
373 | file_path_name('fa', 'fsl') => 1, | |
374 | file_path_name('fa', 'fa_ord') => 1, | |
375 | file_path_name('fa', 'fab') => 1, | |
376 | file_path_name('fa', 'fab', 'fab_ord') => 1, | |
377 | file_path_name('fa', 'fab', 'faba') => 1, | |
378 | file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, | |
379 | file_path_name('fa', 'faa') => 1, | |
380 | file_path_name('fa', 'faa', 'faa_ord') => 1,); | |
381 | ||
3fa6e24b TW |
382 | delete $Expect_File{ file_path_name('fa', 'fsl') } unless $symlink_exists; |
383 | %Expect_Name = (); | |
bb7dc48b JH |
384 | |
385 | %Expect_Dir = (dir_path('fa') => 1, | |
386 | dir_path('fa', 'faa') => 1, | |
387 | dir_path('fa', 'fab') => 1, | |
388 | dir_path('fa', 'fab', 'faba') => 1, | |
389 | dir_path('fb') => 1, | |
390 | dir_path('fb', 'fba') => 1); | |
391 | ||
392 | delete @Expect_Dir{ dir_path('fb'), dir_path('fb', 'fba') } | |
393 | unless $symlink_exists; | |
394 | ||
395 | File::Find::find( {wanted => \&wanted_File_Dir, no_chdir => 1}, | |
396 | topdir('fa') ); Check( scalar(keys %Expect_File) == 0 ); | |
3fa6e24b TW |
397 | |
398 | ||
399 | %Expect_File = (); | |
bb7dc48b JH |
400 | |
401 | %Expect_Name = (File::Spec->curdir => 1, | |
402 | file_path_name('.', 'fa') => 1, | |
403 | file_path_name('.', 'fa', 'fsl') => 1, | |
404 | file_path_name('.', 'fa', 'fa_ord') => 1, | |
405 | file_path_name('.', 'fa', 'fab') => 1, | |
406 | file_path_name('.', 'fa', 'fab', 'fab_ord') => 1, | |
407 | file_path_name('.', 'fa', 'fab', 'faba') => 1, | |
408 | file_path_name('.', 'fa', 'fab', 'faba', 'faba_ord') => 1, | |
409 | file_path_name('.', 'fa', 'faa') => 1, | |
410 | file_path_name('.', 'fa', 'faa', 'faa_ord') => 1, | |
411 | file_path_name('.', 'fb') => 1, | |
412 | file_path_name('.', 'fb', 'fba') => 1, | |
413 | file_path_name('.', 'fb', 'fba', 'fba_ord') => 1, | |
414 | file_path_name('.', 'fb', 'fb_ord') => 1); | |
415 | ||
3fa6e24b TW |
416 | delete $Expect_Name{ file_path('.', 'fa', 'fsl') } unless $symlink_exists; |
417 | %Expect_Dir = (); | |
418 | File::Find::finddepth( {wanted => \&wanted_Name}, File::Spec->curdir ); | |
419 | Check( scalar(keys %Expect_Name) == 0 ); | |
420 | ||
421 | ||
bb7dc48b JH |
422 | # no_chdir is in effect, hence we use file_path_name to specify the |
423 | # expected paths for %Expect_File | |
424 | ||
425 | %Expect_File = (File::Spec->curdir => 1, | |
426 | file_path_name('.', 'fa') => 1, | |
427 | file_path_name('.', 'fa', 'fsl') => 1, | |
428 | file_path_name('.', 'fa', 'fa_ord') => 1, | |
429 | file_path_name('.', 'fa', 'fab') => 1, | |
430 | file_path_name('.', 'fa', 'fab', 'fab_ord') => 1, | |
431 | file_path_name('.', 'fa', 'fab', 'faba') => 1, | |
432 | file_path_name('.', 'fa', 'fab', 'faba', 'faba_ord') => 1, | |
433 | file_path_name('.', 'fa', 'faa') => 1, | |
434 | file_path_name('.', 'fa', 'faa', 'faa_ord') => 1, | |
435 | file_path_name('.', 'fb') => 1, | |
436 | file_path_name('.', 'fb', 'fba') => 1, | |
437 | file_path_name('.', 'fb', 'fba', 'fba_ord') => 1, | |
438 | file_path_name('.', 'fb', 'fb_ord') => 1); | |
439 | ||
3fa6e24b TW |
440 | delete $Expect_File{ file_path_name('.', 'fa', 'fsl') } unless $symlink_exists; |
441 | %Expect_Name = (); | |
442 | %Expect_Dir = (); | |
bb7dc48b JH |
443 | |
444 | File::Find::finddepth( {wanted => \&wanted_File, no_chdir => 1}, | |
445 | File::Spec->curdir ); | |
446 | ||
3fa6e24b TW |
447 | Check( scalar(keys %Expect_File) == 0 ); |
448 | ||
449 | ||
450 | print "# check preprocess\n"; | |
451 | %Expect_File = (); | |
452 | %Expect_Name = (); | |
453 | %Expect_Dir = ( | |
454 | File::Spec->curdir => {fa => 1, fb => 1}, | |
455 | dir_path('.', 'fa') => {faa => 1, fab => 1, fa_ord => 1}, | |
456 | dir_path('.', 'fa', 'faa') => {faa_ord => 1}, | |
457 | dir_path('.', 'fa', 'fab') => {faba => 1, fab_ord => 1}, | |
458 | dir_path('.', 'fa', 'fab', 'faba') => {faba_ord => 1}, | |
459 | dir_path('.', 'fb') => {fba => 1, fb_ord => 1}, | |
460 | dir_path('.', 'fb', 'fba') => {fba_ord => 1} | |
461 | ); | |
bb7dc48b JH |
462 | |
463 | File::Find::find( {wanted => \&noop_wanted, | |
464 | preprocess => \&my_preprocess}, File::Spec->curdir ); | |
465 | ||
3fa6e24b TW |
466 | Check( scalar(keys %Expect_Dir) == 0 ); |
467 | ||
468 | ||
469 | print "# check postprocess\n"; | |
470 | %Expect_File = (); | |
471 | %Expect_Name = (); | |
472 | %Expect_Dir = ( | |
473 | File::Spec->curdir => 1, | |
474 | dir_path('.', 'fa') => 1, | |
475 | dir_path('.', 'fa', 'faa') => 1, | |
476 | dir_path('.', 'fa', 'fab') => 1, | |
477 | dir_path('.', 'fa', 'fab', 'faba') => 1, | |
478 | dir_path('.', 'fb') => 1, | |
479 | dir_path('.', 'fb', 'fba') => 1 | |
480 | ); | |
bb7dc48b JH |
481 | |
482 | File::Find::find( {wanted => \&noop_wanted, | |
483 | postprocess => \&my_postprocess}, File::Spec->curdir ); | |
484 | ||
3fa6e24b TW |
485 | Check( scalar(keys %Expect_Dir) == 0 ); |
486 | ||
17ab9c14 JB |
487 | { |
488 | print "# checking argument localization\n"; | |
489 | ||
490 | ### this checks the fix of perlbug [19977] ### | |
491 | my @foo = qw( a b c d e f ); | |
492 | my %pre = map { $_ => } @foo; | |
493 | ||
494 | File::Find::find( sub { } , 'fa' ) for @foo; | |
495 | delete $pre{$_} for @foo; | |
496 | ||
497 | Check( scalar( keys %pre ) == 0 ); | |
498 | } | |
3fa6e24b | 499 | |
bc125c03 NC |
500 | # see thread starting |
501 | # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2004-02/msg00351.html | |
502 | { | |
503 | print "# checking that &_ and %_ are still accessible and that\n", | |
504 | "# tie magic on \$_ is not triggered\n"; | |
505 | ||
506 | my $true_count; | |
507 | my $sub = 0; | |
508 | sub _ { | |
509 | ++$sub; | |
510 | } | |
511 | my $tie_called = 0; | |
512 | ||
513 | package Foo; | |
514 | sub STORE { | |
515 | ++$tie_called; | |
516 | } | |
517 | sub FETCH {return 'N'}; | |
518 | sub TIESCALAR {bless []}; | |
519 | package main; | |
520 | ||
521 | Check( scalar( keys %_ ) == 0 ); | |
522 | my @foo = 'n'; | |
523 | tie $foo[0], "Foo"; | |
524 | ||
525 | File::Find::find( sub { $true_count++; $_{$_}++; &_; } , 'fa' ) for @foo; | |
526 | untie $_; | |
527 | ||
528 | Check( $tie_called == 0); | |
529 | Check( scalar( keys %_ ) == $true_count ); | |
530 | Check( $sub == $true_count ); | |
531 | Check( scalar( @foo ) == 1); | |
532 | Check( $foo[0] eq 'N' ); | |
533 | } | |
534 | ||
3fa6e24b | 535 | if ( $symlink_exists ) { |
bb7dc48b | 536 | print "# --- symbolic link tests --- \n"; |
3fa6e24b | 537 | $FastFileTests_OK= 1; |
7e47e6ff | 538 | |
7e47e6ff | 539 | |
3fa6e24b TW |
540 | # Verify that File::Find::find will call wanted even if the topdir of |
541 | # is a symlink to a directory, and it shouldn't follow the link | |
542 | # unless follow is set, which it isn't in this case | |
543 | %Expect_File = ( file_path('fsl') => 1 ); | |
544 | %Expect_Name = (); | |
545 | %Expect_Dir = (); | |
546 | File::Find::find( {wanted => \&wanted_File_Dir}, topdir('fa', 'fsl') ); | |
547 | Check( scalar(keys %Expect_File) == 0 ); | |
548 | ||
549 | ||
bb7dc48b JH |
550 | %Expect_File = (File::Spec->curdir => 1, file_path('fa_ord') => 1, |
551 | file_path('fsl') => 1, file_path('fb_ord') => 1, | |
552 | file_path('fba') => 1, file_path('fba_ord') => 1, | |
553 | file_path('fab') => 1, file_path('fab_ord') => 1, | |
554 | file_path('faba') => 1, file_path('faa') => 1, | |
555 | file_path('faa_ord') => 1); | |
556 | ||
3fa6e24b | 557 | %Expect_Name = (); |
bb7dc48b JH |
558 | |
559 | %Expect_Dir = (File::Spec->curdir => 1, dir_path('fa') => 1, | |
560 | dir_path('faa') => 1, dir_path('fab') => 1, | |
561 | dir_path('faba') => 1, dir_path('fb') => 1, | |
562 | dir_path('fba') => 1); | |
563 | ||
564 | File::Find::find( {wanted => \&wanted_File_Dir_prune, | |
565 | follow_fast => 1}, topdir('fa') ); | |
566 | ||
3fa6e24b TW |
567 | Check( scalar(keys %Expect_File) == 0 ); |
568 | ||
569 | ||
bb7dc48b JH |
570 | # no_chdir is in effect, hence we use file_path_name to specify |
571 | # the expected paths for %Expect_File | |
572 | ||
573 | %Expect_File = (file_path_name('fa') => 1, | |
574 | file_path_name('fa', 'fa_ord') => 1, | |
575 | file_path_name('fa', 'fsl') => 1, | |
576 | file_path_name('fa', 'fsl', 'fb_ord') => 1, | |
577 | file_path_name('fa', 'fsl', 'fba') => 1, | |
578 | file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, | |
579 | file_path_name('fa', 'fab') => 1, | |
580 | file_path_name('fa', 'fab', 'fab_ord') => 1, | |
581 | file_path_name('fa', 'fab', 'faba') => 1, | |
582 | file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, | |
583 | file_path_name('fa', 'faa') => 1, | |
584 | file_path_name('fa', 'faa', 'faa_ord') => 1); | |
585 | ||
3fa6e24b | 586 | %Expect_Name = (); |
3fa6e24b | 587 | |
bb7dc48b JH |
588 | %Expect_Dir = (dir_path('fa') => 1, |
589 | dir_path('fa', 'faa') => 1, | |
590 | dir_path('fa', 'fab') => 1, | |
591 | dir_path('fa', 'fab', 'faba') => 1, | |
592 | dir_path('fb') => 1, | |
593 | dir_path('fb', 'fba') => 1); | |
594 | ||
595 | File::Find::find( {wanted => \&wanted_File_Dir, follow_fast => 1, | |
596 | no_chdir => 1}, topdir('fa') ); | |
597 | ||
598 | Check( scalar(keys %Expect_File) == 0 ); | |
3fa6e24b TW |
599 | |
600 | %Expect_File = (); | |
bb7dc48b JH |
601 | |
602 | %Expect_Name = (file_path_name('fa') => 1, | |
603 | file_path_name('fa', 'fa_ord') => 1, | |
604 | file_path_name('fa', 'fsl') => 1, | |
605 | file_path_name('fa', 'fsl', 'fb_ord') => 1, | |
606 | file_path_name('fa', 'fsl', 'fba') => 1, | |
607 | file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, | |
608 | file_path_name('fa', 'fab') => 1, | |
609 | file_path_name('fa', 'fab', 'fab_ord') => 1, | |
610 | file_path_name('fa', 'fab', 'faba') => 1, | |
611 | file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, | |
612 | file_path_name('fa', 'faa') => 1, | |
3fa6e24b | 613 | file_path_name('fa', 'faa', 'faa_ord') => 1); |
bb7dc48b | 614 | |
3fa6e24b | 615 | %Expect_Dir = (); |
3fa6e24b | 616 | |
bb7dc48b JH |
617 | File::Find::finddepth( {wanted => \&wanted_Name, |
618 | follow_fast => 1}, topdir('fa') ); | |
619 | ||
620 | Check( scalar(keys %Expect_Name) == 0 ); | |
3fa6e24b | 621 | |
bb7dc48b JH |
622 | # no_chdir is in effect, hence we use file_path_name to specify |
623 | # the expected paths for %Expect_File | |
624 | ||
625 | %Expect_File = (file_path_name('fa') => 1, | |
626 | file_path_name('fa', 'fa_ord') => 1, | |
627 | file_path_name('fa', 'fsl') => 1, | |
628 | file_path_name('fa', 'fsl', 'fb_ord') => 1, | |
629 | file_path_name('fa', 'fsl', 'fba') => 1, | |
630 | file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, | |
631 | file_path_name('fa', 'fab') => 1, | |
632 | file_path_name('fa', 'fab', 'fab_ord') => 1, | |
633 | file_path_name('fa', 'fab', 'faba') => 1, | |
634 | file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, | |
635 | file_path_name('fa', 'faa') => 1, | |
3fa6e24b | 636 | file_path_name('fa', 'faa', 'faa_ord') => 1); |
bb7dc48b | 637 | |
3fa6e24b TW |
638 | %Expect_Name = (); |
639 | %Expect_Dir = (); | |
bb7dc48b JH |
640 | |
641 | File::Find::finddepth( {wanted => \&wanted_File, follow_fast => 1, | |
642 | no_chdir => 1}, topdir('fa') ); | |
643 | ||
3fa6e24b TW |
644 | Check( scalar(keys %Expect_File) == 0 ); |
645 | ||
646 | ||
647 | print "# check dangling symbolic links\n"; | |
648 | MkDir( dir_path('dangling_dir'), 0770 ); | |
bb7dc48b JH |
649 | CheckDie( symlink( dir_path('dangling_dir'), |
650 | file_path('dangling_dir_sl') ) ); | |
3fa6e24b TW |
651 | rmdir dir_path('dangling_dir'); |
652 | touch(file_path('dangling_file')); | |
653 | if ($^O eq 'MacOS') { | |
654 | CheckDie( symlink('dangling_file', ':fa:dangling_file_sl') ); | |
655 | } else { | |
656 | CheckDie( symlink('../dangling_file','fa/dangling_file_sl') ); | |
657 | } | |
658 | unlink file_path('dangling_file'); | |
659 | ||
660 | { | |
661 | # these tests should also emit a warning | |
bb7dc48b JH |
662 | use warnings; |
663 | ||
664 | %Expect_File = (File::Spec->curdir => 1, | |
665 | file_path('fa_ord') => 1, | |
666 | file_path('fsl') => 1, | |
667 | file_path('fb_ord') => 1, | |
668 | file_path('fba') => 1, | |
669 | file_path('fba_ord') => 1, | |
670 | file_path('fab') => 1, | |
671 | file_path('fab_ord') => 1, | |
672 | file_path('faba') => 1, | |
673 | file_path('faba_ord') => 1, | |
674 | file_path('faa') => 1, | |
675 | file_path('faa_ord') => 1); | |
676 | ||
3fa6e24b TW |
677 | %Expect_Name = (); |
678 | %Expect_Dir = (); | |
679 | undef $warn_msg; | |
bb7dc48b JH |
680 | |
681 | File::Find::find( {wanted => \&wanted_File, follow => 1, | |
682 | dangling_symlinks => | |
683 | sub { $warn_msg = "$_[0] is a dangling symbolic link" } | |
684 | }, | |
685 | topdir('dangling_dir_sl'), topdir('fa') ); | |
686 | ||
3fa6e24b TW |
687 | Check( scalar(keys %Expect_File) == 0 ); |
688 | Check( $warn_msg =~ m|dangling_dir_sl is a dangling symbolic link| ); | |
bb7dc48b JH |
689 | unlink file_path('fa', 'dangling_file_sl'), |
690 | file_path('dangling_dir_sl'); | |
691 | ||
3fa6e24b TW |
692 | } |
693 | ||
694 | ||
695 | print "# check recursion\n"; | |
696 | if ($^O eq 'MacOS') { | |
697 | CheckDie( symlink(':fa:faa',':fa:faa:faa_sl') ); | |
698 | } else { | |
699 | CheckDie( symlink('../faa','fa/faa/faa_sl') ); | |
700 | } | |
7e47e6ff | 701 | undef $@; |
bb7dc48b JH |
702 | eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, |
703 | no_chdir => 1}, topdir('fa') ); }; | |
3fa6e24b TW |
704 | Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]faa_sl is a recursive symbolic link| ); |
705 | unlink file_path('fa', 'faa', 'faa_sl'); | |
7e47e6ff | 706 | |
3fa6e24b TW |
707 | |
708 | print "# check follow_skip (file)\n"; | |
709 | if ($^O eq 'MacOS') { | |
710 | CheckDie( symlink(':fa:fa_ord',':fa:fa_ord_sl') ); # symlink to a file | |
711 | } else { | |
712 | CheckDie( symlink('./fa_ord','fa/fa_ord_sl') ); # symlink to a file | |
713 | } | |
7e47e6ff | 714 | undef $@; |
bb7dc48b JH |
715 | |
716 | eval {File::Find::finddepth( {wanted => \&simple_wanted, | |
717 | follow => 1, | |
718 | follow_skip => 0, no_chdir => 1}, | |
719 | topdir('fa') );}; | |
720 | ||
3fa6e24b | 721 | Check( $@ =~ m|for_find[:/]fa[:/]fa_ord encountered a second time| ); |
7e47e6ff | 722 | |
7e47e6ff | 723 | |
bb7dc48b JH |
724 | # no_chdir is in effect, hence we use file_path_name to specify |
725 | # the expected paths for %Expect_File | |
726 | ||
727 | %Expect_File = (file_path_name('fa') => 1, | |
728 | file_path_name('fa', 'fa_ord') => 1, | |
729 | file_path_name('fa', 'fsl') => 1, | |
730 | file_path_name('fa', 'fsl', 'fb_ord') => 1, | |
731 | file_path_name('fa', 'fsl', 'fba') => 1, | |
732 | file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, | |
733 | file_path_name('fa', 'fab') => 1, | |
734 | file_path_name('fa', 'fab', 'fab_ord') => 1, | |
735 | file_path_name('fa', 'fab', 'faba') => 1, | |
736 | file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, | |
737 | file_path_name('fa', 'faa') => 1, | |
738 | file_path_name('fa', 'faa', 'faa_ord') => 1); | |
3fa6e24b TW |
739 | |
740 | %Expect_Name = (); | |
bb7dc48b JH |
741 | |
742 | %Expect_Dir = (dir_path('fa') => 1, | |
743 | dir_path('fa', 'faa') => 1, | |
744 | dir_path('fa', 'fab') => 1, | |
745 | dir_path('fa', 'fab', 'faba') => 1, | |
746 | dir_path('fb') => 1, | |
747 | dir_path('fb','fba') => 1); | |
748 | ||
749 | File::Find::finddepth( {wanted => \&wanted_File_Dir, follow => 1, | |
750 | follow_skip => 1, no_chdir => 1}, | |
3fa6e24b | 751 | topdir('fa') ); |
bb7dc48b | 752 | |
3fa6e24b TW |
753 | Check( scalar(keys %Expect_File) == 0 ); |
754 | unlink file_path('fa', 'fa_ord_sl'); | |
755 | ||
756 | ||
757 | print "# check follow_skip (directory)\n"; | |
758 | if ($^O eq 'MacOS') { | |
759 | CheckDie( symlink(':fa:faa',':fa:faa_sl') ); # symlink to a directory | |
760 | } else { | |
761 | CheckDie( symlink('./faa','fa/faa_sl') ); # symlink to a directory | |
7e47e6ff | 762 | } |
3fa6e24b | 763 | undef $@; |
bb7dc48b JH |
764 | |
765 | eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, | |
766 | follow_skip => 0, no_chdir => 1}, | |
3fa6e24b | 767 | topdir('fa') );}; |
bb7dc48b | 768 | |
3fa6e24b TW |
769 | Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time| ); |
770 | ||
771 | ||
772 | undef $@; | |
bb7dc48b JH |
773 | |
774 | eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, | |
775 | follow_skip => 1, no_chdir => 1}, | |
3fa6e24b | 776 | topdir('fa') );}; |
bb7dc48b | 777 | |
3fa6e24b TW |
778 | Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time| ); |
779 | ||
bb7dc48b JH |
780 | # no_chdir is in effect, hence we use file_path_name to specify |
781 | # the expected paths for %Expect_File | |
782 | ||
783 | %Expect_File = (file_path_name('fa') => 1, | |
784 | file_path_name('fa', 'fa_ord') => 1, | |
785 | file_path_name('fa', 'fsl') => 1, | |
786 | file_path_name('fa', 'fsl', 'fb_ord') => 1, | |
787 | file_path_name('fa', 'fsl', 'fba') => 1, | |
788 | file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, | |
789 | file_path_name('fa', 'fab') => 1, | |
790 | file_path_name('fa', 'fab', 'fab_ord') => 1, | |
791 | file_path_name('fa', 'fab', 'faba') => 1, | |
792 | file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, | |
793 | file_path_name('fa', 'faa') => 1, | |
794 | file_path_name('fa', 'faa', 'faa_ord') => 1); | |
3fa6e24b TW |
795 | |
796 | %Expect_Name = (); | |
bb7dc48b JH |
797 | |
798 | %Expect_Dir = (dir_path('fa') => 1, | |
799 | dir_path('fa', 'faa') => 1, | |
800 | dir_path('fa', 'fab') => 1, | |
801 | dir_path('fa', 'fab', 'faba') => 1, | |
802 | dir_path('fb') => 1, | |
803 | dir_path('fb', 'fba') => 1); | |
804 | ||
805 | File::Find::find( {wanted => \&wanted_File_Dir, follow => 1, | |
806 | follow_skip => 2, no_chdir => 1}, topdir('fa') ); | |
807 | ||
3fa6e24b TW |
808 | Check( scalar(keys %Expect_File) == 0 ); |
809 | unlink file_path('fa', 'faa_sl'); | |
810 | ||
17ab9c14 | 811 | } |