1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#!/usr/bin/perl
# $Id$
use strict;
use warnings;
use Test::More tests => 4;
use File::Path qw(rmtree);
use Test::File 1.993 ();
# TEST
use_ok('File::Find::Object');
mkdir('t/dir');
mkdir('t/dir/a');
mkdir('t/dir/b');
open( my $h, ">", 't/dir/file' );
close($h);
# symlink does not exists everywhere (windows)
# if it failed, this does not matter
eval { symlink( '.', 't/dir/link' ); };
my $has_symlinks = Test::File->has_symlinks();
my ( @res1, @res2 );
my $tree = File::Find::Object->new(
{
callback => sub {
push( @res1, $_[0] );
},
followlink => 1,
},
't/dir'
);
my @warnings;
local $SIG{__WARN__} = sub { my $w = shift; push @warnings, $w; };
# TEST
ok( $tree, "Can get tree object" );
while ( my $r = $tree->next() )
{
push( @res2, $r );
}
# TEST
ok( scalar(@res1) == scalar(@res2), "Get same result from callback and next" );
# TEST
if ($has_symlinks)
{
like(
$warnings[0],
qr{\AAvoid loop (\S+) => \1\S+?link\r?\n?\z},
"Avoid loop warning"
);
}
else
{
pass("No symlink.");
}
# Cleanup
rmtree( 't/dir', 0, 1 );
|