簡體   English   中英

如何從Test :: Script運行獲取標准輸出?

[英]How to get the stdout from a Test::Script run?

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

我也嘗試使用數組ref \\ @out代替$ out,仍然沒有運氣。 任何想法? 謝謝!

你差不多了。 您需要stdout選項提供參考 否則,您只是傳遞undef ,它將忽略該選項。

script_runs(['testme.pl'], {"stdout"=>\$out}, 'run_script');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM