throvolos has asked for the wisdom of the Perl Monks concerning the following question:

Hello-

Please be gentle, this is my first question. =) I consider myself to be a novice perl user.

I'm trying to convince TAP::Parser::Aggregator that it is ok to coallate all of the "ok" messages provided by Test::More within the script that is calling aggregator, but can't seem to figure out how to make this happen.

The script doesn't call individual tests; rather, it just loads some parameters. The script itself, is thus being tested (to ensure its functionality).

I don't understand classes or objects very well, thus my confusion, I'm sure.

Is this possible? Thanks!

use Test::More; use TAP::Harness; use TAP::Parser::Aggregator; my $mm_start_time = gettimeofday; my $harness = TAP::Harness->new({ verbosity => -2, merge => 1, }); my $aggregator = TAP::Parser::Aggregator->new; $aggregator->start(); my $mm_parser; ## Doesn't work: ## $aggregator->add( 'myself', $mm_parser ); BEGIN { use_ok( 'ACTH::Base::Load_test', "load_test" ) or die "Could not use module ACTH::Base::Load_test"; can_ok( 'ACTH::Base::Load_test', "load_test" ); # others... } # lots of other work, subroutines called, etc done_testing( ); $aggregator->stop(); my $summary = <<'END_SUMMARY'; Passed: %s Failed: %s Unexpectedly succeeded: %s To do: %s Skipped: %s Planned: %s END_SUMMARY printf STDERR $summary, scalar $aggregator->passed, scalar $aggregator->failed, scalar $aggregator->todo_passed, scalar $aggregator->todo , scalar $aggregator->todo_passed, scalar $aggregator->skipped, scalar $aggregator->planned; exit 0;

Provides output like this. I'd prefer to see none of the "ok" meessages except when debugging...

ok 1 - use ACTH::Base::Load_test; ok 2 - ACTH::Base::Load_test->can('load_test') ok 3 - use ACTH::Base::Sanity_test; ok 4 - ACTH::Base::Sanity_test->can('sanity_test') ## ..snip... ===================================================== ===================================================== 1..23 Passed: 0 Failed: 0 Unexpectedly succeeded: 0 To do: 0 Skipped: 0 Planned: 0

Replies are listed 'Best First'.
Re: Aggregating "ok" messages within an aggregating script
by Khen1950fx (Canon) on Jan 20, 2011 at 07:27 UTC
    I think you were after something like this:
    #!/usr/bin/perl use strict; use warnings; use POSIX qw/strftime/; use TAP::Parser qw/all/; use TAP::Parser::Aggregator qw/all/; printf STDOUT "\n---\nReport %s\n---\n", strftime("%y%m%d-%H:%M", localtime); my $file = 'your_test_here.t'; my $parser = TAP::Parser->new({ source => $file }); while ( my $result = $parser->next ) { print "$file results: ", $result->as_string, "\n"; } my $aggregate = TAP::Parser::Aggregator->new; $aggregate->add( 'your_test_here', $parser ); my $summary = <<'END_SUMMARY'; Passed: %s Failed: %s Todo: %s Skipped: %s Planned: %s Unexpectedly succeeded: %s END_SUMMARY printf $summary, scalar $aggregate->passed, scalar $aggregate->failed, scalar $aggregate->todo_passed, scalar $aggregate->todo, scalar $aggregate->skipped, scalar $aggregate->planned;

      Unfortunately, that's not what I need.

      There is no $file (no .t files to test)

      Take that script your wrote, add a bunch of 'ok' tests into it, have no $file targets, and have the script summarize its OWN 'ok' messages... that's what I need.

        I am not experienced with test, separated test scripts seems popular. So I am not sure what I think is good or bad. How about using pod comment like Test::inline? And use prove command of Test::Harness? I mean like this.
        ... contents of module =test begin ok(1==1, "1 test") ok(2==2, "2 test") =test end
        And grep this test.pl and test.
        > cat test.pl |grep -v "^test" > testfile > perl testfile; prove testfile
        regards