TAP::Harness perl 测试 tee 输出

发布于 2024-10-18 14:43:20 字数 694 浏览 5 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间不值得 2024-10-25 14:43:20

使用 script 而不是 tee 可以实现您想要的功能:

script -c 'perl harness.pl' file

找到一个简单的更改以使 tee 也能工作:指定 formatter_class

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

这是因为 <如果输出不是 tty,则 code>TAP::Harness 通常会使用不同的默认值,这就是导致您看到的缓冲的原因。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文