I run some TAP Tests using TAP::Formatter::HTML.
This CPAN module generates beautiful dynamic HTML Reports, but I want to use the number of passed tests, failed tests etc - to insert them into a database after all tests completed.
The code below does not work. It prints nothing to the console. I admit, for lines 10 and after, I just have slapped together some code from the POD descriptions of the TAP::* classes.
Before I dive into the source code of Aggregator, Harmess or Formatter classes and subclasses, I better ask:
does anyone here know how to make this code work?
my $cons = TAP::Formatter::Console->new();
my $fmt = TAP::Formatter::HTML->new;
$fmt->css_uris( \@css_uris )->inline_css($my_css)->js_uris($js_uris)->inline_js($inline_js);
my $harness = TAP::Harness->new( { formatter => $fmt, merge => 1 } );
$fmt->output_file($outfile);
$harness->test_args(["--browser=$browser", "--config=$config"]);
my $aggregator = TAP::Parser::Aggregator->new;
$aggregator->start();
$harness->runtests(@tests);
# $harness->aggregate_tests( $aggregator, @tests );
$aggregator->stop();
# print $fmt->summary($aggregator);
my $txt = $cons->summary( $aggregator );
my $summary = <<'END_SUMMARY';
Passed: %s
Failed: %s
Unexpectedly succeeded: %s
END_SUMMARY
printf $summary,
scalar $aggregator->passed,
scalar $aggregator->failed,
scalar $aggregator->todo_passed;
#$failcount = sprintf("%03d", $harness->failures());
print "summary: $txt\n";
Why not get the test data from the same source TAP::Formatter::HTML does? It is probably inspecting the Test::Builder object and getting the test statistics from there. The Test::Builder object is a singleton, so it is pretty easy to request a copy of it after your tests have been done and extract the data from it for DB insertion, at about the same time the pretty HTML reports are generated.