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