0

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";
knb
  • 9,138
  • 4
  • 58
  • 85

3 Answers3

1

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.

Ether
  • 53,118
  • 13
  • 86
  • 159
  • All I had to do was to look at the code of the TAP::Harness->runtests() method. It returns an aggregator object which contains the data I was looking for. – knb Nov 10 '10 at 17:56
0

App::Prove::History

daxim
  • 39,270
  • 4
  • 65
  • 132
  • You spotted an underlying problem, but in this case the source code of App::Prove::history did not help me that much. It *does* contain, however, a good starting point for a database schema I could use. Thanks. – knb Nov 10 '10 at 18:16
0

Answering my own question:

   my $harness = TAP::Harness->new( { formatter => $fmt, merge => 1 } );
    $harness->test_args( [ "--browser=$browser", "--config=$h{config}" ] );
    my $agg = $harness->runtests(@tests);
    my $summary = <<'END_SUMMARY';
    Passed:    %s
    Failed:    %s
    Unexpectedly succeeded: %s
    To do:     %s
    Skipped:   %s
    Planned:   %s
    END_SUMMARY
    printf $summary, scalar $agg->passed,
           scalar $agg->failed,
           scalar $agg->todo_passed,
         scalar $agg->todo  ,
         scalar $agg->todo_passed,
         scalar $agg->skipped,
         scalar $agg->planned;

All I had to do was using the return value of runtests.

knb
  • 9,138
  • 4
  • 58
  • 85