5 my %Expect_File = (); # what we expect for $_
6 my %Expect_Name = (); # what we expect for $File::Find::name/fullname
7 my %Expect_Dir = (); # what we expect for $File::Find::dir
8 my $symlink_exists = eval { symlink("",""); 1 };
9 my ($warn_msg, @files, $file);
15 # May be doing dynamic loading while @INC is all relative
16 unshift @INC => File::Spec->rel2abs('../lib');
18 $SIG{'__WARN__'} = sub { $warn_msg = $_[0]; warn "# $_[0]"; }
22 $test_count += 114 if $symlink_exists;
23 $test_count += 18 if $^O eq 'MSWin32';
24 $test_count += 2 if $^O eq 'MSWin32' and $symlink_exists;
26 print "1..$test_count\n";
27 #if ( $symlink_exists ) { print "1..199\n"; }
28 #else { print "1..85\n"; }
32 # Uncomment this to see where File::Find is chdir'ing to. Helpful for
33 # debugging its little jaunts around the filesystem.
36 # *CORE::GLOBAL::chdir = sub ($) {
37 # my($file, $line) = (caller)[1,2];
39 # printf "# cwd: %s\n", cwd();
40 # print "# chdir: @_ from $file at $line\n";
41 # my($return) = CORE::chdir($_[0]);
42 # printf "# newcwd: %s\n", cwd();
51 if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'VMS')
53 # This is a hack - at present File::Find does not produce native names on
54 # Win32 or VMS, so force File::Spec to use Unix names.
55 # must be set *before* importing File::Find
56 require File::Spec::Unix;
57 @File::Spec::ISA = 'File::Spec::Unix';
65 $::count_commonsense = 0;
66 find({wanted => sub { ++$::count_commonsense if $_ eq 'commonsense.t'; } },
68 if ($::count_commonsense == 1) {
71 print "not ok 1 # found $::count_commonsense files named 'commonsense.t'\n";
74 $::count_commonsense = 0;
75 finddepth({wanted => sub { ++$::count_commonsense if $_ eq 'commonsense.t'; } },
77 if ($::count_commonsense == 1) {
80 print "not ok 2 # found $::count_commonsense files named 'commonsense.t'\n";
84 my $FastFileTests_OK = 0;
89 if (-d dir_path('for_find')) {
90 $need_updir = 1 if chdir(dir_path('for_find'));
92 if (-d dir_path('fa')) {
93 unlink file_path('fa', 'fa_ord'),
94 file_path('fa', 'fsl'),
95 file_path('fa', 'faa', 'faa_ord'),
96 file_path('fa', 'fab', 'fab_ord'),
97 file_path('fa', 'fab', 'faba', 'faba_ord'),
98 file_path('fb', 'fb_ord'),
99 file_path('fb', 'fba', 'fba_ord');
100 rmdir dir_path('fa', 'faa');
101 rmdir dir_path('fa', 'fab', 'faba');
102 rmdir dir_path('fa', 'fab');
103 rmdir dir_path('fa');
104 rmdir dir_path('fb', 'fba');
105 rmdir dir_path('fb');
108 my $updir = $^O eq 'VMS' ? File::Spec::VMS->updir() : File::Spec->updir;
111 if (-d dir_path('for_find')) {
112 rmdir dir_path('for_find') or print "# Can't rmdir for_find: $!\n";
122 if ($_[0]) { print "ok $case\n"; }
123 else { print "not ok $case\n"; }
128 if ($_[0]) { print "ok $case\n"; }
129 else { print "not ok $case\n $!\n"; exit 0; }
133 CheckDie( open(my $T,'>',$_[0]) );
137 CheckDie( mkdir($_[0],$_[1]) );
140 sub wanted_File_Dir {
141 printf "# \$File::Find::dir => '$File::Find::dir'\t\$_ => '$_'\n";
142 s#\.$## if ($^O eq 'VMS' && $_ ne '.');
143 s/(.dir)?$//i if ($^O eq 'VMS' && -d _);
144 Check( $Expect_File{$_} );
145 if ( $FastFileTests_OK ) {
146 delete $Expect_File{ $_}
147 unless ( $Expect_Dir{$_} && ! -d _ );
149 delete $Expect_File{$_}
150 unless ( $Expect_Dir{$_} && ! -d $_ );
154 sub wanted_File_Dir_prune {
156 $File::Find::prune=1 if $_ eq 'faba';
160 my $n = $File::Find::name;
161 $n =~ s#\.$## if ($^O eq 'VMS' && $n ne '.');
162 print "# \$File::Find::name => '$n'\n";
163 my $i = rindex($n,'/');
164 my $OK = exists($Expect_Name{$n});
165 unless ($^O eq 'MacOS') {
167 $OK= exists($Expect_Name{substr($n,0,$i)}) if $i >= 0;
171 delete $Expect_Name{$n};
175 print "# \$_ => '$_'\n";
176 s#\.$## if ($^O eq 'VMS' && $_ ne '.');
177 my $i = rindex($_,'/');
178 my $OK = exists($Expect_File{ $_});
179 unless ($^O eq 'MacOS') {
181 $OK= exists($Expect_File{ substr($_,0,$i)}) if $i >= 0;
185 delete $Expect_File{ $_};
189 print "# \$File::Find::dir => '$File::Find::dir'\n";
190 print "# \$_ => '$_'\n";
197 print "# --preprocess--\n";
198 print "# \$File::Find::dir => '$File::Find::dir' \n";
199 foreach $file (@files) {
200 $file =~ s/\.(dir)?$// if $^O eq 'VMS';
202 delete $Expect_Dir{ $File::Find::dir }->{$file};
204 print "# --end preprocess--\n";
205 Check(scalar(keys %{$Expect_Dir{ $File::Find::dir }}) == 0);
206 if (scalar(keys %{$Expect_Dir{ $File::Find::dir }}) == 0) {
207 delete $Expect_Dir{ $File::Find::dir }
213 print "# postprocess: \$File::Find::dir => '$File::Find::dir' \n";
214 delete $Expect_Dir{ $File::Find::dir};
218 # Use dir_path() to specify a directory path that's expected for
219 # $File::Find::dir (%Expect_Dir). Also use it in file operations like
222 # dir_path() concatenates directory names to form a *relative*
223 # directory path, independent from the platform it's run on, although
224 # there are limitations. Don't try to create an absolute path,
225 # because that may fail on operating systems that have the concept of
226 # volume names (e.g. Mac OS). As a special case, you can pass it a "."
227 # as first argument, to create a directory path like "./fa/dir" on
228 # operating systems other than Mac OS (actually, Mac OS will ignore
229 # the ".", if it's the first argument). If there's no second argument,
230 # this function will return the empty string on Mac OS and the string
234 my $first_arg = shift @_;
236 if ($first_arg eq '.') {
237 if ($^O eq 'MacOS') {
239 # ignore first argument; return a relative path
240 # with leading ":" and with trailing ":"
241 return File::Spec->catdir(@_);
243 return './' unless @_;
244 my $path = File::Spec->catdir(@_);
250 } else { # $first_arg ne '.'
251 return $first_arg unless @_; # return plain filename
252 return File::Spec->catdir($first_arg, @_); # relative path
257 # Use topdir() to specify a directory path that you want to pass to
258 # find/finddepth. Basically, topdir() does the same as dir_path() (see
259 # above), except that there's no trailing ":" on Mac OS.
262 my $path = dir_path(@_);
263 $path =~ s/:$// if ($^O eq 'MacOS');
268 # Use file_path() to specify a file path that's expected for $_
269 # (%Expect_File). Also suitable for file operations like unlink etc.
271 # file_path() concatenates directory names (if any) and a filename to
272 # form a *relative* file path (the last argument is assumed to be a
273 # file). It's independent from the platform it's run on, although
274 # there are limitations. As a special case, you can pass it a "." as
275 # first argument, to create a file path like "./fa/file" on operating
276 # systems other than Mac OS (actually, Mac OS will ignore the ".", if
277 # it's the first argument). If there's no second argument, this
278 # function will return the empty string on Mac OS and the string "./"
282 my $first_arg = shift @_;
284 if ($first_arg eq '.') {
285 if ($^O eq 'MacOS') {
287 # ignore first argument; return a relative path
288 # with leading ":", but without trailing ":"
289 return File::Spec->catfile(@_);
291 return './' unless @_;
292 my $path = File::Spec->catfile(@_);
298 } else { # $first_arg ne '.'
299 return $first_arg unless @_; # return plain filename
300 return File::Spec->catfile($first_arg, @_); # relative path
305 # Use file_path_name() to specify a file path that's expected for
306 # $File::Find::Name (%Expect_Name). Note: When the no_chdir => 1
307 # option is in effect, $_ is the same as $File::Find::Name. In that
308 # case, also use this function to specify a file path that's expected
311 # Basically, file_path_name() does the same as file_path() (see
312 # above), except that there's always a leading ":" on Mac OS, even for
313 # plain file/directory names.
316 my $path = file_path(@_);
317 $path = ":$path" if (($^O eq 'MacOS') && ($path !~ /:/));
323 MkDir( dir_path('for_find'), 0770 );
324 CheckDie(chdir( dir_path('for_find')));
325 MkDir( dir_path('fa'), 0770 );
326 MkDir( dir_path('fb'), 0770 );
327 touch( file_path('fb', 'fb_ord') );
328 MkDir( dir_path('fb', 'fba'), 0770 );
329 touch( file_path('fb', 'fba', 'fba_ord') );
330 if ($^O eq 'MacOS') {
331 CheckDie( symlink(':fb',':fa:fsl') ) if $symlink_exists;
333 CheckDie( symlink('../fb','fa/fsl') ) if $symlink_exists;
335 touch( file_path('fa', 'fa_ord') );
337 MkDir( dir_path('fa', 'faa'), 0770 );
338 touch( file_path('fa', 'faa', 'faa_ord') );
339 MkDir( dir_path('fa', 'fab'), 0770 );
340 touch( file_path('fa', 'fab', 'fab_ord') );
341 MkDir( dir_path('fa', 'fab', 'faba'), 0770 );
342 touch( file_path('fa', 'fab', 'faba', 'faba_ord') );
345 %Expect_File = (File::Spec->curdir => 1, file_path('fsl') => 1,
346 file_path('fa_ord') => 1, file_path('fab') => 1,
347 file_path('fab_ord') => 1, file_path('faba') => 1,
348 file_path('faa') => 1, file_path('faa_ord') => 1);
350 delete $Expect_File{ file_path('fsl') } unless $symlink_exists;
353 %Expect_Dir = ( dir_path('fa') => 1, dir_path('faa') => 1,
354 dir_path('fab') => 1, dir_path('faba') => 1,
355 dir_path('fb') => 1, dir_path('fba') => 1);
357 delete @Expect_Dir{ dir_path('fb'), dir_path('fba') } unless $symlink_exists;
358 File::Find::find( {wanted => \&wanted_File_Dir_prune}, topdir('fa') );
359 Check( scalar(keys %Expect_File) == 0 );
362 print "# check re-entrancy\n";
364 %Expect_File = (File::Spec->curdir => 1, file_path('fsl') => 1,
365 file_path('fa_ord') => 1, file_path('fab') => 1,
366 file_path('fab_ord') => 1, file_path('faba') => 1,
367 file_path('faa') => 1, file_path('faa_ord') => 1);
369 delete $Expect_File{ file_path('fsl') } unless $symlink_exists;
372 %Expect_Dir = ( dir_path('fa') => 1, dir_path('faa') => 1,
373 dir_path('fab') => 1, dir_path('faba') => 1,
374 dir_path('fb') => 1, dir_path('fba') => 1);
376 delete @Expect_Dir{ dir_path('fb'), dir_path('fba') } unless $symlink_exists;
378 File::Find::find( {wanted => sub { wanted_File_Dir_prune();
379 File::Find::find( {wanted => sub
380 {} }, File::Spec->curdir ); } },
383 Check( scalar(keys %Expect_File) == 0 );
386 # no_chdir is in effect, hence we use file_path_name to specify the expected paths for %Expect_File
388 %Expect_File = (file_path_name('fa') => 1,
389 file_path_name('fa', 'fsl') => 1,
390 file_path_name('fa', 'fa_ord') => 1,
391 file_path_name('fa', 'fab') => 1,
392 file_path_name('fa', 'fab', 'fab_ord') => 1,
393 file_path_name('fa', 'fab', 'faba') => 1,
394 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
395 file_path_name('fa', 'faa') => 1,
396 file_path_name('fa', 'faa', 'faa_ord') => 1,);
398 delete $Expect_File{ file_path_name('fa', 'fsl') } unless $symlink_exists;
401 %Expect_Dir = (dir_path('fa') => 1,
402 dir_path('fa', 'faa') => 1,
403 dir_path('fa', 'fab') => 1,
404 dir_path('fa', 'fab', 'faba') => 1,
406 dir_path('fb', 'fba') => 1);
408 delete @Expect_Dir{ dir_path('fb'), dir_path('fb', 'fba') }
409 unless $symlink_exists;
411 File::Find::find( {wanted => \&wanted_File_Dir, no_chdir => 1},
412 topdir('fa') ); Check( scalar(keys %Expect_File) == 0 );
417 %Expect_Name = (File::Spec->curdir => 1,
418 file_path_name('.', 'fa') => 1,
419 file_path_name('.', 'fa', 'fsl') => 1,
420 file_path_name('.', 'fa', 'fa_ord') => 1,
421 file_path_name('.', 'fa', 'fab') => 1,
422 file_path_name('.', 'fa', 'fab', 'fab_ord') => 1,
423 file_path_name('.', 'fa', 'fab', 'faba') => 1,
424 file_path_name('.', 'fa', 'fab', 'faba', 'faba_ord') => 1,
425 file_path_name('.', 'fa', 'faa') => 1,
426 file_path_name('.', 'fa', 'faa', 'faa_ord') => 1,
427 file_path_name('.', 'fb') => 1,
428 file_path_name('.', 'fb', 'fba') => 1,
429 file_path_name('.', 'fb', 'fba', 'fba_ord') => 1,
430 file_path_name('.', 'fb', 'fb_ord') => 1);
432 delete $Expect_Name{ file_path('.', 'fa', 'fsl') } unless $symlink_exists;
434 File::Find::finddepth( {wanted => \&wanted_Name}, File::Spec->curdir );
435 Check( scalar(keys %Expect_Name) == 0 );
438 # no_chdir is in effect, hence we use file_path_name to specify the
439 # expected paths for %Expect_File
441 %Expect_File = (File::Spec->curdir => 1,
442 file_path_name('.', 'fa') => 1,
443 file_path_name('.', 'fa', 'fsl') => 1,
444 file_path_name('.', 'fa', 'fa_ord') => 1,
445 file_path_name('.', 'fa', 'fab') => 1,
446 file_path_name('.', 'fa', 'fab', 'fab_ord') => 1,
447 file_path_name('.', 'fa', 'fab', 'faba') => 1,
448 file_path_name('.', 'fa', 'fab', 'faba', 'faba_ord') => 1,
449 file_path_name('.', 'fa', 'faa') => 1,
450 file_path_name('.', 'fa', 'faa', 'faa_ord') => 1,
451 file_path_name('.', 'fb') => 1,
452 file_path_name('.', 'fb', 'fba') => 1,
453 file_path_name('.', 'fb', 'fba', 'fba_ord') => 1,
454 file_path_name('.', 'fb', 'fb_ord') => 1);
456 delete $Expect_File{ file_path_name('.', 'fa', 'fsl') } unless $symlink_exists;
460 File::Find::finddepth( {wanted => \&wanted_File, no_chdir => 1},
461 File::Spec->curdir );
463 Check( scalar(keys %Expect_File) == 0 );
466 print "# check preprocess\n";
470 File::Spec->curdir => {fa => 1, fb => 1},
471 dir_path('.', 'fa') => {faa => 1, fab => 1, fa_ord => 1},
472 dir_path('.', 'fa', 'faa') => {faa_ord => 1},
473 dir_path('.', 'fa', 'fab') => {faba => 1, fab_ord => 1},
474 dir_path('.', 'fa', 'fab', 'faba') => {faba_ord => 1},
475 dir_path('.', 'fb') => {fba => 1, fb_ord => 1},
476 dir_path('.', 'fb', 'fba') => {fba_ord => 1}
479 File::Find::find( {wanted => \&noop_wanted,
480 preprocess => \&my_preprocess}, File::Spec->curdir );
482 Check( scalar(keys %Expect_Dir) == 0 );
485 print "# check postprocess\n";
489 File::Spec->curdir => 1,
490 dir_path('.', 'fa') => 1,
491 dir_path('.', 'fa', 'faa') => 1,
492 dir_path('.', 'fa', 'fab') => 1,
493 dir_path('.', 'fa', 'fab', 'faba') => 1,
494 dir_path('.', 'fb') => 1,
495 dir_path('.', 'fb', 'fba') => 1
498 File::Find::find( {wanted => \&noop_wanted,
499 postprocess => \&my_postprocess}, File::Spec->curdir );
501 Check( scalar(keys %Expect_Dir) == 0 );
504 print "# checking argument localization\n";
506 ### this checks the fix of perlbug [19977] ###
507 my @foo = qw( a b c d e f );
508 my %pre = map { $_ => } @foo;
510 File::Find::find( sub { } , 'fa' ) for @foo;
511 delete $pre{$_} for @foo;
513 Check( scalar( keys %pre ) == 0 );
516 # see thread starting
517 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2004-02/msg00351.html
519 print "# checking that &_ and %_ are still accessible and that\n",
520 "# tie magic on \$_ is not triggered\n";
533 sub FETCH {return 'N'};
534 sub TIESCALAR {bless []};
537 Check( scalar( keys %_ ) == 0 );
541 File::Find::find( sub { $true_count++; $_{$_}++; &_; } , 'fa' ) for @foo;
544 Check( $tie_called == 0);
545 Check( scalar( keys %_ ) == $true_count );
546 Check( $sub == $true_count );
547 Check( scalar( @foo ) == 1);
548 Check( $foo[0] eq 'N' );
551 if ( $symlink_exists ) {
552 print "# --- symbolic link tests --- \n";
553 $FastFileTests_OK= 1;
556 # Verify that File::Find::find will call wanted even if the topdir of
557 # is a symlink to a directory, and it shouldn't follow the link
558 # unless follow is set, which it isn't in this case
559 %Expect_File = ( file_path('fsl') => 1 );
562 File::Find::find( {wanted => \&wanted_File_Dir}, topdir('fa', 'fsl') );
563 Check( scalar(keys %Expect_File) == 0 );
566 %Expect_File = (File::Spec->curdir => 1, file_path('fa_ord') => 1,
567 file_path('fsl') => 1, file_path('fb_ord') => 1,
568 file_path('fba') => 1, file_path('fba_ord') => 1,
569 file_path('fab') => 1, file_path('fab_ord') => 1,
570 file_path('faba') => 1, file_path('faa') => 1,
571 file_path('faa_ord') => 1);
575 %Expect_Dir = (File::Spec->curdir => 1, dir_path('fa') => 1,
576 dir_path('faa') => 1, dir_path('fab') => 1,
577 dir_path('faba') => 1, dir_path('fb') => 1,
578 dir_path('fba') => 1);
580 File::Find::find( {wanted => \&wanted_File_Dir_prune,
581 follow_fast => 1}, topdir('fa') );
583 Check( scalar(keys %Expect_File) == 0 );
586 # no_chdir is in effect, hence we use file_path_name to specify
587 # the expected paths for %Expect_File
589 %Expect_File = (file_path_name('fa') => 1,
590 file_path_name('fa', 'fa_ord') => 1,
591 file_path_name('fa', 'fsl') => 1,
592 file_path_name('fa', 'fsl', 'fb_ord') => 1,
593 file_path_name('fa', 'fsl', 'fba') => 1,
594 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
595 file_path_name('fa', 'fab') => 1,
596 file_path_name('fa', 'fab', 'fab_ord') => 1,
597 file_path_name('fa', 'fab', 'faba') => 1,
598 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
599 file_path_name('fa', 'faa') => 1,
600 file_path_name('fa', 'faa', 'faa_ord') => 1);
604 %Expect_Dir = (dir_path('fa') => 1,
605 dir_path('fa', 'faa') => 1,
606 dir_path('fa', 'fab') => 1,
607 dir_path('fa', 'fab', 'faba') => 1,
609 dir_path('fb', 'fba') => 1);
611 File::Find::find( {wanted => \&wanted_File_Dir, follow_fast => 1,
612 no_chdir => 1}, topdir('fa') );
614 Check( scalar(keys %Expect_File) == 0 );
618 %Expect_Name = (file_path_name('fa') => 1,
619 file_path_name('fa', 'fa_ord') => 1,
620 file_path_name('fa', 'fsl') => 1,
621 file_path_name('fa', 'fsl', 'fb_ord') => 1,
622 file_path_name('fa', 'fsl', 'fba') => 1,
623 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
624 file_path_name('fa', 'fab') => 1,
625 file_path_name('fa', 'fab', 'fab_ord') => 1,
626 file_path_name('fa', 'fab', 'faba') => 1,
627 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
628 file_path_name('fa', 'faa') => 1,
629 file_path_name('fa', 'faa', 'faa_ord') => 1);
633 File::Find::finddepth( {wanted => \&wanted_Name,
634 follow_fast => 1}, topdir('fa') );
636 Check( scalar(keys %Expect_Name) == 0 );
638 # no_chdir is in effect, hence we use file_path_name to specify
639 # the expected paths for %Expect_File
641 %Expect_File = (file_path_name('fa') => 1,
642 file_path_name('fa', 'fa_ord') => 1,
643 file_path_name('fa', 'fsl') => 1,
644 file_path_name('fa', 'fsl', 'fb_ord') => 1,
645 file_path_name('fa', 'fsl', 'fba') => 1,
646 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
647 file_path_name('fa', 'fab') => 1,
648 file_path_name('fa', 'fab', 'fab_ord') => 1,
649 file_path_name('fa', 'fab', 'faba') => 1,
650 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
651 file_path_name('fa', 'faa') => 1,
652 file_path_name('fa', 'faa', 'faa_ord') => 1);
657 File::Find::finddepth( {wanted => \&wanted_File, follow_fast => 1,
658 no_chdir => 1}, topdir('fa') );
660 Check( scalar(keys %Expect_File) == 0 );
663 print "# check dangling symbolic links\n";
664 MkDir( dir_path('dangling_dir'), 0770 );
665 CheckDie( symlink( dir_path('dangling_dir'),
666 file_path('dangling_dir_sl') ) );
667 rmdir dir_path('dangling_dir');
668 touch(file_path('dangling_file'));
669 if ($^O eq 'MacOS') {
670 CheckDie( symlink('dangling_file', ':fa:dangling_file_sl') );
672 CheckDie( symlink('../dangling_file','fa/dangling_file_sl') );
674 unlink file_path('dangling_file');
677 # these tests should also emit a warning
680 %Expect_File = (File::Spec->curdir => 1,
681 file_path('dangling_file_sl') => 1,
682 file_path('fa_ord') => 1,
683 file_path('fsl') => 1,
684 file_path('fb_ord') => 1,
685 file_path('fba') => 1,
686 file_path('fba_ord') => 1,
687 file_path('fab') => 1,
688 file_path('fab_ord') => 1,
689 file_path('faba') => 1,
690 file_path('faba_ord') => 1,
691 file_path('faa') => 1,
692 file_path('faa_ord') => 1);
698 File::Find::find( {wanted => \&wanted_File, follow => 1,
700 sub { $warn_msg = "$_[0] is a dangling symbolic link" }
702 topdir('dangling_dir_sl'), topdir('fa') );
704 Check( scalar(keys %Expect_File) == 0 );
705 Check( $warn_msg =~ m|dangling_file_sl is a dangling symbolic link| );
706 unlink file_path('fa', 'dangling_file_sl'),
707 file_path('dangling_dir_sl');
712 print "# check recursion\n";
713 if ($^O eq 'MacOS') {
714 CheckDie( symlink(':fa:faa',':fa:faa:faa_sl') );
716 CheckDie( symlink('../faa','fa/faa/faa_sl') );
719 eval {File::Find::find( {wanted => \&simple_wanted, follow => 1,
720 no_chdir => 1}, topdir('fa') ); };
721 Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]faa_sl is a recursive symbolic link|i );
722 unlink file_path('fa', 'faa', 'faa_sl');
725 print "# check follow_skip (file)\n";
726 if ($^O eq 'MacOS') {
727 CheckDie( symlink(':fa:fa_ord',':fa:fa_ord_sl') ); # symlink to a file
729 CheckDie( symlink('./fa_ord','fa/fa_ord_sl') ); # symlink to a file
733 eval {File::Find::finddepth( {wanted => \&simple_wanted,
735 follow_skip => 0, no_chdir => 1},
738 Check( $@ =~ m|for_find[:/]fa[:/]fa_ord encountered a second time|i );
741 # no_chdir is in effect, hence we use file_path_name to specify
742 # the expected paths for %Expect_File
744 %Expect_File = (file_path_name('fa') => 1,
745 file_path_name('fa', 'fa_ord') => 2,
746 # We may encounter the symlink first
747 file_path_name('fa', 'fa_ord_sl') => 2,
748 file_path_name('fa', 'fsl') => 1,
749 file_path_name('fa', 'fsl', 'fb_ord') => 1,
750 file_path_name('fa', 'fsl', 'fba') => 1,
751 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
752 file_path_name('fa', 'fab') => 1,
753 file_path_name('fa', 'fab', 'fab_ord') => 1,
754 file_path_name('fa', 'fab', 'faba') => 1,
755 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
756 file_path_name('fa', 'faa') => 1,
757 file_path_name('fa', 'faa', 'faa_ord') => 1);
761 %Expect_Dir = (dir_path('fa') => 1,
762 dir_path('fa', 'faa') => 1,
763 dir_path('fa', 'fab') => 1,
764 dir_path('fa', 'fab', 'faba') => 1,
766 dir_path('fb','fba') => 1);
768 File::Find::finddepth( {wanted => \&wanted_File_Dir, follow => 1,
769 follow_skip => 1, no_chdir => 1},
771 Check( scalar(keys %Expect_File) == 0 );
772 unlink file_path('fa', 'fa_ord_sl');
775 print "# check follow_skip (directory)\n";
776 if ($^O eq 'MacOS') {
777 CheckDie( symlink(':fa:faa',':fa:faa_sl') ); # symlink to a directory
779 CheckDie( symlink('./faa','fa/faa_sl') ); # symlink to a directory
783 eval {File::Find::find( {wanted => \&simple_wanted, follow => 1,
784 follow_skip => 0, no_chdir => 1},
787 Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time|i );
792 eval {File::Find::find( {wanted => \&simple_wanted, follow => 1,
793 follow_skip => 1, no_chdir => 1},
796 Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time|i );
798 # no_chdir is in effect, hence we use file_path_name to specify
799 # the expected paths for %Expect_File
801 %Expect_File = (file_path_name('fa') => 1,
802 file_path_name('fa', 'fa_ord') => 1,
803 file_path_name('fa', 'fsl') => 1,
804 file_path_name('fa', 'fsl', 'fb_ord') => 1,
805 file_path_name('fa', 'fsl', 'fba') => 1,
806 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
807 file_path_name('fa', 'fab') => 1,
808 file_path_name('fa', 'fab', 'fab_ord') => 1,
809 file_path_name('fa', 'fab', 'faba') => 1,
810 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
811 file_path_name('fa', 'faa') => 1,
812 file_path_name('fa', 'faa', 'faa_ord') => 1,
813 # We may actually encounter the symlink first.
814 file_path_name('fa', 'faa_sl') => 1,
815 file_path_name('fa', 'faa_sl', 'faa_ord') => 1);
819 %Expect_Dir = (dir_path('fa') => 1,
820 dir_path('fa', 'faa') => 1,
821 dir_path('fa', 'fab') => 1,
822 dir_path('fa', 'fab', 'faba') => 1,
824 dir_path('fb', 'fba') => 1);
826 File::Find::find( {wanted => \&wanted_File_Dir, follow => 1,
827 follow_skip => 2, no_chdir => 1}, topdir('fa') );
829 # If we encountered the symlink first, then the entries corresponding to
830 # the real name remain, if the real name first then the symlink
831 my @names = sort keys %Expect_File;
832 Check( @names == 1 );
833 # Normalise both to the original name
834 s/_sl// foreach @names;
835 Check ($names[0] eq file_path_name('fa', 'faa', 'faa_ord'));
836 unlink file_path('fa', 'faa_sl');
841 # Win32 checks - [perl #41555]
842 if ($^O eq 'MSWin32') {
843 require File::Spec::Win32;
844 my ($volume) = File::Spec::Win32->splitpath($orig_dir, 1);
845 print STDERR "VOLUME = $volume\n";
848 %Expect_File = (File::Spec->curdir => 1,
849 file_path('fsl') => 1,
850 file_path('fa_ord') => 1,
851 file_path('fab') => 1,
852 file_path('fab_ord') => 1,
853 file_path('faba') => 1,
854 file_path('faba_ord') => 1,
855 file_path('faa') => 1,
856 file_path('faa_ord') => 1);
858 delete $Expect_File{ file_path('fsl') } unless $symlink_exists;
861 %Expect_Dir = (dir_path('fa') => 1,
862 dir_path('faa') => 1,
863 dir_path('fab') => 1,
864 dir_path('faba') => 1,
866 dir_path('fba') => 1);
870 File::Find::find( {wanted => \&wanted_File_Dir}, topdir('fa'));
871 Check( scalar(keys %Expect_File) == 0 );
874 %Expect_File = ($volume . file_path_name('fa') => 1,
875 $volume . file_path_name('fa', 'fsl') => 1,
876 $volume . file_path_name('fa', 'fa_ord') => 1,
877 $volume . file_path_name('fa', 'fab') => 1,
878 $volume . file_path_name('fa', 'fab', 'fab_ord') => 1,
879 $volume . file_path_name('fa', 'fab', 'faba') => 1,
880 $volume . file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
881 $volume . file_path_name('fa', 'faa') => 1,
882 $volume . file_path_name('fa', 'faa', 'faa_ord') => 1);
885 delete $Expect_File{ $volume . file_path_name('fa', 'fsl') } unless $symlink_exists;
888 %Expect_Dir = ($volume . dir_path('fa') => 1,
889 $volume . dir_path('fa', 'faa') => 1,
890 $volume . dir_path('fa', 'fab') => 1,
891 $volume . dir_path('fa', 'fab', 'faba') => 1);
893 File::Find::find( {wanted => \&wanted_File_Dir, no_chdir => 1}, $volume . topdir('fa'));
894 Check( scalar(keys %Expect_File) == 0 );