[tap-l] Inter-stream punctuation

Andy Armstrong andy at hexten.net
Tue Mar 20 12:22:49 GMT 2007


On 20 Mar 2007, at 11:00, Adrian Howard wrote:

 >
 > On 19 Mar 2007, at 17:50, Andy Armstrong wrote:
 >
 > > Given that TAP is streaming I wonder if it might ever be useful  
to be
 > > able to concatenate a number of TAP streams and have the harness be
 > > able to work out that the single stream represented multiple tests?
 > [snip]
 >
 > I've wanted something like this in the past
 >
 > <http://www.nntp.perl.org/group/perl.qa/2007/01/msg7545.html>

Aha. Here's the little driver I wrote yesterday to aggregate a bunch  
of PHP tests into a single TAP stream:

     use strict;
     use warnings;

     my $php = $ENV{PHP} || 'php';

     my $TESTS = 't/*.php';

     my $planned = 0;

     for my $test ( glob( $TESTS ) ) {
         warn "# $test\n";
         my $offset = $planned;
         my @command = ( $php, $test );
         open my $th, '-|', @command or die "Can't run $test ($?)\n";
         while ( defined( my $line = <$th> ) ) {
             chomp $line;
             if ( $line =~ /^1..(\d+)/ ) {
                 $planned += $1;
             }
             else {
                 $line =~ s/^((?:not\s+)?ok\s+)(\d+)/$1 . ($2 +  
$offset)/e;
                 print "$line\n";
             }
         }
         close $th or die "Can't run $test ($?)\n";
     }

     # Trailing plan
     print "1..$planned\n";

Which is almost exactly your:

     Something that I've wanted in the past is a way to merge TAP  
streams
     together. So I could take these:

     1..2
     ok 1 - foo the first
     ok 2 - foo the second

     1..2
     ok 1 - bar the first
     ok 2 - bar the second

     and produce something like

     1..4
     ok 1 - foo the first
     ok 2 - bar the first
     ok 3 - bar the second
     ok 4 - foo the second

Except that the output is actually

     ok 1 - foo the first
     ok 2 - bar the first
     ok 3 - bar the second
     ok 4 - foo the second
     1..4

 > [snip]
 > > I can see that it might simplify network testing also to be able to
 > > send a single TAP stream that represents the output from multiple
 > > tests.
 > [snip]
 >
 > That was my use case.

I think all the TAP grammar would need would be 'begin' and 'end'

     begin
     1..2
     ok 1 - foo the first
     ok 2 - foo the second
     end
     begin
     1..2
     ok 1 - bar the first
     ok 2 - bar the second
     end

It doesn't then matter how many test scripts that output comes from.

--
Andy Armstrong, hexten.net



More information about the tap-l mailing list