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