开发者

TAP::Harness perl tests tee output

I am running my tests using TAP::Harness , when I run the tests from command line on a Linux system I get the test results on STDOUT as it is run but when i try to capture the output to a file as well as STDOUT using perl harness.pl | tee out.tap the results are buffered and 开发者_运维知识库displayed only at the end, I tried passing in a file handle to the new but the results are still buffered before being written to a file , Is there a way not to buffer the output, I have a long running suite and would like to look at the results while the tests are running as well as capture the output.

TAP::Harness version 3.22 and perl version 5.8.8

here is the sample code harness.pl

#!/usr/bin/perl
use strict;
use warnings;
use TAP::Harness;
$|++;

my @tests = ('del.t',);


my $harness = TAP::Harness->new( {
    verbosity => 1,
 } );
$harness->runtests(@tests);

and the test del.t

use Test::More qw /no_plan/;
$|++;

my $count =1;
for (1 ..20 ) {
   ok ( $count ++ == $_, "Pass  $_");
   sleep 1 if ( $count % 5 == 0 ) ;
}


Using script instead of tee does what you want:

script -c 'perl harness.pl' file

Found a simple change to make tee work as well: Specify a formatter_class:

my $harness = TAP::Harness->new( {
    verbosity => 1,
    formatter_class => 'TAP::Formatter::Console',
 } );

This is because TAP::Harness normally uses a different default one if the output is not a tty, which is what is causing the buffering you're seeing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜