perl - 如何从 Test::Script 运行中获取标准输出?

标签 perl testing

我想用 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/

相关文章:

regex - 解决灾难性回溯的工具

比较 2 个字符串数组以查找 C 优化中的匹配项

java - 一起使用 JUnit 和 TestNG

perl - 为 Dancer2 配置 Test::DBIx::Class::Schema 到应用程序

perl - 在 Windows 中手动安装 Perl 模块

Perl 哈希、数组和引用

Android Dalvik 调试器在运行 ActivityInstrumentationTestCase2 时并不总是附加

java - Spring Boot : Preload Data and configure H2 for tests. 特殊配置问题

python - 如何删除 py.test 中的持久对象?

api - Postman JSON 值检查测试失败