in reply to Intercepting TAP output

It would appear to me that a poor initial choice has been made. Test::More would seem ill suited to being the framework for what seems like a network monitoring app. Can you explain the rationale for using Test::More?

I would suggest using Tap::Parser if you wish to persist with this approach:

use TAP::Parser; for my $file ( @test_files ) { my $parser = TAP::Parser->new( { source => $file } ); # do stuff with the parser }

Alternatively (and seeing you appear to want to do things the hard way) because Test::More is built on top of Test::Builder all you need to do to redirect the output is modify the underlying T::B object using the published interface:

use Test::More 'no_plan'; my $ok_fh = 'ok.txt'; my $fail_fh = 'fail.txt'; my $Test = Test::More->builder; $Test->output($ok_fh); $Test->failure_output($fail_fh); ok(1); ok(0,'bar');

Unfortuantely Test::Builder is "broken" in that while it will accept a FH or filename to redirect to it will not accept an IO::String object, so it constrains you to writing to a file.

Replies are listed 'Best First'.
Re^2: Intercepting TAP output
by peters (Sexton) on May 08, 2008 at 17:46 UTC
    It would appear to me that a poor initial choice has been made. Test::More would seem ill suited to being the framework for what seems like a network monitoring app. Can you explain the rationale for using Test::More?

    It wasn't my choice, but it has a certain elegance. At the point where the customer said that they wanted different output it lost some of that elegance.

    TAP::Parser totally looks like the way to go. Thanks!

    Peter Scott
    Perl Medic
      I have boiled it down to this demo. TAP::Harness looks like the best driver and it has a callback that lets me get at the parser before it would otherwise be used. Silencing the harness means that it never gets to find out that its parsers have been drained.
      use TAP::Harness; my $harness = TAP::Harness->new( { verbosity => -3, merge => 1 } ); my @tests = glob "t/*.t"; $harness->callback( made_parser => \&hijack_parser ); $harness->runtests( @tests ); sub hijack_parser { my ($parser, $test_ref) = @_; while ( my $result = $parser->next ) { $result->is_test or next; $result->is_actual_ok and next; (my $description = $result->description) =~ s/- //; print "I seem to have failed $description in $test_ref->[1]\n"; } }
      Peter Scott
      Perl Medic
Re^2: Intercepting TAP output
by reisinge (Hermit) on Jul 05, 2013 at 21:11 UTC

    Test::More would seem ill suited to being the framework for what seems like a network monitoring app.

    Both Randal Schwartz (here) and David N. Blank-Edelman (here, p. 522) consider it a plausible idea.

    Well done is better than well said. -- Benjamin Franklin

Re^2: Intercepting TAP output
by Anonymous Monk on May 08, 2008 at 13:17 UTC
    Test::More would seem ill suited to being the framework for what seems like a network monitoring app.
    O RLY