util/perl/OpenSSL/Test.pm: Disable stdout/stderr redirection on non-verbosity

... except on VMS, where output from executed programs doesn't seem to be
captured properly by Test::Harness or TAP::Harness.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9862)
This commit is contained in:
Richard Levitte 2019-09-11 11:02:24 +02:00
parent 45211c563f
commit f3503cb0f6

View file

@ -446,16 +446,21 @@ sub run {
die "OpenSSL::Test::run(): statusvar value not a scalar reference" die "OpenSSL::Test::run(): statusvar value not a scalar reference"
if $opts{statusvar} && ref($opts{statusvar}) ne "SCALAR"; if $opts{statusvar} && ref($opts{statusvar}) ne "SCALAR";
# In non-verbose, we want to shut up the command interpreter, in case # For some reason, program output, or even output from this function
# it has something to complain about. On VMS, it might complain both # somehow isn't caught by TAP::Harness (TAP::Parser?) on VMS, so we're
# on stdout and stderr # silencing it specifically there until further notice.
my $save_STDOUT; my $save_STDOUT;
my $save_STDERR; my $save_STDERR;
if ($ENV{HARNESS_ACTIVE} && !$ENV{HARNESS_VERBOSE}) { if ($^O eq 'VMS') {
open $save_STDOUT, '>&', \*STDOUT or die "Can't dup STDOUT: $!"; # In non-verbose, we want to shut up the command interpreter, in case
open $save_STDERR, '>&', \*STDERR or die "Can't dup STDERR: $!"; # it has something to complain about. On VMS, it might complain both
open STDOUT, ">", devnull(); # on stdout and stderr
open STDERR, ">", devnull(); if ($ENV{HARNESS_ACTIVE} && !$ENV{HARNESS_VERBOSE}) {
open $save_STDOUT, '>&', \*STDOUT or die "Can't dup STDOUT: $!";
open $save_STDERR, '>&', \*STDERR or die "Can't dup STDERR: $!";
open STDOUT, ">", devnull();
open STDERR, ">", devnull();
}
} }
$ENV{HARNESS_OSSL_LEVEL} = $level + 1; $ENV{HARNESS_OSSL_LEVEL} = $level + 1;
@ -489,15 +494,20 @@ sub run {
${$opts{statusvar}} = $r; ${$opts{statusvar}} = $r;
} }
if ($ENV{HARNESS_ACTIVE} && !$ENV{HARNESS_VERBOSE}) { # Restore STDOUT / STDERR on VMS
close STDOUT; if ($^O eq 'VMS') {
close STDERR; if ($ENV{HARNESS_ACTIVE} && !$ENV{HARNESS_VERBOSE}) {
open STDOUT, '>&', $save_STDOUT or die "Can't restore STDOUT: $!"; close STDOUT;
open STDERR, '>&', $save_STDERR or die "Can't restore STDERR: $!"; close STDERR;
} open STDOUT, '>&', $save_STDOUT or die "Can't restore STDOUT: $!";
open STDERR, '>&', $save_STDERR or die "Can't restore STDERR: $!";
}
print STDERR "$prefix$display_cmd => $e\n" print STDERR "$prefix$display_cmd => $e\n"
if !$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE}; if !$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE};
} else {
print STDERR "$prefix$display_cmd => $e\n";
}
# At this point, $? stops being interesting, and unfortunately, # At this point, $? stops being interesting, and unfortunately,
# there are Test::More versions that get picky if we leave it # there are Test::More versions that get picky if we leave it
@ -1244,8 +1254,11 @@ sub __decorate_cmd {
my $display_cmd = "$cmdstr$stdin$stdout$stderr"; my $display_cmd = "$cmdstr$stdin$stdout$stderr";
$stderr=" 2> ".$null # VMS program output escapes TAP::Parser
unless $stderr || !$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE}; if ($^O eq 'VMS') {
$stderr=" 2> ".$null
unless $stderr || !$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE};
}
$cmdstr .= "$stdin$stdout$stderr"; $cmdstr .= "$stdin$stdout$stderr";