creamygoodness has asked for the wisdom of the Perl Monks concerning the following question:
Let's say I've got a string containing some TAP output:
1..4 ok 1 ok 2 not ok 3 # Failed test at t/my_test.t line 7. ok 4
In real life, the source for the TAP output is a compiled C app that generates TAP, but we can simulate it using a plain old string for demo purposes. I can feed the $tap string to a TAP::Parser object:
my $tap = qx|./compiled_test_app|; my $parser = TAP::Parser->new( { tap => $tap } );
The goal is to wrap the compiled test app with a Perl script and run it as part of a test suite. I've been able to get the TAP::Parser object to iterate over the lines in the TAP string. However, I haven't been able to figure out how to extract clean test results.
Here's a coarse attempt:
use strict; use warnings; use Test::More; use TAP::Parser; my $tap = <<'END_TAP'; 1..4 ok 1 ok 2 not ok 3 # Failed test at t/my_test.t line 7. ok 4 END_TAP my $parser = TAP::Parser->new( { tap => $tap } ); my $plan = $parser->next; die "not a plan" unless $plan->is_plan; plan( tests => $plan->tests_planned ); while ( my $result = $parser->next ) { if ( $result->is_test ) { if ( $result->is_ok ) { pass( $result->as_string ); } else { fail( $result->as_string ); } } elsif ( $result->is_comment ) { print $result->as_string; } else { die "Can't figure out what to do with $result"; } }
... and here's the garbled output it produces:
1..4 ok 1 - ok 1 ok 2 - ok 2 not ok 3 - not ok 3 # Failed test 'not ok 3' # at t/tap_wrapper.t line 28. # Failed test at t/my_test.t line 7.ok 4 - ok 4 # Looks like you failed 1 test of 4.
Is this something that I should be able to use TAP::Parser for, or am I barking up the wrong tree? I actually feel like the result-by-result approach of that test script is completely wrong -- I'd need to add more cases for TODO tests, SKIP directives, etc. The script really ought to look something like this:
use Test::ParseTAP; my $tap = qx|./compiled_test|; parse_tap($tap);
Suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using externally generated TAP to drive a test
by jasonk (Parson) on Sep 05, 2008 at 21:09 UTC | |
by creamygoodness (Curate) on Sep 05, 2008 at 23:12 UTC | |
|
Re: Using externally generated TAP to drive a test
by moritz (Cardinal) on Sep 05, 2008 at 20:37 UTC |