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?

--
Marvin Humphrey
Rectangular Research ― http://www.rectangular.com

In reply to Using externally generated TAP to drive a test by creamygoodness

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.