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