This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
more Compiler tweaks for useithreads
[perl5.git] / t / lib / filefind.t
CommitLineData
81793b90
GS
1####!./perl
2
3
4my %Expect;
5my $symlink_exists = eval { symlink("",""); 1 };
1a3850a5
GA
6
7BEGIN {
8 chdir 't' if -d 't';
93430cb4 9 unshift @INC, '../lib';
1a3850a5
GA
10}
11
81793b90 12if ( $symlink_exists ) { print "1..59\n"; }
fd886cf2 13else { print "1..31\n"; }
1a3850a5
GA
14
15use File::Find;
16
1a3850a5 17find(sub { print "ok 1\n" if $_ eq 'filefind.t'; }, ".");
55d729e4 18finddepth(sub { print "ok 2\n" if $_ eq 'filefind.t'; }, ".");
81793b90
GS
19
20
21my $case = 2;
22
23END {
24 unlink 'FA/FA_ord','FA/FSL','FA/FAA/FAA_ord',
25 'FA/FAB/FAB_ord','FA/FAB/FABA/FABA_ord','FB/FB_ord','FB/FBA/FBA_ord';
26 rmdir 'FA/FAA';
27 rmdir 'FA/FAB/FABA';
28 rmdir 'FA/FAB';
29 rmdir 'FA';
30 rmdir 'FB/FBA';
31 rmdir 'FB';
32}
33
34sub Check($) {
35 $case++;
36 if ($_[0]) { print "ok $case\n"; }
37 else { print "not ok $case\n"; }
38}
39
40sub CheckDie($) {
41 $case++;
42 if ($_[0]) { print "ok $case\n"; }
43 else { print "not ok $case\n $!\n"; exit 0; }
44}
45
46sub touch {
47 CheckDie( open(my $T,'>',$_[0]) );
48}
49
50sub MkDir($$) {
51 CheckDie( mkdir($_[0],$_[1]) );
52}
53
54sub wanted {
fd886cf2 55 print "# '$_' => 1\n";
81793b90
GS
56 Check( $Expect{$_} );
57 delete $Expect{$_};
58 $File::Find::prune=1 if $_ eq 'FABA';
59}
60
61MkDir( 'FA',0770 );
62MkDir( 'FB',0770 );
63touch('FB/FB_ord');
64MkDir( 'FB/FBA',0770 );
65touch('FB/FBA/FBA_ord');
66CheckDie( symlink('../FB','FA/FSL') ) if $symlink_exists;
67touch('FA/FA_ord');
68
69MkDir( 'FA/FAA',0770 );
70touch('FA/FAA/FAA_ord');
71MkDir( 'FA/FAB',0770 );
72touch('FA/FAB/FAB_ord');
73MkDir( 'FA/FAB/FABA',0770 );
74touch('FA/FAB/FABA/FABA_ord');
75
fd886cf2
GS
76%Expect = ('.' => 1, 'FSL' => 1, 'FA_ord' => 1, 'FAB' => 1, 'FAB_ord' => 1,
77 'FABA' => 1, 'FAA' => 1, 'FAA_ord' => 1);
78delete $Expect{'FSL'} unless $symlink_exists;
81793b90
GS
79File::Find::find( {wanted => \&wanted, },'FA' );
80Check( scalar(keys %Expect) == 0 );
81
fd886cf2
GS
82%Expect=('FA' => 1, 'FA/FSL' => 1, 'FA/FA_ord' => 1, 'FA/FAB' => 1,
83 'FA/FAB/FAB_ord' => 1, 'FA/FAB/FABA' => 1,
84 'FA/FAB/FABA/FABA_ord' => 1, 'FA/FAA' => 1, 'FA/FAA/FAA_ord' => 1);
85delete $Expect{'FA/FSL'} unless $symlink_exists;
81793b90
GS
86File::Find::find( {wanted => \&wanted, no_chdir => 1},'FA' );
87
88Check( scalar(keys %Expect) == 0 );
89
90if ( $symlink_exists ) {
91 %Expect=('.' => 1, 'FA_ord' => 1, 'FSL' => 1, 'FB_ord' => 1, 'FBA' => 1,
92 'FBA_ord' => 1, 'FAB' => 1, 'FAB_ord' => 1, 'FABA' => 1, 'FAA' => 1,
93 'FAA_ord' => 1);
94
95 File::Find::find( {wanted => \&wanted, follow_fast => 1},'FA' );
96 Check( scalar(keys %Expect) == 0 );
97 %Expect=('FA' => 1, 'FA/FA_ord' => 1, 'FA/FSL' => 1, 'FA/FSL/FB_ord' => 1,
98 'FA/FSL/FBA' => 1, 'FA/FSL/FBA/FBA_ord' => 1, 'FA/FAB' => 1,
99 'FA/FAB/FAB_ord' => 1, 'FA/FAB/FABA' => 1, 'FA/FAB/FABA/FABA_ord' => 1,
100 'FA/FAA' => 1, 'FA/FAA/FAA_ord' => 1);
101 File::Find::find( {wanted => \&wanted, follow_fast => 1, no_chdir => 1},'FA' );
102 Check( scalar(keys %Expect) == 0 );
103}
104
105print "# of cases: $case\n";