perl-Test-Count / modules / Test-Count / t / 02-main.t

#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 6;
use File::Spec;
use IO::Scalar;

use Test::Count;

{
    open my $in, "<", File::Spec->catfile("t", "sample-data", "test-scripts", "01-parser.t");

    my $counter = Test::Count->new(
        {
            'input_fh' => $in,
        }
    );

    my $ret = $counter->process();

    # TEST
    is ($ret->{'tests_count'}, 5, "Testing for 01-parser.t");

    close($in);
}

{
    open my $in, "<",
        File::Spec->catfile(
            "t", "sample-data", "test-scripts","arithmetics.t"
        );

    my $counter = Test::Count->new(
        {
            'input_fh' => $in,
        }
    );

    my $ret = $counter->process();

    # TEST
    is ($ret->{'tests_count'}, 18, "Testing for arithmetics.t");

    close($in);
}

{
    my $buffer = "# T" . "EST        \n".
    "ok (1, 'Everything is OK');\n";
    my $in = IO::Scalar->new(\$buffer);

    my $counter = Test::Count->new(
        {
            'input_fh' => $in,
        }
    );

    my $ret = $counter->process();

    # TEST
    is ($ret->{'tests_count'}, 1, "Correctly handling trailing whitespace");

    close($in);
}

{
    my $_T = 'T' . 'EST';
    my $buffer = <<"EOF";
use MyModule;

# ${_T}:\$my_func=10;

# ${_T}:\$c=0;

for my \$idx (1 .. 30)
{
    # ${_T}:\$c++;
    ok (1, "Idx \$idx");

    # ${_T}:\$c+=\$my_func;
    MyModule->my_func("Foo", "Foo \$idx");

    # ${_T}:\$c+=\$my_func;
    MyModule->my_bar("Bar", "Bar \$idx");
}

# ${_T}:\$foo_loop=\$c;
# ${_T}*\$foo_loop*30

EOF

    my $in = IO::Scalar->new(\$buffer);

    my $counter = Test::Count->new(
        {
            'input_fh' => $in,
        }
    );

    my $ret = $counter->process();

    # TEST
    is ($ret->{'tests_count'}, (1+10+10)*30,
        "Handling +=.");

    close($in);
}

{
    my $_T = 'T' . 'EST';
    my $buffer = <<"EOF";
use MyModule;

# ${_T}:\$my_func=10;

# ${_T}:\$c=0;

for my \$idx (1 .. 30)
{
    # ${_T}:\$c++;
    ok (1, "Idx \$idx");

    # ${_T}:\$c+=\$my_func+50;
    MyModule->my_func("Foo", "Foo \$idx");

    # ${_T}:\$c-=50;

    # ${_T}:\$c+=\$my_func;
    MyModule->my_bar("Bar", "Bar \$idx");
}

# ${_T}:\$foo_loop=\$c;
# ${_T}*\$foo_loop*30

EOF

    my $in = IO::Scalar->new(\$buffer);

    my $counter = Test::Count->new(
        {
            'input_fh' => $in,
        }
    );

    my $ret = $counter->process();

    # TEST
    is ($ret->{'tests_count'}, (1+10+10)*30,
        "Handling += and -=.");

    close($in);
}

{
    my $_T = 'T' . 'EST';
    my $buffer = <<"EOF";
use MyModule;

# ${_T}:\$my_func=10;

# ${_T}:\$c=0;

for my \$idx (1 .. 30)
{
    # ${_T}:\$c++;
    MyModule->my_func("Foo", "Foo \$idx");

    # ${_T}:\$c++;
    MyModule->my_bar("Bar", "Bar \$idx");
}

# ${_T}:\$c*=\$my_func;
# ${_T}:\$foo_loop=\$c;
# ${_T}*\$foo_loop*30

EOF

    my $in = IO::Scalar->new(\$buffer);

    my $counter = Test::Count->new(
        {
            'input_fh' => $in,
        }
    );

    my $ret = $counter->process();

    # TEST
    is ($ret->{'tests_count'}, (10+10)*30,
        "Handling *=",);

    close($in);
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.