Pseudo-code For Rewriting TAP Streams

Ovid on 2009-06-08T13:57:55

Another team has an issue where they have multiple TAP streams which all need to be integrated into a single stream, but obviously concatenating them won't do the trick. It would fail because you can't have more than one plan in a stream and the test numbers would be out of sequence (though you can turn them off if you're using Test::Builder). In talking with one of their developers, I wrote the following pseudo-code to explain the basic concept.

#!/usr/bin/env perl

use strict;
use warnings;

use TAP::Parser;

my $test_num = 1;
foreach my $stream (get_streams()) {
    my $parser = TAP::Parser->new($stream);
    while ( my $result = $parser->next ) {
        if ( $result->is_plan ) {

            # sent to STDOUT to ensure proper synchronization
            print '# '.$result->as_string;
        }
        next unless $result->is_test;
        print $result->ok;
        print $test_num++;
        # don't forget SKIP and TODO
        print ' - ',$result->description,$/;
    }
    # check to see if the parser succeeded
}
print "1..$test_num\n";

sub get_streams {
    ...
}

When we get nested TAP, ugly hacks like this will go away.