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