Commit | Line | Data |
---|---|---|
3fa6e24b | 1 | #!./perl |
81793b90 GS |
2 | |
3 | ||
3fa6e24b TW |
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 | |
81793b90 | 7 | my $symlink_exists = eval { symlink("",""); 1 }; |
7e47e6ff | 8 | my $warn_msg; |
3fa6e24b | 9 | |
1a3850a5 GA |
10 | |
11 | BEGIN { | |
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 |
18 | if ( $symlink_exists ) { print "1..188\n"; } |
19 | else { print "1..78\n"; } | |
1a3850a5 | 20 | |
7dc9aaa5 MS |
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 CL |
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 | } | |
6455dd3b | 51 | |
c80f55d1 JH |
52 | cleanup(); |
53 | ||
922e63eb | 54 | find({wanted => sub { print "ok 1\n" if $_ eq 'commonsense.t'; } }, |
bb7dc48b | 55 | File::Spec->curdir); |
3fa6e24b | 56 | |
922e63eb | 57 | finddepth({wanted => sub { print "ok 2\n" if $_ eq 'commonsense.t'; } }, |
bb7dc48b | 58 | File::Spec->curdir); |
81793b90 | 59 | |
6455dd3b | 60 | |
81793b90 | 61 | my $case = 2; |
5eb85357 | 62 | my $FastFileTests_OK = 0; |
81793b90 | 63 | |
c80f55d1 | 64 | sub cleanup { |
3fa6e24b TW |
65 | if (-d dir_path('for_find')) { |
66 | chdir(dir_path('for_find')); | |
6fecce66 RGS |
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"; | |
c80f55d1 JH |
86 | } |
87 | } | |
88 | ||
81793b90 | 89 | END { |
c80f55d1 | 90 | cleanup(); |
81793b90 GS |
91 | } |
92 | ||
93 | sub Check($) { | |
3fa6e24b TW |
94 | $case++; |
95 | if ($_[0]) { print "ok $case\n"; } | |
96 | else { print "not ok $case\n"; } | |
81793b90 GS |
97 | } |
98 | ||
99 | sub CheckDie($) { | |
3fa6e24b TW |
100 | $case++; |
101 | if ($_[0]) { print "ok $case\n"; } | |
102 | else { print "not ok $case\n $!\n"; exit 0; } | |
81793b90 GS |
103 | } |
104 | ||
105 | sub touch { | |
3fa6e24b | 106 | CheckDie( open(my $T,'>',$_[0]) ); |
81793b90 GS |
107 | } |
108 | ||
109 | sub MkDir($$) { | |
3fa6e24b | 110 | CheckDie( mkdir($_[0],$_[1]) ); |
81793b90 GS |
111 | } |
112 | ||
3fa6e24b TW |
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 | } | |
7e47e6ff | 126 | |
3fa6e24b TW |
127 | sub wanted_File_Dir_prune { |
128 | &wanted_File_Dir; | |
129 | $File::Find::prune=1 if $_ eq 'faba'; | |
81793b90 GS |
130 | } |
131 | ||
3fa6e24b TW |
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 | } | |
7e47e6ff | 142 | } |
3fa6e24b TW |
143 | Check($OK); |
144 | delete $Expect_Name{$n}; | |
57907763 GS |
145 | } |
146 | ||
3fa6e24b TW |
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 | } | |
7e47e6ff | 156 | } |
3fa6e24b TW |
157 | Check($OK); |
158 | delete $Expect_File{ $_}; | |
57907763 GS |
159 | } |
160 | ||
7e47e6ff | 161 | sub simple_wanted { |
3fa6e24b TW |
162 | print "# \$File::Find::dir => '$File::Find::dir'\n"; |
163 | print "# \$_ => '$_'\n"; | |
7e47e6ff JH |
164 | } |
165 | ||
166 | sub noop_wanted {} | |
78eac027 | 167 | |
7e47e6ff | 168 | sub my_preprocess { |
3fa6e24b TW |
169 | @files = @_; |
170 | print "# --preprocess--\n"; | |
171 | print "# \$File::Find::dir => '$File::Find::dir' \n"; | |
172 | foreach $file (@files) { | |
30db15be | 173 | $file =~ s/\.(dir)?$// if $^O eq 'VMS'; |
3fa6e24b TW |
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; | |
7e47e6ff JH |
183 | } |
184 | ||
185 | sub my_postprocess { | |
3fa6e24b TW |
186 | print "# postprocess: \$File::Find::dir => '$File::Find::dir' \n"; |
187 | delete $Expect_Dir{ $File::Find::dir}; | |
7e47e6ff JH |
188 | } |
189 | ||
190 | ||
bb7dc48b JH |
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. | |
3fa6e24b | 194 | # |
2586ba89 | 195 | # dir_path() concatenates directory names to form a *relative* |
30db15be | 196 | # directory path, independent from the platform it's run on, although |
2586ba89 | 197 | # there are limitations. Don't try to create an absolute path, |
bb7dc48b | 198 | # because that may fail on operating systems that have the concept of |
2586ba89 JH |
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 | |
bb7dc48b JH |
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. | |
3fa6e24b TW |
205 | |
206 | sub dir_path { | |
2586ba89 | 207 | my $first_arg = shift @_; |
3fa6e24b | 208 | |
2586ba89 | 209 | if ($first_arg eq '.') { |
3fa6e24b TW |
210 | if ($^O eq 'MacOS') { |
211 | return '' unless @_; | |
212 | # ignore first argument; return a relative path | |
213 | # with leading ":" and with trailing ":" | |
2586ba89 | 214 | return File::Spec->catdir(@_); |
3fa6e24b TW |
215 | } else { # other OS |
216 | return './' unless @_; | |
217 | my $path = File::Spec->catdir(@_); | |
218 | # add leading "./" | |
219 | $path = "./$path"; | |
220 | return $path; | |
221 | } | |
222 | ||
2586ba89 JH |
223 | } else { # $first_arg ne '.' |
224 | return $first_arg unless @_; # return plain filename | |
225 | return File::Spec->catdir($first_arg, @_); # relative path | |
3fa6e24b TW |
226 | } |
227 | } | |
7e47e6ff | 228 | |
7e47e6ff | 229 | |
bb7dc48b | 230 | # Use topdir() to specify a directory path that you want to pass to |
2586ba89 JH |
231 | # find/finddepth. Basically, topdir() does the same as dir_path() (see |
232 | # above), except that there's no trailing ":" on Mac OS. | |
7e47e6ff | 233 | |
3fa6e24b TW |
234 | sub topdir { |
235 | my $path = dir_path(@_); | |
236 | $path =~ s/:$// if ($^O eq 'MacOS'); | |
237 | return $path; | |
238 | } | |
7e47e6ff | 239 | |
7e47e6ff | 240 | |
bb7dc48b | 241 | # Use file_path() to specify a file path that's expected for $_ |
2586ba89 | 242 | # (%Expect_File). Also suitable for file operations like unlink etc. |
3fa6e24b | 243 | # |
bb7dc48b | 244 | # file_path() concatenates directory names (if any) and a filename to |
2586ba89 | 245 | # form a *relative* file path (the last argument is assumed to be a |
30db15be | 246 | # file). It's independent from the platform it's run on, although |
2586ba89 JH |
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. | |
3fa6e24b TW |
253 | |
254 | sub file_path { | |
2586ba89 | 255 | my $first_arg = shift @_; |
3fa6e24b | 256 | |
2586ba89 | 257 | if ($first_arg eq '.') { |
3fa6e24b TW |
258 | if ($^O eq 'MacOS') { |
259 | return '' unless @_; | |
260 | # ignore first argument; return a relative path | |
261 | # with leading ":", but without trailing ":" | |
2586ba89 | 262 | return File::Spec->catfile(@_); |
3fa6e24b TW |
263 | } else { # other OS |
264 | return './' unless @_; | |
265 | my $path = File::Spec->catfile(@_); | |
266 | # add leading "./" | |
267 | $path = "./$path"; | |
268 | return $path; | |
269 | } | |
270 | ||
2586ba89 JH |
271 | } else { # $first_arg ne '.' |
272 | return $first_arg unless @_; # return plain filename | |
273 | return File::Spec->catfile($first_arg, @_); # relative path | |
7e47e6ff | 274 | } |
3fa6e24b TW |
275 | } |
276 | ||
277 | ||
bb7dc48b JH |
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 $_. | |
3fa6e24b | 283 | # |
bb7dc48b JH |
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. | |
3fa6e24b TW |
287 | |
288 | sub file_path_name { | |
289 | my $path = file_path(@_); | |
290 | $path = ":$path" if (($^O eq 'MacOS') && ($path !~ /:/)); | |
291 | return $path; | |
292 | } | |
293 | ||
7e47e6ff | 294 | |
3fa6e24b TW |
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; | |
7e47e6ff | 305 | } else { |
3fa6e24b TW |
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 | ||
bb7dc48b JH |
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, | |
3fa6e24b | 321 | file_path('faa') => 1, file_path('faa_ord') => 1); |
bb7dc48b | 322 | |
3fa6e24b TW |
323 | delete $Expect_File{ file_path('fsl') } unless $symlink_exists; |
324 | %Expect_Name = (); | |
bb7dc48b JH |
325 | |
326 | %Expect_Dir = ( dir_path('fa') => 1, dir_path('faa') => 1, | |
327 | dir_path('fab') => 1, dir_path('faba') => 1, | |
3fa6e24b | 328 | dir_path('fb') => 1, dir_path('fba') => 1); |
bb7dc48b | 329 | |
3fa6e24b TW |
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"; | |
bb7dc48b JH |
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, | |
3fa6e24b | 340 | file_path('faa') => 1, file_path('faa_ord') => 1); |
bb7dc48b | 341 | |
3fa6e24b TW |
342 | delete $Expect_File{ file_path('fsl') } unless $symlink_exists; |
343 | %Expect_Name = (); | |
bb7dc48b JH |
344 | |
345 | %Expect_Dir = ( dir_path('fa') => 1, dir_path('faa') => 1, | |
346 | dir_path('fab') => 1, dir_path('faba') => 1, | |
3fa6e24b | 347 | dir_path('fb') => 1, dir_path('fba') => 1); |
bb7dc48b | 348 | |
3fa6e24b | 349 | delete @Expect_Dir{ dir_path('fb'), dir_path('fba') } unless $symlink_exists; |
bb7dc48b JH |
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 | ||
3fa6e24b TW |
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 | |
bb7dc48b JH |
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 | ||
3fa6e24b TW |
371 | delete $Expect_File{ file_path_name('fa', 'fsl') } unless $symlink_exists; |
372 | %Expect_Name = (); | |
bb7dc48b JH |
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 ); | |
3fa6e24b TW |
386 | |
387 | ||
388 | %Expect_File = (); | |
bb7dc48b JH |
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 | ||
3fa6e24b TW |
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 | ||
bb7dc48b JH |
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 | ||
3fa6e24b TW |
429 | delete $Expect_File{ file_path_name('.', 'fa', 'fsl') } unless $symlink_exists; |
430 | %Expect_Name = (); | |
431 | %Expect_Dir = (); | |
bb7dc48b JH |
432 | |
433 | File::Find::finddepth( {wanted => \&wanted_File, no_chdir => 1}, | |
434 | File::Spec->curdir ); | |
435 | ||
3fa6e24b TW |
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 | ); | |
bb7dc48b JH |
451 | |
452 | File::Find::find( {wanted => \&noop_wanted, | |
453 | preprocess => \&my_preprocess}, File::Spec->curdir ); | |
454 | ||
3fa6e24b TW |
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 | ); | |
bb7dc48b JH |
470 | |
471 | File::Find::find( {wanted => \&noop_wanted, | |
472 | postprocess => \&my_postprocess}, File::Spec->curdir ); | |
473 | ||
3fa6e24b TW |
474 | Check( scalar(keys %Expect_Dir) == 0 ); |
475 | ||
476 | ||
477 | if ( $symlink_exists ) { | |
bb7dc48b | 478 | print "# --- symbolic link tests --- \n"; |
3fa6e24b | 479 | $FastFileTests_OK= 1; |
7e47e6ff | 480 | |
7e47e6ff | 481 | |
3fa6e24b TW |
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 | ||
bb7dc48b JH |
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 | ||
3fa6e24b | 499 | %Expect_Name = (); |
bb7dc48b JH |
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 | ||
3fa6e24b TW |
509 | Check( scalar(keys %Expect_File) == 0 ); |
510 | ||
511 | ||
bb7dc48b JH |
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 | ||
3fa6e24b | 528 | %Expect_Name = (); |
3fa6e24b | 529 | |
bb7dc48b JH |
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 ); | |
3fa6e24b TW |
541 | |
542 | %Expect_File = (); | |
bb7dc48b JH |
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, | |
3fa6e24b | 555 | file_path_name('fa', 'faa', 'faa_ord') => 1); |
bb7dc48b | 556 | |
3fa6e24b | 557 | %Expect_Dir = (); |
3fa6e24b | 558 | |
bb7dc48b JH |
559 | File::Find::finddepth( {wanted => \&wanted_Name, |
560 | follow_fast => 1}, topdir('fa') ); | |
561 | ||
562 | Check( scalar(keys %Expect_Name) == 0 ); | |
3fa6e24b | 563 | |
bb7dc48b JH |
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, | |
3fa6e24b | 578 | file_path_name('fa', 'faa', 'faa_ord') => 1); |
bb7dc48b | 579 | |
3fa6e24b TW |
580 | %Expect_Name = (); |
581 | %Expect_Dir = (); | |
bb7dc48b JH |
582 | |
583 | File::Find::finddepth( {wanted => \&wanted_File, follow_fast => 1, | |
584 | no_chdir => 1}, topdir('fa') ); | |
585 | ||
3fa6e24b TW |
586 | Check( scalar(keys %Expect_File) == 0 ); |
587 | ||
588 | ||
589 | print "# check dangling symbolic links\n"; | |
590 | MkDir( dir_path('dangling_dir'), 0770 ); | |
bb7dc48b JH |
591 | CheckDie( symlink( dir_path('dangling_dir'), |
592 | file_path('dangling_dir_sl') ) ); | |
3fa6e24b TW |
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 | |
bb7dc48b JH |
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 | ||
3fa6e24b TW |
619 | %Expect_Name = (); |
620 | %Expect_Dir = (); | |
621 | undef $warn_msg; | |
bb7dc48b JH |
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 | ||
3fa6e24b TW |
629 | Check( scalar(keys %Expect_File) == 0 ); |
630 | Check( $warn_msg =~ m|dangling_dir_sl is a dangling symbolic link| ); | |
bb7dc48b JH |
631 | unlink file_path('fa', 'dangling_file_sl'), |
632 | file_path('dangling_dir_sl'); | |
633 | ||
3fa6e24b TW |
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 | } | |
7e47e6ff | 643 | undef $@; |
bb7dc48b JH |
644 | eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, |
645 | no_chdir => 1}, topdir('fa') ); }; | |
3fa6e24b TW |
646 | Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]faa_sl is a recursive symbolic link| ); |
647 | unlink file_path('fa', 'faa', 'faa_sl'); | |
7e47e6ff | 648 | |
3fa6e24b TW |
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 | } | |
7e47e6ff | 656 | undef $@; |
bb7dc48b JH |
657 | |
658 | eval {File::Find::finddepth( {wanted => \&simple_wanted, | |
659 | follow => 1, | |
660 | follow_skip => 0, no_chdir => 1}, | |
661 | topdir('fa') );}; | |
662 | ||
3fa6e24b | 663 | Check( $@ =~ m|for_find[:/]fa[:/]fa_ord encountered a second time| ); |
7e47e6ff | 664 | |
7e47e6ff | 665 | |
bb7dc48b JH |
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); | |
3fa6e24b TW |
681 | |
682 | %Expect_Name = (); | |
bb7dc48b JH |
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}, | |
3fa6e24b | 693 | topdir('fa') ); |
bb7dc48b | 694 | |
3fa6e24b TW |
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 | |
7e47e6ff | 704 | } |
3fa6e24b | 705 | undef $@; |
bb7dc48b JH |
706 | |
707 | eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, | |
708 | follow_skip => 0, no_chdir => 1}, | |
3fa6e24b | 709 | topdir('fa') );}; |
bb7dc48b | 710 | |
3fa6e24b TW |
711 | Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time| ); |
712 | ||
713 | ||
714 | undef $@; | |
bb7dc48b JH |
715 | |
716 | eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, | |
717 | follow_skip => 1, no_chdir => 1}, | |
3fa6e24b | 718 | topdir('fa') );}; |
bb7dc48b | 719 | |
3fa6e24b TW |
720 | Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time| ); |
721 | ||
bb7dc48b JH |
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); | |
3fa6e24b TW |
737 | |
738 | %Expect_Name = (); | |
bb7dc48b JH |
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 | ||
3fa6e24b TW |
750 | Check( scalar(keys %Expect_File) == 0 ); |
751 | unlink file_path('fa', 'faa_sl'); | |
752 | ||
753 | } | |
81793b90 | 754 |