📄 find.t
字号:
file_path_name('.', 'fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('.', 'fa', 'faa') => 1, file_path_name('.', 'fa', 'faa', 'faa_ord') => 1, file_path_name('.', 'fb') => 1, file_path_name('.', 'fb', 'fba') => 1, file_path_name('.', 'fb', 'fba', 'fba_ord') => 1, file_path_name('.', 'fb', 'fb_ord') => 1);delete $Expect_Name{ file_path('.', 'fa', 'fsl') } unless $symlink_exists;%Expect_Dir = (); File::Find::finddepth( {wanted => \&wanted_Name}, File::Spec->curdir );Check( scalar(keys %Expect_Name) == 0 );# no_chdir is in effect, hence we use file_path_name to specify the# expected paths for %Expect_File%Expect_File = (File::Spec->curdir => 1, file_path_name('.', 'fa') => 1, file_path_name('.', 'fa', 'fsl') => 1, file_path_name('.', 'fa', 'fa_ord') => 1, file_path_name('.', 'fa', 'fab') => 1, file_path_name('.', 'fa', 'fab', 'fab_ord') => 1, file_path_name('.', 'fa', 'fab', 'faba') => 1, file_path_name('.', 'fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('.', 'fa', 'faa') => 1, file_path_name('.', 'fa', 'faa', 'faa_ord') => 1, file_path_name('.', 'fb') => 1, file_path_name('.', 'fb', 'fba') => 1, file_path_name('.', 'fb', 'fba', 'fba_ord') => 1, file_path_name('.', 'fb', 'fb_ord') => 1);delete $Expect_File{ file_path_name('.', 'fa', 'fsl') } unless $symlink_exists;%Expect_Name = ();%Expect_Dir = (); File::Find::finddepth( {wanted => \&wanted_File, no_chdir => 1}, File::Spec->curdir );Check( scalar(keys %Expect_File) == 0 );print "# check preprocess\n";%Expect_File = ();%Expect_Name = ();%Expect_Dir = ( File::Spec->curdir => {fa => 1, fb => 1}, dir_path('.', 'fa') => {faa => 1, fab => 1, fa_ord => 1}, dir_path('.', 'fa', 'faa') => {faa_ord => 1}, dir_path('.', 'fa', 'fab') => {faba => 1, fab_ord => 1}, dir_path('.', 'fa', 'fab', 'faba') => {faba_ord => 1}, dir_path('.', 'fb') => {fba => 1, fb_ord => 1}, dir_path('.', 'fb', 'fba') => {fba_ord => 1} );File::Find::find( {wanted => \&noop_wanted, preprocess => \&my_preprocess}, File::Spec->curdir );Check( scalar(keys %Expect_Dir) == 0 );print "# check postprocess\n";%Expect_File = ();%Expect_Name = ();%Expect_Dir = ( File::Spec->curdir => 1, dir_path('.', 'fa') => 1, dir_path('.', 'fa', 'faa') => 1, dir_path('.', 'fa', 'fab') => 1, dir_path('.', 'fa', 'fab', 'faba') => 1, dir_path('.', 'fb') => 1, dir_path('.', 'fb', 'fba') => 1 );File::Find::find( {wanted => \&noop_wanted, postprocess => \&my_postprocess}, File::Spec->curdir );Check( scalar(keys %Expect_Dir) == 0 );{ print "# checking argument localization\n"; ### this checks the fix of perlbug [19977] ### my @foo = qw( a b c d e f ); my %pre = map { $_ => } @foo; File::Find::find( sub { } , 'fa' ) for @foo; delete $pre{$_} for @foo; Check( scalar( keys %pre ) == 0 );}# see thread starting# http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2004-02/msg00351.html{ print "# checking that &_ and %_ are still accessible and that\n", "# tie magic on \$_ is not triggered\n"; my $true_count; my $sub = 0; sub _ { ++$sub; } my $tie_called = 0; package Foo; sub STORE { ++$tie_called; } sub FETCH {return 'N'}; sub TIESCALAR {bless []}; package main; Check( scalar( keys %_ ) == 0 ); my @foo = 'n'; tie $foo[0], "Foo"; File::Find::find( sub { $true_count++; $_{$_}++; &_; } , 'fa' ) for @foo; untie $_; Check( $tie_called == 0); Check( scalar( keys %_ ) == $true_count ); Check( $sub == $true_count ); Check( scalar( @foo ) == 1); Check( $foo[0] eq 'N' );}if ( $symlink_exists ) { print "# --- symbolic link tests --- \n"; $FastFileTests_OK= 1; # Verify that File::Find::find will call wanted even if the topdir of # is a symlink to a directory, and it shouldn't follow the link # unless follow is set, which it isn't in this case %Expect_File = ( file_path('fsl') => 1 ); %Expect_Name = (); %Expect_Dir = (); File::Find::find( {wanted => \&wanted_File_Dir}, topdir('fa', 'fsl') ); Check( scalar(keys %Expect_File) == 0 ); %Expect_File = (File::Spec->curdir => 1, file_path('fa_ord') => 1, file_path('fsl') => 1, file_path('fb_ord') => 1, file_path('fba') => 1, file_path('fba_ord') => 1, file_path('fab') => 1, file_path('fab_ord') => 1, file_path('faba') => 1, file_path('faa') => 1, file_path('faa_ord') => 1); %Expect_Name = (); %Expect_Dir = (File::Spec->curdir => 1, dir_path('fa') => 1, dir_path('faa') => 1, dir_path('fab') => 1, dir_path('faba') => 1, dir_path('fb') => 1, dir_path('fba') => 1); File::Find::find( {wanted => \&wanted_File_Dir_prune, follow_fast => 1}, topdir('fa') ); Check( scalar(keys %Expect_File) == 0 ); # no_chdir is in effect, hence we use file_path_name to specify # the expected paths for %Expect_File %Expect_File = (file_path_name('fa') => 1, file_path_name('fa', 'fa_ord') => 1, file_path_name('fa', 'fsl') => 1, file_path_name('fa', 'fsl', 'fb_ord') => 1, file_path_name('fa', 'fsl', 'fba') => 1, file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, file_path_name('fa', 'fab') => 1, file_path_name('fa', 'fab', 'fab_ord') => 1, file_path_name('fa', 'fab', 'faba') => 1, file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('fa', 'faa') => 1, file_path_name('fa', 'faa', 'faa_ord') => 1); %Expect_Name = (); %Expect_Dir = (dir_path('fa') => 1, dir_path('fa', 'faa') => 1, dir_path('fa', 'fab') => 1, dir_path('fa', 'fab', 'faba') => 1, dir_path('fb') => 1, dir_path('fb', 'fba') => 1); File::Find::find( {wanted => \&wanted_File_Dir, follow_fast => 1, no_chdir => 1}, topdir('fa') ); Check( scalar(keys %Expect_File) == 0 ); %Expect_File = (); %Expect_Name = (file_path_name('fa') => 1, file_path_name('fa', 'fa_ord') => 1, file_path_name('fa', 'fsl') => 1, file_path_name('fa', 'fsl', 'fb_ord') => 1, file_path_name('fa', 'fsl', 'fba') => 1, file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, file_path_name('fa', 'fab') => 1, file_path_name('fa', 'fab', 'fab_ord') => 1, file_path_name('fa', 'fab', 'faba') => 1, file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('fa', 'faa') => 1, file_path_name('fa', 'faa', 'faa_ord') => 1); %Expect_Dir = (); File::Find::finddepth( {wanted => \&wanted_Name, follow_fast => 1}, topdir('fa') ); Check( scalar(keys %Expect_Name) == 0 ); # no_chdir is in effect, hence we use file_path_name to specify # the expected paths for %Expect_File %Expect_File = (file_path_name('fa') => 1, file_path_name('fa', 'fa_ord') => 1, file_path_name('fa', 'fsl') => 1, file_path_name('fa', 'fsl', 'fb_ord') => 1, file_path_name('fa', 'fsl', 'fba') => 1, file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, file_path_name('fa', 'fab') => 1, file_path_name('fa', 'fab', 'fab_ord') => 1, file_path_name('fa', 'fab', 'faba') => 1, file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('fa', 'faa') => 1, file_path_name('fa', 'faa', 'faa_ord') => 1); %Expect_Name = (); %Expect_Dir = (); File::Find::finddepth( {wanted => \&wanted_File, follow_fast => 1, no_chdir => 1}, topdir('fa') ); Check( scalar(keys %Expect_File) == 0 ); print "# check dangling symbolic links\n"; MkDir( dir_path('dangling_dir'), 0770 ); CheckDie( symlink( dir_path('dangling_dir'), file_path('dangling_dir_sl') ) ); rmdir dir_path('dangling_dir'); touch(file_path('dangling_file')); if ($^O eq 'MacOS') { CheckDie( symlink('dangling_file', ':fa:dangling_file_sl') ); } else { CheckDie( symlink('../dangling_file','fa/dangling_file_sl') ); } unlink file_path('dangling_file'); { # these tests should also emit a warning use warnings; %Expect_File = (File::Spec->curdir => 1, file_path('dangling_file_sl') => 1, file_path('fa_ord') => 1, file_path('fsl') => 1, file_path('fb_ord') => 1, file_path('fba') => 1, file_path('fba_ord') => 1, file_path('fab') => 1, file_path('fab_ord') => 1, file_path('faba') => 1, file_path('faba_ord') => 1, file_path('faa') => 1, file_path('faa_ord') => 1); %Expect_Name = (); %Expect_Dir = (); undef $warn_msg; File::Find::find( {wanted => \&wanted_File, follow => 1, dangling_symlinks => sub { $warn_msg = "$_[0] is a dangling symbolic link" } }, topdir('dangling_dir_sl'), topdir('fa') ); Check( scalar(keys %Expect_File) == 0 ); Check( $warn_msg =~ m|dangling_file_sl is a dangling symbolic link| ); unlink file_path('fa', 'dangling_file_sl'), file_path('dangling_dir_sl'); } print "# check recursion\n"; if ($^O eq 'MacOS') { CheckDie( symlink(':fa:faa',':fa:faa:faa_sl') ); } else { CheckDie( symlink('../faa','fa/faa/faa_sl') ); } undef $@; eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, no_chdir => 1}, topdir('fa') ); }; Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]faa_sl is a recursive symbolic link|i ); unlink file_path('fa', 'faa', 'faa_sl'); print "# check follow_skip (file)\n"; if ($^O eq 'MacOS') { CheckDie( symlink(':fa:fa_ord',':fa:fa_ord_sl') ); # symlink to a file } else { CheckDie( symlink('./fa_ord','fa/fa_ord_sl') ); # symlink to a file } undef $@; eval {File::Find::finddepth( {wanted => \&simple_wanted, follow => 1, follow_skip => 0, no_chdir => 1}, topdir('fa') );}; Check( $@ =~ m|for_find[:/]fa[:/]fa_ord encountered a second time|i ); # no_chdir is in effect, hence we use file_path_name to specify # the expected paths for %Expect_File %Expect_File = (file_path_name('fa') => 1, file_path_name('fa', 'fa_ord') => 2, # We may encounter the symlink first file_path_name('fa', 'fa_ord_sl') => 2, file_path_name('fa', 'fsl') => 1, file_path_name('fa', 'fsl', 'fb_ord') => 1, file_path_name('fa', 'fsl', 'fba') => 1, file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, file_path_name('fa', 'fab') => 1, file_path_name('fa', 'fab', 'fab_ord') => 1, file_path_name('fa', 'fab', 'faba') => 1, file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('fa', 'faa') => 1, file_path_name('fa', 'faa', 'faa_ord') => 1); %Expect_Name = (); %Expect_Dir = (dir_path('fa') => 1, dir_path('fa', 'faa') => 1, dir_path('fa', 'fab') => 1, dir_path('fa', 'fab', 'faba') => 1, dir_path('fb') => 1, dir_path('fb','fba') => 1); File::Find::finddepth( {wanted => \&wanted_File_Dir, follow => 1, follow_skip => 1, no_chdir => 1}, topdir('fa') ); Check( scalar(keys %Expect_File) == 0 ); unlink file_path('fa', 'fa_ord_sl'); print "# check follow_skip (directory)\n"; if ($^O eq 'MacOS') { CheckDie( symlink(':fa:faa',':fa:faa_sl') ); # symlink to a directory } else { CheckDie( symlink('./faa','fa/faa_sl') ); # symlink to a directory } undef $@; eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, follow_skip => 0, no_chdir => 1}, topdir('fa') );}; Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time|i ); undef $@; eval {File::Find::find( {wanted => \&simple_wanted, follow => 1, follow_skip => 1, no_chdir => 1}, topdir('fa') );}; Check( $@ =~ m|for_find[:/]fa[:/]faa[:/]? encountered a second time|i ); # no_chdir is in effect, hence we use file_path_name to specify # the expected paths for %Expect_File %Expect_File = (file_path_name('fa') => 1, file_path_name('fa', 'fa_ord') => 1, file_path_name('fa', 'fsl') => 1, file_path_name('fa', 'fsl', 'fb_ord') => 1, file_path_name('fa', 'fsl', 'fba') => 1, file_path_name('fa', 'fsl', 'fba', 'fba_ord') => 1, file_path_name('fa', 'fab') => 1, file_path_name('fa', 'fab', 'fab_ord') => 1, file_path_name('fa', 'fab', 'faba') => 1, file_path_name('fa', 'fab', 'faba', 'faba_ord') => 1, file_path_name('fa', 'faa') => 1, file_path_name('fa', 'faa', 'faa_ord') => 1, # We may actually encounter the symlink first. file_path_name('fa', 'faa_sl') => 1, file_path_name('fa', 'faa_sl', 'faa_ord') => 1); %Expect_Name = (); %Expect_Dir = (dir_path('fa') => 1, dir_path('fa', 'faa') => 1, dir_path('fa', 'fab') => 1, dir_path('fa', 'fab', 'faba') => 1, dir_path('fb') => 1, dir_path('fb', 'fba') => 1); File::Find::find( {wanted => \&wanted_File_Dir, follow => 1, follow_skip => 2, no_chdir => 1}, topdir('fa') ); # If we encountered the symlink first, then the entries corresponding to # the real name remain, if the real name first then the symlink my @names = sort keys %Expect_File; Check( @names == 1 ); # Normalise both to the original name s/_sl// foreach @names; Check ($names[0] eq file_path_name('fa', 'faa', 'faa_ord')); unlink file_path('fa', 'faa_sl');}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -