From: Nicholas Clark Date: Tue, 17 Feb 2009 20:18:39 +0000 (+0000) Subject: In runenv.t, break apart running perl and testing the output into two functions. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d5226c4c8f9a293280b320d06c082073daeb75b1;p=p5sagit%2Fp5-mst-13.2.git In runenv.t, break apart running perl and testing the output into two functions. --- diff --git a/t/run/runenv.t b/t/run/runenv.t index 5012359..9baf43c 100644 --- a/t/run/runenv.t +++ b/t/run/runenv.t @@ -26,18 +26,12 @@ delete $ENV{PERLLIB}; delete $ENV{PERL5LIB}; delete $ENV{PERL5OPT}; -# Run perl with specified environment and arguments returns a list. -# First element is true if Perl's stdout and stderr match the -# supplied $stdout and $stderr argument strings exactly. -# second element is an explanation of the failure -sub runperl { - local *F; - my ($env, $args, $stdout, $stderr) = @_; +sub runperl_and_capture { + local *F; + my ($env, $args) = @_; unshift @$args, '-I../lib'; - $stdout = '' unless defined $stdout; - $stderr = '' unless defined $stderr; local %ENV = %ENV; delete $ENV{PERLLIB}; delete $ENV{PERL5LIB}; @@ -54,13 +48,7 @@ sub runperl { open F, "< $STDERR" or return (0, "Couldn't read $STDERR file"); { local $/; $actual_stderr = } - if ($actual_stdout ne $stdout) { - return (0, "Stdout mismatch: expected [$stdout], saw [$actual_stdout]"); - } elsif ($actual_stderr ne $stderr) { - return (0, "Stderr mismatch: expected [$stderr], saw [$actual_stderr]"); - } else { - return 1; # success - } + return ($actual_stdout, $actual_stderr); } else { # child for my $k (keys %$env) { $ENV{$k} = $env->{$k}; @@ -72,6 +60,22 @@ sub runperl { } } +# Run perl with specified environment and arguments returns a list. +# First element is true if Perl's stdout and stderr match the +# supplied $stdout and $stderr argument strings exactly. +# second element is an explanation of the failure +sub runperl { + local *F; + my ($env, $args, $stdout, $stderr) = @_; + my ($actual_stdout, $actual_stderr) = runperl_and_capture($env, $args); + if ($actual_stdout ne $stdout) { + return (0, "Stdout mismatch: expected [$stdout], saw [$actual_stdout]"); + } elsif ($actual_stderr ne $stderr) { + return (0, "Stderr mismatch: expected [$stderr], saw [$actual_stderr]"); + } else { + return 1; # success + } +} sub it_didnt_work { print STDOUT "IWHCWJIHCI\cNHJWCJQWKJQJWCQW\n";