Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Using externally generated TAP to drive a test

by creamygoodness (Curate)
on Sep 05, 2008 at 19:33 UTC ( [id://709376]=perlquestion: print w/replies, xml ) Need Help??

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?

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

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

    Maybe I'm missing something, but if you are just trying to write a perl test script to produce TAP output from your binary which already produces TAP output, why not just...

    #!/usr/bin/perl -w qx|./compiled_test_app|;

    and then deal with it the same way you deal with your other test scripts, using prove or something like it, instead of trying to interpret the TAP just to produce more TAP output...


    www.jasonkohles.com
    We're not surrounded, we're in a target-rich environment!

      Heh. It really is that simple! Somehow I'd figured there had to be more to it than just printing test output.

      Thanks!

      --
      Marvin Humphrey
      Rectangular Research ― http://www.rectangular.com
Re: Using externally generated TAP to drive a test
by moritz (Cardinal) on Sep 05, 2008 at 20:37 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://709376]
Approved by SankoR
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found