File-Wildcard

 view release on metacpan or  search on metacpan

t/03_absolute.t  view on Meta::CPAN

    }

    #01
    use_ok('File::Wildcard');
}

use File::Spec;

my $debug = $ENV{FILE_WILDCARD_DEBUG} || 0;

my $temp = File::Spec->tmpdir . '/File-Wildcard-test';
$temp =~ s!\\!/!g;    # for Windows silly slash direction

# Just in case the temp directory is lying around...

if ( -e $temp ) {
    my $wcrm = File::Wildcard->new(
        path           => "$temp///",
        ellipsis_order => "inside-out"
    );
    for ( $wcrm->all ) {
        if ( -d $_ ) {
            rmdir $_;
        }
        else {
            1 while unlink $_;
        }
    }
}

mkdir $temp;
mkdir "$temp/abs";
mkdir "$temp/abs/foo";
mkdir "$temp/abs/bar";

open FOO, ">$temp/abs/foo/lish.tmp";
close FOO;
open FOO, ">$temp/abs/bar/drink.tmp";
close FOO;

# Force the case sensitivity for absolute files
# as it says in the docs

my $sens = Filesys::Type::case($temp) ne 'sensitive';

my $mods = File::Wildcard->new(
    path             => "$temp/abs/foo/lish.tmp",
    case_insensitive => $sens,
    debug            => $debug
);

#02
isa_ok( $mods, 'File::Wildcard', "return from new" );

#03
like( $mods->next, qr"$temp/abs/foo/lish.tmp"i, 'Simple case, no wildcard' );

#04
ok( !$mods->next, 'Only found one file' );

my ( $junk, @chunks ) = split m'/', "$temp/abs/*/*.tmp";

$mods = File::Wildcard->new(
    path             => \@chunks,
    case_insensitive => $sens,
    debug            => $debug,
    absolute         => 1,
    sort             => 1
);

#05
isa_ok( $mods, 'File::Wildcard', "return from new" );

my @found = $mods->all;

SKIP:
{
    skip 'This test unreliable on Windows', 1 if $^O =~ /win/i;

    #06
    is_deeply(
        \@found,
        [ "$temp/abs/bar/drink.tmp", "$temp/abs/foo/lish.tmp" ],
        'Wildcard in filename'
    );
}

$mods = File::Wildcard->new(
    path             => "$temp///*.tmp",
    case_insensitive => $sens,
    debug            => $debug,
    sort             => 1
);

#07
isa_ok( $mods, 'File::Wildcard', "(ellipsis) return from new" );

@found = $mods->all;

#08
is_deeply(
    \@found,
    [ "$temp/abs/bar/drink.tmp", "$temp/abs/foo/lish.tmp" ],
    'Ellipsis found tmp files'
);

$mods = File::Wildcard->new(
    path             => "$temp///",
    case_insensitive => $sens,
    debug            => $debug,
    sort             => 1
);

#09
isa_ok( $mods, 'File::Wildcard', "(ellipsis) return from new" );

@found = $mods->all;

#10
is_deeply(
    \@found,



( run in 0.813 second using v1.01-cache-2.11-cpan-71847e10f99 )