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