App-Du-Analyze

 view release on metacpan or  search on metacpan

t/app.t  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;

use autodie;

use File::Spec;

use Test::More tests => 12;

use Test::Differences qw( eq_or_diff );

use Test::Trap
    qw( trap $trap :flow:stderr(systemsafe):stdout(systemsafe):warn );

use App::Du::Analyze;
my $input_filename = File::Spec->catfile( File::Spec->curdir, 't', 'data',
    'fc-solve-git-du-output.txt' );

# TEST:$test_filter_on_fc_solve__proto=1;
sub test_filter_on_fc_solve__proto
{
    my ( $args, $expected_output, $blurb ) = @_;

    local $Test::Builder::Level = $Test::Builder::Level + 1;

    trap
    {
        App::Du::Analyze->new( { argv => [@$args] } )->run();
    };

    my $got_output = $trap->stdout;

    return eq_or_diff( $got_output, $expected_output, $blurb, );
}

# TEST:$test_filter_on_fc_solve=0;
sub test_filter_on_fc_solve
{
    local $Test::Builder::Level = $Test::Builder::Level + 1;
    my ( $args, $expected_output, $blurb ) = @_;

    {
        local $ENV{ANALYZE_DU_INPUT_FN} = $input_filename;

        # TEST:$test_filter_on_fc_solve+=$test_filter_on_fc_solve__proto;
        test_filter_on_fc_solve__proto( $args, $expected_output,
            "$blurb - ENV", );
    }

    {
        # TEST:$test_filter_on_fc_solve+=$test_filter_on_fc_solve__proto;
        test_filter_on_fc_solve__proto( [ @$args, $input_filename ],
            $expected_output, "$blurb - arg", );
    }
}

{

    # TEST*$test_filter_on_fc_solve
    test_filter_on_fc_solve(
        [ '-p', '', '-d', 0, ],
        <<"EOF", "depth 0 and no prefix",
119224\t
EOF
    );

    # TEST*$test_filter_on_fc_solve
    test_filter_on_fc_solve(
        [ '-p', 'fc-solve', '-d', 0, ],
        <<"EOF", "depth 0 and specified prefix",
52532\tfc-solve
EOF
    );

    # TEST*$test_filter_on_fc_solve
    test_filter_on_fc_solve(
        [ '-p', 'fc-solve', '-d', 1, ],
        <<"EOF", "depth 1 and specified prefix",
16\tfc-solve/tests
120\tfc-solve/docs
172\tfc-solve/scripts
232\tfc-solve/arch_doc
276\tfc-solve/rejects
392\tfc-solve/benchmarks
2920\tfc-solve/site
4192\tfc-solve/source
44208\tfc-solve/presets
EOF
    );

    # TEST*$test_filter_on_fc_solve
    test_filter_on_fc_solve(
        [ '-p', '', '-d', 1, ],
        <<"EOF", "depth 1 and an empty prefix",
72\tTask-FreecellSolver-Testing
172\text-ifaces
6900\twww-solitaire
7512\tcpan
52012\t.git
52532\tfc-solve
EOF
    );



( run in 1.223 second using v1.01-cache-2.11-cpan-5a3173703d6 )