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