Regen modlib, toc.
[p5sagit/p5-mst-13.2.git] / t / lib / filefind.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
21use File::Find;
3fa6e24b 22use File::Spec;
24e8cdb8 23
c80f55d1 24cleanup();
25
3fa6e24b 26find({wanted => sub { print "ok 1\n" if $_ eq 'filefind.t'; } }, File::Spec->curdir);
27
28finddepth({wanted => sub { print "ok 2\n" if $_ eq 'filefind.t'; } }, File::Spec->curdir);
81793b90 29
81793b90 30my $case = 2;
5eb85357 31my $FastFileTests_OK = 0;
81793b90 32
c80f55d1 33sub cleanup {
3fa6e24b 34 if (-d dir_path('for_find')) {
35 chdir(dir_path('for_find'));
36 }
37 if (-d dir_path('fa')) {
38 unlink file_path('fa', 'fa_ord'),
39 file_path('fa', 'fsl'),
40 file_path('fa', 'faa', 'faa_ord'),
41 file_path('fa', 'fab', 'fab_ord'),
42 file_path('fa', 'fab', 'faba', 'faba_ord'),
43 file_path('fb', 'fb_ord'),
44 file_path('fb', 'fba', 'fba_ord');
45 rmdir dir_path('fa', 'faa');
46 rmdir dir_path('fa', 'fab', 'faba');
47 rmdir dir_path('fa', 'fab');
48 rmdir dir_path('fa');
49 rmdir dir_path('fb', 'fba');
50 rmdir dir_path('fb');
51 chdir File::Spec->updir;
52 rmdir dir_path('for_find');
c80f55d1 53 }
54}
55
81793b90 56END {
c80f55d1 57 cleanup();
81793b90 58}
59
60sub Check($) {
3fa6e24b 61 $case++;
62 if ($_[0]) { print "ok $case\n"; }
63 else { print "not ok $case\n"; }
81793b90 64}
65
66sub CheckDie($) {
3fa6e24b 67 $case++;
68 if ($_[0]) { print "ok $case\n"; }
69 else { print "not ok $case\n $!\n"; exit 0; }
81793b90 70}
71
72sub touch {
3fa6e24b 73 CheckDie( open(my $T,'>',$_[0]) );
81793b90 74}
75
76sub MkDir($$) {
3fa6e24b 77 CheckDie( mkdir($_[0],$_[1]) );
81793b90 78}
79
3fa6e24b 80sub wanted_File_Dir {
81 print "# \$File::Find::dir => '$File::Find::dir'\n";
82 print "# \$_ => '$_'\n";
83 s#\.$## if ($^O eq 'VMS' && $_ ne '.');
84 Check( $Expect_File{$_} );
85 if ( $FastFileTests_OK ) {
86 delete $Expect_File{ $_}
87 unless ( $Expect_Dir{$_} && ! -d _ );
88 } else {
89 delete $Expect_File{$_}
90 unless ( $Expect_Dir{$_} && ! -d $_ );
91 }
92}
7e47e6ff 93
3fa6e24b 94sub wanted_File_Dir_prune {
95 &wanted_File_Dir;
96 $File::Find::prune=1 if $_ eq 'faba';
81793b90 97}
98
3fa6e24b 99sub wanted_Name {
100 my $n = $File::Find::name;
101 $n =~ s#\.$## if ($^O eq 'VMS' && $n ne '.');
102 print "# \$File::Find::name => '$n'\n";
103 my $i = rindex($n,'/');
104 my $OK = exists($Expect_Name{$n});
105 unless ($^O eq 'MacOS') {
106 if ( $OK ) {
107 $OK= exists($Expect_Name{substr($n,0,$i)}) if $i >= 0;
108 }
7e47e6ff 109 }
3fa6e24b 110 Check($OK);
111 delete $Expect_Name{$n};
57907763 112}
113
3fa6e24b 114sub wanted_File {
115 print "# \$_ => '$_'\n";
116 s#\.$## if ($^O eq 'VMS' && $_ ne '.');
117 my $i = rindex($_,'/');
118 my $OK = exists($Expect_File{ $_});
119 unless ($^O eq 'MacOS') {
120 if ( $OK ) {
121 $OK= exists($Expect_File{ substr($_,0,$i)}) if $i >= 0;
122 }
7e47e6ff 123 }
3fa6e24b 124 Check($OK);
125 delete $Expect_File{ $_};
57907763 126}
127
7e47e6ff 128sub simple_wanted {
3fa6e24b 129 print "# \$File::Find::dir => '$File::Find::dir'\n";
130 print "# \$_ => '$_'\n";
7e47e6ff 131}
132
133sub noop_wanted {}
78eac027 134
7e47e6ff 135sub my_preprocess {
3fa6e24b 136 @files = @_;
137 print "# --preprocess--\n";
138 print "# \$File::Find::dir => '$File::Find::dir' \n";
139 foreach $file (@files) {
140 print "# $file \n";
141 delete $Expect_Dir{ $File::Find::dir }->{$file};
142 }
143 print "# --end preprocess--\n";
144 Check(scalar(keys %{$Expect_Dir{ $File::Find::dir }}) == 0);
145 if (scalar(keys %{$Expect_Dir{ $File::Find::dir }}) == 0) {
146 delete $Expect_Dir{ $File::Find::dir }
147 }
148 return @files;
7e47e6ff 149}
150
151sub my_postprocess {
3fa6e24b 152 print "# postprocess: \$File::Find::dir => '$File::Find::dir' \n";
153 delete $Expect_Dir{ $File::Find::dir};
7e47e6ff 154}
155
156
3fa6e24b 157# Use dir_path() to specify a directory path that's expected for $File::Find::dir
158# (%Expect_Dir). Also use it in file operations like chdir, rmdir etc.
159#
160# dir_path() concatenates directory names to form a _relative_ directory path,
161# independant from the platform it's run on, although there are limitations.
162# Don't try to create an absolute path, because that may fail on operating
163# systems that have the concept of volume names (e.g. Mac OS). Be careful when
164# you want to create an updir path like ../fa (Unix) or ::fa: (Mac OS). Plain
165# directory names will work best. As a special case, you can pass it a "." as
166# first argument, to create a directory path like "./fa/dir" on operating
167# systems other than Mac OS (actually, Mac OS will ignore the ".", if it's the
168# first argument). If there's no second argument, this function will return the
169# empty string on Mac OS and the string "./" otherwise.
170
171sub dir_path {
172 my $first_item = shift @_;
173
174 if ($first_item eq '.') {
175 if ($^O eq 'MacOS') {
176 return '' unless @_;
177 # ignore first argument; return a relative path
178 # with leading ":" and with trailing ":"
179 return File::Spec->catdir("", @_);
180 } else { # other OS
181 return './' unless @_;
182 my $path = File::Spec->catdir(@_);
183 # add leading "./"
184 $path = "./$path";
185 return $path;
186 }
187
188 } else { # $first_item ne '.'
189 return $first_item unless @_; # return plain filename
190 if ($^O eq 'MacOS') {
191 # relative path with leading ":" and with trailing ":"
192 return File::Spec->catdir("", $first_item, @_);
193 } else { # other OS
194 return File::Spec->catdir($first_item, @_);
195 }
196 }
197}
7e47e6ff 198
7e47e6ff 199
3fa6e24b 200# Use topdir() to specify a directory path that you want to pass to find/finddepth
201#
202# Basically, topdir() does the same as dir_path() (see above), except that there's
203# no trailing ":" on Mac OS.
7e47e6ff 204
3fa6e24b 205sub topdir {
206 my $path = dir_path(@_);
207 $path =~ s/:$// if ($^O eq 'MacOS');
208 return $path;
209}
7e47e6ff 210
7e47e6ff 211
3fa6e24b 212# Use file_path() to specify a file path that's expected for $_ (%Expect_File).
213# Also suitable for file operations like unlink etc.
214#
215# file_path() concatenates directory names (if any) and a filename to form a
216# _relative_ file path (the last argument is assumed to be a file). It's
217# independant from the platform it's run on, although there are limitations
218# (see the warnings for dir_path() above). As a special case, you can pass it a
219# "." as first argument, to create a file path like "./fa/file" on operating
220# systems other than Mac OS (actually, Mac OS will ignore the ".", if it's the
221# first argument). If there's no second argument, this function will return the
222# empty string on Mac OS and the string "./" otherwise.
223
224sub file_path {
225 my $first_item = shift @_;
226
227 if ($first_item eq '.') {
228 if ($^O eq 'MacOS') {
229 return '' unless @_;
230 # ignore first argument; return a relative path
231 # with leading ":", but without trailing ":"
232 return File::Spec->catfile("", @_);
233 } else { # other OS
234 return './' unless @_;
235 my $path = File::Spec->catfile(@_);
236 # add leading "./"
237 $path = "./$path";
238 return $path;
239 }
240
241 } else { # $first_item ne '.'
242 return $first_item unless @_; # return plain filename
243 if ($^O eq 'MacOS') {
244 # relative path with leading ":", but without trailing ":"
245 return File::Spec->catfile("", $first_item, @_);
246 } else { # other OS
247 return File::Spec->catfile($first_item, @_);
248 }
7e47e6ff 249 }
3fa6e24b 250}
251
252
253# Use file_path_name() to specify a file path that's expected for $File::Find::Name
254# (%Expect_Name). Note: When the no_chdir => 1 option is in effect, $_ is the same
255# as $File::Find::Name. In that case, also use this function to specify a file path
256# that's expected for $_.
257#
258# Basically, file_path_name() does the same as file_path() (see above), except that
259# there's always a leading ":" on Mac OS, even for plain file/directory names.
260
261sub file_path_name {
262 my $path = file_path(@_);
263 $path = ":$path" if (($^O eq 'MacOS') && ($path !~ /:/));
264 return $path;
265}
266
7e47e6ff 267
3fa6e24b 268
269MkDir( dir_path('for_find'), 0770 );
270CheckDie(chdir( dir_path('for_find')));
271MkDir( dir_path('fa'), 0770 );
272MkDir( dir_path('fb'), 0770 );
273touch( file_path('fb', 'fb_ord') );
274MkDir( dir_path('fb', 'fba'), 0770 );
275touch( file_path('fb', 'fba', 'fba_ord') );
276if ($^O eq 'MacOS') {
277 CheckDie( symlink(':fb',':fa:fsl') ) if $symlink_exists;
7e47e6ff 278} else {
3fa6e24b 279 CheckDie( symlink('../fb','fa/fsl') ) if $symlink_exists;
280}
281touch( file_path('fa', 'fa_ord') );
282
283MkDir( dir_path('fa', 'faa'), 0770 );
284touch( file_path('fa', 'faa', 'faa_ord') );
285MkDir( dir_path('fa', 'fab'), 0770 );
286touch( file_path('fa', 'fab', 'fab_ord') );
287MkDir( dir_path('fa', 'fab', 'faba'), 0770 );
288touch( file_path('fa', 'fab', 'faba', 'faba_ord') );
289
290
291%Expect_File = (File::Spec->curdir => 1, file_path('fsl') => 1, file_path('fa_ord') => 1,
292 file_path('fab') => 1, file_path('fab_ord') => 1, file_path('faba') => 1,
293 file_path('faa') => 1, file_path('faa_ord') => 1);
294delete $Expect_File{ file_path('fsl') } unless $symlink_exists;
295%Expect_Name = ();
296%Expect_Dir = ( dir_path('fa') => 1, dir_path('faa') => 1, dir_path('fab') => 1, dir_path('faba') => 1,
297 dir_path('fb') => 1, dir_path('fba') => 1);
298delete @Expect_Dir{ dir_path('fb'), dir_path('fba') } unless $symlink_exists;
299File::Find::find( {wanted => \&wanted_File_Dir_prune}, topdir('fa') );
300Check( scalar(keys %Expect_File) == 0 );
301
302
303print "# check re-entrancy\n";
304%Expect_File = (File::Spec->curdir => 1, file_path('fsl') => 1, file_path('fa_ord') => 1,
305 file_path('fab') => 1, file_path('fab_ord') => 1, file_path('faba') => 1,
306 file_path('faa') => 1, file_path('faa_ord') => 1);
307delete $Expect_File{ file_path('fsl') } unless $symlink_exists;
308%Expect_Name = ();
309%Expect_Dir = ( dir_path('fa') => 1, dir_path('faa') => 1, dir_path('fab') => 1, dir_path('faba') => 1,
310 dir_path('fb') => 1, dir_path('fba') => 1);
311delete @Expect_Dir{ dir_path('fb'), dir_path('fba') } unless $symlink_exists;
312File::Find::find( {wanted => sub {
313 wanted_File_Dir_prune();
314 File::Find::find( {wanted => sub {} }, File::Spec->curdir );
315 }
316 }, topdir('fa') );
317Check( scalar(keys %Expect_File) == 0 );
318
319
320# no_chdir is in effect, hence we use file_path_name to specify the expected paths for %Expect_File
321%Expect_File = (file_path_name('fa') => 1, file_path_name('fa', 'fsl') => 1, file_path_name('fa', 'fa_ord') => 1,
322 file_path_name('fa', 'fab') => 1, file_path_name('fa', 'fab', 'fab_ord') => 1,
323 file_path_name('fa', 'fab', 'faba') => 1, file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
324 file_path_name('fa', 'faa') => 1, file_path_name('fa', 'faa', 'faa_ord') => 1,);
325delete $Expect_File{ file_path_name('fa', 'fsl') } unless $symlink_exists;
326%Expect_Name = ();
327%Expect_Dir = (dir_path('fa') => 1, dir_path('fa', 'faa') => 1, dir_path('fa', 'fab') => 1,
328 dir_path('fa', 'fab', 'faba') => 1, dir_path('fb') => 1, dir_path('fb', 'fba') => 1);
329delete @Expect_Dir{ dir_path('fb'), dir_path('fb', 'fba') } unless $symlink_exists;
330File::Find::find( {wanted => \&wanted_File_Dir, no_chdir => 1}, topdir('fa') );
331Check( scalar(keys %Expect_File) == 0 );
332
333
334%Expect_File = ();
335%Expect_Name = (File::Spec->curdir => 1, file_path_name('.', 'fa') => 1, file_path_name('.', 'fa', 'fsl') => 1,
336 file_path_name('.', 'fa', 'fa_ord') => 1, file_path_name('.', 'fa', 'fab') => 1,
337 file_path_name('.', 'fa', 'fab', 'fab_ord') => 1, file_path_name('.', 'fa', 'fab', 'faba') => 1,
338 file_path_name('.', 'fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('.', 'fa', 'faa') => 1,
339 file_path_name('.', 'fa', 'faa', 'faa_ord') => 1, file_path_name('.', 'fb') => 1,
340 file_path_name('.', 'fb', 'fba') => 1, file_path_name('.', 'fb', 'fba', 'fba_ord') => 1,
341 file_path_name('.', 'fb', 'fb_ord') => 1);
342delete $Expect_Name{ file_path('.', 'fa', 'fsl') } unless $symlink_exists;
343%Expect_Dir = ();
344File::Find::finddepth( {wanted => \&wanted_Name}, File::Spec->curdir );
345Check( scalar(keys %Expect_Name) == 0 );
346
347
348# no_chdir is in effect, hence we use file_path_name to specify the expected paths for %Expect_File
349%Expect_File = (File::Spec->curdir => 1, file_path_name('.', 'fa') => 1, file_path_name('.', 'fa', 'fsl') => 1,
350 file_path_name('.', 'fa', 'fa_ord') => 1, file_path_name('.', 'fa', 'fab') => 1,
351 file_path_name('.', 'fa', 'fab', 'fab_ord') => 1, file_path_name('.', 'fa', 'fab', 'faba') => 1,
352 file_path_name('.', 'fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('.', 'fa', 'faa') => 1,
353 file_path_name('.', 'fa', 'faa', 'faa_ord') => 1, file_path_name('.', 'fb') => 1,
354 file_path_name('.', 'fb', 'fba') => 1, file_path_name('.', 'fb', 'fba', 'fba_ord') => 1,
355 file_path_name('.', 'fb', 'fb_ord') => 1);
356delete $Expect_File{ file_path_name('.', 'fa', 'fsl') } unless $symlink_exists;
357%Expect_Name = ();
358%Expect_Dir = ();
359File::Find::finddepth( {wanted => \&wanted_File, no_chdir => 1}, File::Spec->curdir );
360Check( scalar(keys %Expect_File) == 0 );
361
362
363print "# check preprocess\n";
364%Expect_File = ();
365%Expect_Name = ();
366%Expect_Dir = (
367 File::Spec->curdir => {fa => 1, fb => 1},
368 dir_path('.', 'fa') => {faa => 1, fab => 1, fa_ord => 1},
369 dir_path('.', 'fa', 'faa') => {faa_ord => 1},
370 dir_path('.', 'fa', 'fab') => {faba => 1, fab_ord => 1},
371 dir_path('.', 'fa', 'fab', 'faba') => {faba_ord => 1},
372 dir_path('.', 'fb') => {fba => 1, fb_ord => 1},
373 dir_path('.', 'fb', 'fba') => {fba_ord => 1}
374 );
375File::Find::find( {wanted => \&noop_wanted, preprocess => \&my_preprocess}, File::Spec->curdir );
376Check( scalar(keys %Expect_Dir) == 0 );
377
378
379print "# check postprocess\n";
380%Expect_File = ();
381%Expect_Name = ();
382%Expect_Dir = (
383 File::Spec->curdir => 1,
384 dir_path('.', 'fa') => 1,
385 dir_path('.', 'fa', 'faa') => 1,
386 dir_path('.', 'fa', 'fab') => 1,
387 dir_path('.', 'fa', 'fab', 'faba') => 1,
388 dir_path('.', 'fb') => 1,
389 dir_path('.', 'fb', 'fba') => 1
390 );
391File::Find::find( {wanted => \&noop_wanted, postprocess => \&my_postprocess}, File::Spec->curdir );
392Check( scalar(keys %Expect_Dir) == 0 );
393
394
395if ( $symlink_exists ) {
396 print "\n# --- symbolic link tests --- \n\n";
397 $FastFileTests_OK= 1;
7e47e6ff 398
7e47e6ff 399
3fa6e24b 400 # Verify that File::Find::find will call wanted even if the topdir of
401 # is a symlink to a directory, and it shouldn't follow the link
402 # unless follow is set, which it isn't in this case
403 %Expect_File = ( file_path('fsl') => 1 );
404 %Expect_Name = ();
405 %Expect_Dir = ();
406 File::Find::find( {wanted => \&wanted_File_Dir}, topdir('fa', 'fsl') );
407 Check( scalar(keys %Expect_File) == 0 );
408
409
410 %Expect_File = (File::Spec->curdir => 1, file_path('fa_ord') => 1, file_path('fsl') => 1,
411 file_path('fb_ord') => 1, file_path('fba') => 1, file_path('fba_ord') => 1,
412 file_path('fab') => 1, file_path('fab_ord') => 1, file_path('faba') => 1,
413 file_path('faa') => 1, file_path('faa_ord') => 1);
414 %Expect_Name = ();
415 %Expect_Dir = (File::Spec->curdir => 1, dir_path('fa') => 1, dir_path('faa') => 1, dir_path('fab') => 1,
416 dir_path('faba') => 1, dir_path('fb') => 1, dir_path('fba') => 1);
417 File::Find::find( {wanted => \&wanted_File_Dir_prune, follow_fast => 1}, topdir('fa') );
418 Check( scalar(keys %Expect_File) == 0 );
419
420
421 # no_chdir is in effect, hence we use file_path_name to specify the expected paths for %Expect_File
422 %Expect_File = (file_path_name('fa') => 1, file_path_name('fa', 'fa_ord') => 1,
423 file_path_name('fa', 'fsl') => 1, file_path_name('fa', 'fsl', 'fb_ord') => 1,
424 file_path_name('fa', 'fsl', 'fba') => 1, file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
425 file_path_name('fa', 'fab') => 1, file_path_name('fa', 'fab', 'fab_ord') => 1,
426 file_path_name('fa', 'fab', 'faba') => 1, file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
427 file_path_name('fa', 'faa') => 1, file_path_name('fa', 'faa', 'faa_ord') => 1);
428 %Expect_Name = ();
429 %Expect_Dir = (dir_path('fa') => 1, dir_path('fa', 'faa') => 1, dir_path('fa', 'fab') => 1,
430 dir_path('fa', 'fab', 'faba') => 1, dir_path('fb') => 1, dir_path('fb', 'fba') => 1);
431 File::Find::find( {wanted => \&wanted_File_Dir, follow_fast => 1, no_chdir => 1}, topdir('fa') );
432 Check( scalar(keys %Expect_File) == 0 );
433
434
435 %Expect_File = ();
436 %Expect_Name = (file_path_name('fa') => 1, file_path_name('fa', 'fa_ord') => 1, file_path_name('fa', 'fsl') => 1,
437 file_path_name('fa', 'fsl', 'fb_ord') => 1, file_path_name('fa', 'fsl', 'fba') => 1,
438 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, file_path_name('fa', 'fab') => 1,
439 file_path_name('fa', 'fab', 'fab_ord') => 1, file_path_name('fa', 'fab', 'faba') => 1,
440 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('fa', 'faa') => 1,
441 file_path_name('fa', 'faa', 'faa_ord') => 1);
442 %Expect_Dir = ();
443 File::Find::finddepth( {wanted => \&wanted_Name, follow_fast => 1}, topdir('fa') );
444 Check( scalar(keys %Expect_Name) == 0 );
445
446
447 # no_chdir is in effect, hence we use file_path_name to specify the expected paths for %Expect_File
448 %Expect_File = (file_path_name('fa') => 1, file_path_name('fa', 'fa_ord') => 1, file_path_name('fa', 'fsl') => 1,
449 file_path_name('fa', 'fsl', 'fb_ord') => 1, file_path_name('fa', 'fsl', 'fba') => 1,
450 file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, file_path_name('fa', 'fab') => 1,
451 file_path_name('fa', 'fab', 'fab_ord') => 1, file_path_name('fa', 'fab', 'faba') => 1,
452 file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('fa', 'faa') => 1,
453 file_path_name('fa', 'faa', 'faa_ord') => 1);
454 %Expect_Name = ();
455 %Expect_Dir = ();
456 File::Find::finddepth( {wanted => \&wanted_File, follow_fast => 1, no_chdir => 1}, topdir('fa') );
457 Check( scalar(keys %Expect_File) == 0 );
458
459
460 print "# check dangling symbolic links\n";
461 MkDir( dir_path('dangling_dir'), 0770 );
462 CheckDie( symlink( dir_path('dangling_dir'), file_path('dangling_dir_sl') ) );
463 rmdir dir_path('dangling_dir');
464 touch(file_path('dangling_file'));
465 if ($^O eq 'MacOS') {
466 CheckDie( symlink('dangling_file', ':fa:dangling_file_sl') );
467 } else {
468 CheckDie( symlink('../dangling_file','fa/dangling_file_sl') );
469 }
470 unlink file_path('dangling_file');
471
472 {
473 # these tests should also emit a warning
474 local $^W = 1;
475 %Expect_File = (File::Spec->curdir => 1, file_path('fa_ord') => 1, file_path('fsl') => 1,
476 file_path('fb_ord') => 1, file_path('fba') => 1, file_path('fba_ord') => 1,
477 file_path('fab') => 1, file_path('fab_ord') => 1, file_path('faba') => 1,
478 file_path('faba_ord') => 1, file_path('faa') => 1, file_path('faa_ord') => 1);
479 %Expect_Name = ();
480 %Expect_Dir = ();
481 undef $warn_msg;
80e52b73 482 File::Find::find( {wanted => \&wanted_File, follow => 1, dangling_symlinks => sub { $warn_msg = "$_[0] is a dangling symbolic link" }}, topdir('dangling_dir_sl'), topdir('fa') );
3fa6e24b 483 Check( scalar(keys %Expect_File) == 0 );
484 Check( $warn_msg =~ m|dangling_dir_sl is a dangling symbolic link| );
485 unlink file_path('fa', 'dangling_file_sl'), file_path('dangling_dir_sl');
486 }
487
488
489 print "# check recursion\n";
490 if ($^O eq 'MacOS') {
491 CheckDie( symlink(':fa:faa',':fa:faa:faa_sl') );
492 } else {
493 CheckDie( symlink('../faa','fa/faa/faa_sl') );
494 }
7e47e6ff 495 undef $@;
3fa6e24b 496 eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, no_chdir => 1}, topdir('fa') ); };
497 Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]faa_sl is a recursive symbolic link| );
498 unlink file_path('fa', 'faa', 'faa_sl');
7e47e6ff 499
3fa6e24b 500
501 print "# check follow_skip (file)\n";
502 if ($^O eq 'MacOS') {
503 CheckDie( symlink(':fa:fa_ord',':fa:fa_ord_sl') ); # symlink to a file
504 } else {
505 CheckDie( symlink('./fa_ord','fa/fa_ord_sl') ); # symlink to a file
506 }
7e47e6ff 507 undef $@;
3fa6e24b 508 eval {File::Find::finddepth( {wanted => \&simple_wanted, follow => 1,follow_skip => 0, no_chdir => 1},
509 topdir('fa') );};
510 Check( $@ =~ m|for_find[:/]fa[:/]fa_ord encountered a second time| );
7e47e6ff 511
7e47e6ff 512
3fa6e24b 513 # no_chdir is in effect, hence we use file_path_name to specify the expected paths for %Expect_File
514 %Expect_File = (file_path_name('fa') => 1, file_path_name('fa', 'fa_ord') => 1,
515 file_path_name('fa', 'fsl') => 1, file_path_name('fa', 'fsl', 'fb_ord') => 1,
516 file_path_name('fa', 'fsl', 'fba') => 1, file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
517 file_path_name('fa', 'fab') => 1, file_path_name('fa', 'fab', 'fab_ord') => 1,
518 file_path_name('fa', 'fab', 'faba') => 1, file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
519 file_path_name('fa', 'faa') => 1, file_path_name('fa', 'faa', 'faa_ord') => 1);
520
521 %Expect_Name = ();
522 %Expect_Dir = (dir_path('fa') => 1, dir_path('fa', 'faa') => 1, dir_path('fa', 'fab') => 1,
523 dir_path('fa', 'fab', 'faba') => 1, dir_path('fb') => 1, dir_path('fb', 'fba') => 1);
524 File::Find::finddepth( {wanted => \&wanted_File_Dir, follow => 1, follow_skip => 1, no_chdir => 1},
525 topdir('fa') );
526 Check( scalar(keys %Expect_File) == 0 );
527 unlink file_path('fa', 'fa_ord_sl');
528
529
530 print "# check follow_skip (directory)\n";
531 if ($^O eq 'MacOS') {
532 CheckDie( symlink(':fa:faa',':fa:faa_sl') ); # symlink to a directory
533 } else {
534 CheckDie( symlink('./faa','fa/faa_sl') ); # symlink to a directory
7e47e6ff 535 }
3fa6e24b 536 undef $@;
537 eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, follow_skip => 0, no_chdir => 1},
538 topdir('fa') );};
539 Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time| );
540
541
542 undef $@;
543 eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, follow_skip => 1, no_chdir => 1},
544 topdir('fa') );};
545 Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time| );
546
547
548 # no_chdir is in effect, hence we use file_path_name to specify the expected paths for %Expect_File
549 %Expect_File = (file_path_name('fa') => 1, file_path_name('fa', 'fa_ord') => 1,
550 file_path_name('fa', 'fsl') => 1, file_path_name('fa', 'fsl', 'fb_ord') => 1,
551 file_path_name('fa', 'fsl', 'fba') => 1, file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1,
552 file_path_name('fa', 'fab') => 1, file_path_name('fa', 'fab', 'fab_ord') => 1,
553 file_path_name('fa', 'fab', 'faba') => 1, file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1,
554 file_path_name('fa', 'faa') => 1, file_path_name('fa', 'faa', 'faa_ord') => 1);
555
556 %Expect_Name = ();
557 %Expect_Dir = (dir_path('fa') => 1, dir_path('fa', 'faa') => 1, dir_path('fa', 'fab') => 1,
558 dir_path('fa', 'fab', 'faba') => 1, dir_path('fb') => 1, dir_path('fb', 'fba') => 1);
559 File::Find::find( {wanted => \&wanted_File_Dir, follow => 1, follow_skip => 2, no_chdir => 1}, topdir('fa') );
560 Check( scalar(keys %Expect_File) == 0 );
561 unlink file_path('fa', 'faa_sl');
562
563}
81793b90 564