This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
When threads are active we need -lpthread, but previous `fix' of
[perl5.git] / lib / File / Find / t / find.t
CommitLineData
3fa6e24b 1#!./perl
81793b90
GS
2
3
3fa6e24b
TW
4my %Expect_File = (); # what we expect for $_
5my %Expect_Name = (); # what we expect for $File::Find::name/fullname
6my %Expect_Dir = (); # what we expect for $File::Find::dir
81793b90 7my $symlink_exists = eval { symlink("",""); 1 };
7e47e6ff 8my $warn_msg;
3fa6e24b 9
1a3850a5
GA
10
11BEGIN {
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
17ab9c14
JB
18if ( $symlink_exists ) { print "1..189\n"; }
19else { print "1..79\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
38BEGIN {
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
52cleanup();
53
912440be
NC
54$::count_commonsense = 0;
55find({wanted => sub { ++$::count_commonsense if $_ eq 'commonsense.t'; } },
bb7dc48b 56 File::Spec->curdir);
912440be
NC
57if ($::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;
64finddepth({wanted => sub { ++$::count_commonsense if $_ eq 'commonsense.t'; } },
bb7dc48b 65 File::Spec->curdir);
912440be
NC
66if ($::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 72my $case = 2;
5eb85357 73my $FastFileTests_OK = 0;
81793b90 74
c80f55d1 75sub 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 100END {
c80f55d1 101 cleanup();
81793b90
GS
102}
103
104sub Check($) {
3fa6e24b
TW
105 $case++;
106 if ($_[0]) { print "ok $case\n"; }
107 else { print "not ok $case\n"; }
81793b90
GS
108}
109
110sub 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
116sub touch {
3fa6e24b 117 CheckDie( open(my $T,'>',$_[0]) );
81793b90
GS
118}
119
120sub MkDir($$) {
3fa6e24b 121 CheckDie( mkdir($_[0],$_[1]) );
81793b90
GS
122}
123
3fa6e24b
TW
124sub 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
138sub wanted_File_Dir_prune {
139 &wanted_File_Dir;
140 $File::Find::prune=1 if $_ eq 'faba';
81793b90
GS
141}
142
3fa6e24b
TW
143sub 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
158sub 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 172sub simple_wanted {
3fa6e24b
TW
173 print "# \$File::Find::dir => '$File::Find::dir'\n";
174 print "# \$_ => '$_'\n";
7e47e6ff
JH
175}
176
177sub noop_wanted {}
78eac027 178
7e47e6ff 179sub 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
196sub 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
217sub 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
245sub 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
265sub 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
299sub 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
307MkDir( dir_path('for_find'), 0770 );
308CheckDie(chdir( dir_path('for_find')));
309MkDir( dir_path('fa'), 0770 );
310MkDir( dir_path('fb'), 0770 );
311touch( file_path('fb', 'fb_ord') );
312MkDir( dir_path('fb', 'fba'), 0770 );
313touch( file_path('fb', 'fba', 'fba_ord') );
314if ($^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}
319touch( file_path('fa', 'fa_ord') );
320
321MkDir( dir_path('fa', 'faa'), 0770 );
322touch( file_path('fa', 'faa', 'faa_ord') );
323MkDir( dir_path('fa', 'fab'), 0770 );
324touch( file_path('fa', 'fab', 'fab_ord') );
325MkDir( dir_path('fa', 'fab', 'faba'), 0770 );
326touch( 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
334delete $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
341delete @Expect_Dir{ dir_path('fb'), dir_path('fba') } unless $symlink_exists;
342File::Find::find( {wanted => \&wanted_File_Dir_prune}, topdir('fa') );
343Check( scalar(keys %Expect_File) == 0 );
344
345
346print "# 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
353delete $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 360delete @Expect_Dir{ dir_path('fb'), dir_path('fba') } unless $symlink_exists;
bb7dc48b
JH
361
362File::Find::find( {wanted => sub { wanted_File_Dir_prune();
363 File::Find::find( {wanted => sub
364 {} }, File::Spec->curdir ); } },
365 topdir('fa') );
366
3fa6e24b
TW
367Check( 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
382delete $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
392delete @Expect_Dir{ dir_path('fb'), dir_path('fb', 'fba') }
393 unless $symlink_exists;
394
395File::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
416delete $Expect_Name{ file_path('.', 'fa', 'fsl') } unless $symlink_exists;
417%Expect_Dir = ();
418File::Find::finddepth( {wanted => \&wanted_Name}, File::Spec->curdir );
419Check( 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
440delete $Expect_File{ file_path_name('.', 'fa', 'fsl') } unless $symlink_exists;
441%Expect_Name = ();
442%Expect_Dir = ();
bb7dc48b
JH
443
444File::Find::finddepth( {wanted => \&wanted_File, no_chdir => 1},
445 File::Spec->curdir );
446
3fa6e24b
TW
447Check( scalar(keys %Expect_File) == 0 );
448
449
450print "# 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
463File::Find::find( {wanted => \&noop_wanted,
464 preprocess => \&my_preprocess}, File::Spec->curdir );
465
3fa6e24b
TW
466Check( scalar(keys %Expect_Dir) == 0 );
467
468
469print "# 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
482File::Find::find( {wanted => \&noop_wanted,
483 postprocess => \&my_postprocess}, File::Spec->curdir );
484
3fa6e24b
TW
485Check( 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
TW
499
500if ( $symlink_exists ) {
bb7dc48b 501 print "# --- symbolic link tests --- \n";
3fa6e24b 502 $FastFileTests_OK= 1;
7e47e6ff 503
7e47e6ff 504
3fa6e24b
TW
505 # Verify that File::Find::find will call wanted even if the topdir of
506 # is a symlink to a directory, and it shouldn't follow the link
507 # unless follow is set, which it isn't in this case
508 %Expect_File = ( file_path('fsl') => 1 );
509 %Expect_Name = ();
510 %Expect_Dir = ();
511 File::Find::find( {wanted => \&wanted_File_Dir}, topdir('fa', 'fsl') );
512 Check( scalar(keys %Expect_File) == 0 );
513
514
bb7dc48b
JH
515 %Expect_File = (File::Spec->curdir => 1, file_path('fa_ord') => 1,
516 file_path('fsl') => 1, file_path('fb_ord') => 1,
517 file_path('fba') => 1, file_path('fba_ord') => 1,
518 file_path('fab') => 1, file_path('fab_ord') => 1,
519 file_path('faba') => 1, file_path('faa') => 1,
520 file_path('faa_ord') => 1);
521
3fa6e24b 522 %Expect_Name = ();
bb7dc48b
JH
523
524 %Expect_Dir = (File::Spec->curdir => 1, dir_path('fa') => 1,
525 dir_path('faa') => 1, dir_path('fab') => 1,
526 dir_path('faba') => 1, dir_path('fb') => 1,
527 dir_path('fba') => 1);
528
529 File::Find::find( {wanted => \&wanted_File_Dir_prune,
530 follow_fast => 1}, topdir('fa') );
531
3fa6e24b
TW
532 Check( scalar(keys %Expect_File) == 0 );
533
534
bb7dc48b
JH
535 # no_chdir is in effect, hence we use file_path_name to specify
536 # the expected paths for %Expect_File
537
538 %Expect_File = (file_path_name('fa') => 1,
539 file_path_name('fa', 'fa_ord') => 1,
540 file_path_name('fa', 'fsl') => 1,
541 file_path_name('fa', 'fsl', 'fb_ord') => 1,
542 file_path_name('fa', 'fsl', 'fba') => 1,
543 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
544 file_path_name('fa', 'fab') => 1,
545 file_path_name('fa', 'fab', 'fab_ord') => 1,
546 file_path_name('fa', 'fab', 'faba') => 1,
547 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
548 file_path_name('fa', 'faa') => 1,
549 file_path_name('fa', 'faa', 'faa_ord') => 1);
550
3fa6e24b 551 %Expect_Name = ();
3fa6e24b 552
bb7dc48b
JH
553 %Expect_Dir = (dir_path('fa') => 1,
554 dir_path('fa', 'faa') => 1,
555 dir_path('fa', 'fab') => 1,
556 dir_path('fa', 'fab', 'faba') => 1,
557 dir_path('fb') => 1,
558 dir_path('fb', 'fba') => 1);
559
560 File::Find::find( {wanted => \&wanted_File_Dir, follow_fast => 1,
561 no_chdir => 1}, topdir('fa') );
562
563 Check( scalar(keys %Expect_File) == 0 );
3fa6e24b
TW
564
565 %Expect_File = ();
bb7dc48b
JH
566
567 %Expect_Name = (file_path_name('fa') => 1,
568 file_path_name('fa', 'fa_ord') => 1,
569 file_path_name('fa', 'fsl') => 1,
570 file_path_name('fa', 'fsl', 'fb_ord') => 1,
571 file_path_name('fa', 'fsl', 'fba') => 1,
572 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
573 file_path_name('fa', 'fab') => 1,
574 file_path_name('fa', 'fab', 'fab_ord') => 1,
575 file_path_name('fa', 'fab', 'faba') => 1,
576 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
577 file_path_name('fa', 'faa') => 1,
3fa6e24b 578 file_path_name('fa', 'faa', 'faa_ord') => 1);
bb7dc48b 579
3fa6e24b 580 %Expect_Dir = ();
3fa6e24b 581
bb7dc48b
JH
582 File::Find::finddepth( {wanted => \&wanted_Name,
583 follow_fast => 1}, topdir('fa') );
584
585 Check( scalar(keys %Expect_Name) == 0 );
3fa6e24b 586
bb7dc48b
JH
587 # no_chdir is in effect, hence we use file_path_name to specify
588 # the expected paths for %Expect_File
589
590 %Expect_File = (file_path_name('fa') => 1,
591 file_path_name('fa', 'fa_ord') => 1,
592 file_path_name('fa', 'fsl') => 1,
593 file_path_name('fa', 'fsl', 'fb_ord') => 1,
594 file_path_name('fa', 'fsl', 'fba') => 1,
595 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
596 file_path_name('fa', 'fab') => 1,
597 file_path_name('fa', 'fab', 'fab_ord') => 1,
598 file_path_name('fa', 'fab', 'faba') => 1,
599 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
600 file_path_name('fa', 'faa') => 1,
3fa6e24b 601 file_path_name('fa', 'faa', 'faa_ord') => 1);
bb7dc48b 602
3fa6e24b
TW
603 %Expect_Name = ();
604 %Expect_Dir = ();
bb7dc48b
JH
605
606 File::Find::finddepth( {wanted => \&wanted_File, follow_fast => 1,
607 no_chdir => 1}, topdir('fa') );
608
3fa6e24b
TW
609 Check( scalar(keys %Expect_File) == 0 );
610
611
612 print "# check dangling symbolic links\n";
613 MkDir( dir_path('dangling_dir'), 0770 );
bb7dc48b
JH
614 CheckDie( symlink( dir_path('dangling_dir'),
615 file_path('dangling_dir_sl') ) );
3fa6e24b
TW
616 rmdir dir_path('dangling_dir');
617 touch(file_path('dangling_file'));
618 if ($^O eq 'MacOS') {
619 CheckDie( symlink('dangling_file', ':fa:dangling_file_sl') );
620 } else {
621 CheckDie( symlink('../dangling_file','fa/dangling_file_sl') );
622 }
623 unlink file_path('dangling_file');
624
625 {
626 # these tests should also emit a warning
bb7dc48b
JH
627 use warnings;
628
629 %Expect_File = (File::Spec->curdir => 1,
630 file_path('fa_ord') => 1,
631 file_path('fsl') => 1,
632 file_path('fb_ord') => 1,
633 file_path('fba') => 1,
634 file_path('fba_ord') => 1,
635 file_path('fab') => 1,
636 file_path('fab_ord') => 1,
637 file_path('faba') => 1,
638 file_path('faba_ord') => 1,
639 file_path('faa') => 1,
640 file_path('faa_ord') => 1);
641
3fa6e24b
TW
642 %Expect_Name = ();
643 %Expect_Dir = ();
644 undef $warn_msg;
bb7dc48b
JH
645
646 File::Find::find( {wanted => \&wanted_File, follow => 1,
647 dangling_symlinks =>
648 sub { $warn_msg = "$_[0] is a dangling symbolic link" }
649 },
650 topdir('dangling_dir_sl'), topdir('fa') );
651
3fa6e24b
TW
652 Check( scalar(keys %Expect_File) == 0 );
653 Check( $warn_msg =~ m|dangling_dir_sl is a dangling symbolic link| );
bb7dc48b
JH
654 unlink file_path('fa', 'dangling_file_sl'),
655 file_path('dangling_dir_sl');
656
3fa6e24b
TW
657 }
658
659
660 print "# check recursion\n";
661 if ($^O eq 'MacOS') {
662 CheckDie( symlink(':fa:faa',':fa:faa:faa_sl') );
663 } else {
664 CheckDie( symlink('../faa','fa/faa/faa_sl') );
665 }
7e47e6ff 666 undef $@;
bb7dc48b
JH
667 eval {File::Find::find( {wanted => \&simple_wanted, follow => 1,
668 no_chdir => 1}, topdir('fa') ); };
3fa6e24b
TW
669 Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]faa_sl is a recursive symbolic link| );
670 unlink file_path('fa', 'faa', 'faa_sl');
7e47e6ff 671
3fa6e24b
TW
672
673 print "# check follow_skip (file)\n";
674 if ($^O eq 'MacOS') {
675 CheckDie( symlink(':fa:fa_ord',':fa:fa_ord_sl') ); # symlink to a file
676 } else {
677 CheckDie( symlink('./fa_ord','fa/fa_ord_sl') ); # symlink to a file
678 }
7e47e6ff 679 undef $@;
bb7dc48b
JH
680
681 eval {File::Find::finddepth( {wanted => \&simple_wanted,
682 follow => 1,
683 follow_skip => 0, no_chdir => 1},
684 topdir('fa') );};
685
3fa6e24b 686 Check( $@ =~ m|for_find[:/]fa[:/]fa_ord encountered a second time| );
7e47e6ff 687
7e47e6ff 688
bb7dc48b
JH
689 # no_chdir is in effect, hence we use file_path_name to specify
690 # the expected paths for %Expect_File
691
692 %Expect_File = (file_path_name('fa') => 1,
693 file_path_name('fa', 'fa_ord') => 1,
694 file_path_name('fa', 'fsl') => 1,
695 file_path_name('fa', 'fsl', 'fb_ord') => 1,
696 file_path_name('fa', 'fsl', 'fba') => 1,
697 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
698 file_path_name('fa', 'fab') => 1,
699 file_path_name('fa', 'fab', 'fab_ord') => 1,
700 file_path_name('fa', 'fab', 'faba') => 1,
701 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
702 file_path_name('fa', 'faa') => 1,
703 file_path_name('fa', 'faa', 'faa_ord') => 1);
3fa6e24b
TW
704
705 %Expect_Name = ();
bb7dc48b
JH
706
707 %Expect_Dir = (dir_path('fa') => 1,
708 dir_path('fa', 'faa') => 1,
709 dir_path('fa', 'fab') => 1,
710 dir_path('fa', 'fab', 'faba') => 1,
711 dir_path('fb') => 1,
712 dir_path('fb','fba') => 1);
713
714 File::Find::finddepth( {wanted => \&wanted_File_Dir, follow => 1,
715 follow_skip => 1, no_chdir => 1},
3fa6e24b 716 topdir('fa') );
bb7dc48b 717
3fa6e24b
TW
718 Check( scalar(keys %Expect_File) == 0 );
719 unlink file_path('fa', 'fa_ord_sl');
720
721
722 print "# check follow_skip (directory)\n";
723 if ($^O eq 'MacOS') {
724 CheckDie( symlink(':fa:faa',':fa:faa_sl') ); # symlink to a directory
725 } else {
726 CheckDie( symlink('./faa','fa/faa_sl') ); # symlink to a directory
7e47e6ff 727 }
3fa6e24b 728 undef $@;
bb7dc48b
JH
729
730 eval {File::Find::find( {wanted => \&simple_wanted, follow => 1,
731 follow_skip => 0, no_chdir => 1},
3fa6e24b 732 topdir('fa') );};
bb7dc48b 733
3fa6e24b
TW
734 Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time| );
735
736
737 undef $@;
bb7dc48b
JH
738
739 eval {File::Find::find( {wanted => \&simple_wanted, follow => 1,
740 follow_skip => 1, no_chdir => 1},
3fa6e24b 741 topdir('fa') );};
bb7dc48b 742
3fa6e24b
TW
743 Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time| );
744
bb7dc48b
JH
745 # no_chdir is in effect, hence we use file_path_name to specify
746 # the expected paths for %Expect_File
747
748 %Expect_File = (file_path_name('fa') => 1,
749 file_path_name('fa', 'fa_ord') => 1,
750 file_path_name('fa', 'fsl') => 1,
751 file_path_name('fa', 'fsl', 'fb_ord') => 1,
752 file_path_name('fa', 'fsl', 'fba') => 1,
753 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
754 file_path_name('fa', 'fab') => 1,
755 file_path_name('fa', 'fab', 'fab_ord') => 1,
756 file_path_name('fa', 'fab', 'faba') => 1,
757 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
758 file_path_name('fa', 'faa') => 1,
759 file_path_name('fa', 'faa', 'faa_ord') => 1);
3fa6e24b
TW
760
761 %Expect_Name = ();
bb7dc48b
JH
762
763 %Expect_Dir = (dir_path('fa') => 1,
764 dir_path('fa', 'faa') => 1,
765 dir_path('fa', 'fab') => 1,
766 dir_path('fa', 'fab', 'faba') => 1,
767 dir_path('fb') => 1,
768 dir_path('fb', 'fba') => 1);
769
770 File::Find::find( {wanted => \&wanted_File_Dir, follow => 1,
771 follow_skip => 2, no_chdir => 1}, topdir('fa') );
772
3fa6e24b
TW
773 Check( scalar(keys %Expect_File) == 0 );
774 unlink file_path('fa', 'faa_sl');
775
17ab9c14 776}