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