File-Find-Rule
view release on metacpan or search on metacpan
t/File-Find-Rule.t view on Meta::CPAN
#!perl -w
# $Id$
use strict;
use Test::More tests => 46;
use File::Spec;
if (eval { require Test::Differences; 1 }) {
no warnings;
*is_deeply = *Test::Differences::eq_or_diff;
}
my $class;
my @tests = qw( testdir/File-Find-Rule.t testdir/findrule.t );
BEGIN {
$class = 'File::Find::Rule';
use_ok($class)
}
# on win32 systems the testdir/foobar file isn't 10 bytes it's 11, so the
# previous tests on the magic number 10 failed. rt.cpan.org #3838
my $foobar_size = -s 'testdir/foobar';
my $f = $class->new;
isa_ok($f, $class);
# name
$f = $class->name( qr/\.t$/ );
is_deeply( [ sort $f->in('testdir') ],
[ @tests ],
"name( qr/\\.t\$/ )" );
$f = $class->name( 'foobar' );
is_deeply( [ $f->in('testdir') ],
[ 'testdir/foobar' ],
"name( 'foobar' )" );
$f = $class->name( '*.t' );
is_deeply( [ sort $f->in('testdir') ],
\@tests,
"name( '*.t' )" );
$f = $class->name( 'foobar', '*.t' );
is_deeply( [ sort $f->in('testdir') ],
[ @tests, 'testdir/foobar' ],
"name( 'foobar', '*.t' )" );
$f = $class->name( [ 'foobar', '*.t' ] );
is_deeply( [ sort $f->in('testdir') ],
[ @tests, 'testdir/foobar' ],
"name( [ 'foobar', '*.t' ] )" );
$f = $class->name( "test(*" );
is_deeply( [ sort $f->in('testdir') ],
[],
'name("test(*"); used to be invalid' );
# exec
$f = $class->exec(sub { length == 6 })->maxdepth(1);
is_deeply( [ $f->in('testdir') ],
[ 'testdir/foobar' ],
"exec (short)" );
$f = $class->exec(sub { length > $foobar_size })->maxdepth(1);
is_deeply( [ $f->in('testdir') ],
[ 'testdir/File-Find-Rule.t' ],
"exec (long)" );
( run in 0.747 second using v1.01-cache-2.11-cpan-df04353d9ac )