TAP::Harness perl 测试 tee 输出
我正在使用 TAP::Harness 运行测试,当我在 Linux 系统上从命令行运行测试时,我会在运行时在 STDOUT 上获得测试结果,但是当我尝试将输出捕获到文件以及使用 STDOUT 时Perlharness.pl| tee out.tap 结果被缓冲并仅在最后显示,我尝试将文件句柄传递给新文件,但结果在写入文件之前仍然被缓冲,有没有办法不缓冲输出,我有一个长时间运行的套件,希望在测试运行时查看结果并捕获输出。
TAP::Harness 版本 3.22 和 perl 版本 5.8.8
这里是示例代码 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);
和测试 del.t
use Test::More qw /no_plan/;
$|++;
my $count =1;
for (1 ..20 ) {
ok ( $count ++ == $_, "Pass $_");
sleep 1 if ( $count % 5 == 0 ) ;
}
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 ) ;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
script
而不是tee
可以实现您想要的功能:找到一个简单的更改以使 tee 也能工作:指定
formatter_class
:这是因为 <如果输出不是 tty,则 code>TAP::Harness 通常会使用不同的默认值,这就是导致您看到的缓冲的原因。
Using
script
instead oftee
does what you want:Found a simple change to make tee work as well: Specify a
formatter_class
: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.