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