App-Gre

 view release on metacpan or  search on metacpan

t/test.t  view on Meta::CPAN

use Test::More;
use warnings;

sub runcmd {
    my ($cmd) = @_;
    system "$cmd >../stdout 2>../stderr";
    $EXITCODE = $? >> 8;
    if (open my $fh, "<", "../stdout") {
        $STDOUT = do {local $/; <$fh>};
        close $fh;
    }
    if (open my $fh, "<", "../stderr") {
        $STDERR = do {local $/; <$fh>};
        close $fh;
    }
    if ($ENV{DEBUG}) {
        print "STDOUT: $STDOUT\n";
        print "STDERR: $STDERR\n";
        print "EXITCODE: $EXITCODE\n";
    }
    END {system "rm ../stdout ../stderr"}
}

chdir "t/data";
$ENV{PATH} = "../../bin:$ENV{PATH}";

runcmd("gre apple");
my $e = qr{(?:\e\[.*?[mK])*};
my $test = $STDOUT =~ m{
    ^${e}./fruits.txt${e}\n
    ${e}1${e}:${e}apple${e}\n
    ${e}3${e}:pine${e}apple${e}\n$
}x;
ok $test, "found the apples";

runcmd("gre");
my $out = join "", map "$_\n", sort split /\n/, $STDOUT;
my $exp = <<EOSTR;
./dir1/bar.js
./dir1/foo.html
./dir1/simpsons.txt
./fruits.txt
./pokemon.mon
EOSTR
is $out, $exp, "file listing recursive and textonly";

runcmd("gre -ext=txt -noname=simpsons");
$test = $STDOUT eq <<EOSTR;
./fruits.txt
EOSTR
ok $test, "file filtering";

runcmd("gre -html -js");
$out = join "", map "$_\n", sort split /\n/, $STDOUT;
$exp = <<EOSTR;
./dir1/bar.js
./dir1/foo.html
EOSTR
is $out, $exp, "file filtering with combos";

runcmd("gre -x");
$out = join "", map "$_\n", sort split /\n/, $STDOUT;
$exp = <<EOSTR;
./dir1/bar.js
./dir1/foo.html
./dir1/simpsons.txt
./fruits.txt
./fruits.txt.gz
./pokemon.mon
./pokemon.tar.gz
EOSTR
is $out, $exp, "disable builtin filters";

runcmd("gre 'krusty the clown' -i -k");
$test = $STDOUT eq <<EOSTR;
./dir1/simpsons.txt
10:Krusty the Clown
EOSTR
ok $test, "ignore case";

runcmd("gre -help");



( run in 0.568 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )