diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-02-21 11:09:11 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-02-21 11:09:11 +0000 |
commit | 62a1213a862266b141f7120a84c0757eda594f76 (patch) | |
tree | c2ce835e8091703c685e987527b683d515d34ce2 /t/run | |
parent | b01f2fb210240eee556aff42c575e82a5ae3779b (diff) | |
download | perl-62a1213a862266b141f7120a84c0757eda594f76.tar.gz |
Refactor t/run/runenv.t to use lexical file handles.
Also print out $! in open failure diagnostics.
Diffstat (limited to 't/run')
-rw-r--r-- | t/run/runenv.t | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/t/run/runenv.t b/t/run/runenv.t index 2d1ac1f9c5..9af0b29e1c 100644 --- a/t/run/runenv.t +++ b/t/run/runenv.t @@ -40,22 +40,23 @@ sub runperl_and_capture { my $pid = fork; return (0, "Couldn't fork: $!") unless defined $pid; # failure if ($pid) { # parent - my ($actual_stdout, $actual_stderr); wait; return (0, "Failure in child.\n") if ($?>>8) == $FAILURE_CODE; - open F, "< $STDOUT" or return (0, "Couldn't read $STDOUT file"); - { local $/; $actual_stdout = <F> } - open F, "< $STDERR" or return (0, "Couldn't read $STDERR file"); - { local $/; $actual_stderr = <F> } - - return ($actual_stdout, $actual_stderr); + open my $stdout, '<', $STDOUT + or return (0, "Couldn't read $STDOUT file: $!"); + open my $stderr, '<', $STDERR + or return (0, "Couldn't read $STDERR file: $!"); + local $/; + # Empty file with <$stderr> returns nothing in list context + # (because there are no lines) Use scalar to force it to '' + return (scalar <$stdout>, scalar <$stderr>); } else { # child for my $k (keys %$env) { $ENV{$k} = $env->{$k}; } - open STDOUT, "> $STDOUT" or exit $FAILURE_CODE; - open STDERR, "> $STDERR" and do { exec $PERL, @$args }; + open STDOUT, '>', $STDOUT or exit $FAILURE_CODE; + open STDERR, '>', $STDERR and do { exec $PERL, @$args }; # it didn't_work: print STDOUT "IWHCWJIHCI\cNHJWCJQWKJQJWCQW\n"; exit $FAILURE_CODE; @@ -128,9 +129,9 @@ try({PERL5OPT => '-Mstrict -Mwarnings'}, "ok", ""); -open F, ">", "Oooof.pm" or die "Can't write Oooof.pm: $!"; -print F "package Oooof; 1;\n"; -close F; +open my $fh, ">", "Oooof.pm" or die "Can't write Oooof.pm: $!"; +print $fh "package Oooof; 1;\n"; +close $fh; END { 1 while unlink "Oooof.pm" } try({PERL5OPT => '-I. -MOooof'}, |