[英]How to get the stdout from a Test::Script run?
I want to test of Perl script, say testme.pl, with the Test::Script module and get the stdout of the executed script. 我想用Test :: Script模块测试Perl脚本,例如testme.pl,并获取执行脚本的标准输出。 I get an
undef
so far. 我得到一个
undef
至今。
Here is what I tried (test file test.t
): 这是我尝试过的(测试文件
test.t
):
use Test::More tests => 2;
use Test::Script;
use Data::Dumper;
script_compiles('testme.pl');
my $out;
script_runs(['testme.pl'], {"stdout"=>$out}, 'run_script');
print "Out is " . Dumper($out);
And the script to be tested ( testme.pl
) 以及要测试的脚本(
testme.pl
)
print "catchme if you can\n";
boris@midkemia artif_get_file $ perl perl_test.pl
1..2
ok 1 - Script testme.pl compiles
ok 2 - run_script
Out is $VAR1 = undef;
I also tried using an array ref \\@out instead of $out, still no luck. 我也尝试使用数组ref \\ @out代替$ out,仍然没有运气。 Any idea?
任何想法? Thanks!
谢谢!
You've almost got it. 你差不多了。 You need to give the
stdout
option a reference . 您需要给
stdout
选项提供参考 。 Otherwise you're just passing in undef
and it will ignore the option. 否则,您只是传递
undef
,它将忽略该选项。
script_runs(['testme.pl'], {"stdout"=>\$out}, 'run_script');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.