I want to test of Perl script, say testme.pl, with the Test::Script module and get the stdout of the executed script. I get an undef
so far.
Here is what I tried (test file 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
)
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. Any idea? Thanks!
You've almost got it. You need to give the stdout
option a reference . Otherwise you're just passing in undef
and it will ignore the option.
script_runs(['testme.pl'], {"stdout"=>\$out}, 'run_script');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.