我想用 Test::Script 测试 Perl 脚本,比如 testme.pl模块并获取执行脚本的标准输出。到目前为止,我得到了一个 undef
。
这是我尝试过的(测试文件 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);
以及要测试的脚本(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;
我也尝试过使用数组引用\@out 而不是 $out,但仍然没有成功。任何想法?谢谢!
最佳答案
你已经快搞定了。你需要give the stdout
option a reference .否则,您只是传入 undef
,它将忽略该选项。
script_runs(['testme.pl'], {"stdout"=>\$out}, 'run_script');
关于perl - 如何从 Test::Script 运行中获取标准输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41748221/