Skip to content

Commit

Permalink
Per #1624, unset the test-specific environment variables after comple…
Browse files Browse the repository at this point in the history
…ting the run.
  • Loading branch information
JohnHalleyGotway committed Jan 19, 2021
1 parent cc1b9fa commit 1d99733
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions test/perl/unit.pl
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ sub usage {
elsif ($callchk) {
$cmd = "valgrind ".$VALGRIND_OPT_CALL." ".$cmd;
}

# if writing a command file, print the environment and command, then loop
if( $cmd_only ){
print "export $_=\'" . $test->{"env"}{$_} . "\'\n" for sort keys %{ $test->{"env"} };
print "$cmd\n\n";
print "$cmd\n";
print "unset $_\n" for sort keys %{ $test->{"env"} };
print "\n";
next;
}

Expand Down Expand Up @@ -137,23 +139,28 @@ sub usage {

}

# unset the test environment variables
delete $ENV{$_} for keys %{ $test->{"env"} };

# print the test result
printf "%s - %7.3f sec\n", $ret_ok && $out_ok ? "pass" : "FAIL", sprintf("%7.3f", $t_elaps);

# build a list of environment variable exports for reporting
my @envs;
push @envs, "export $_=\'" . $test->{"env"}{$_} . "\'\n" for sort keys %{ $test->{"env"} };
# build a list of environment variable exports and unsets for reporting
my @set_envs;
push @set_envs, "export $_=\'" . $test->{"env"}{$_} . "\'\n" for sort keys %{ $test->{"env"} };
my @unset_envs;
push @unset_envs, "unset $_\n" for sort keys %{ $test->{"env"} };

# if the log file is activated, print the test information
if( $file_log ){
print $fh_log "\n\n";
print $fh_log "$_" for (@envs, @cmd_outs);
print $fh_log "$_" for (@set_envs, @cmd_outs, @unset_envs);
print $fh_log "\n\n";
}

# on failure, print the problematic test and exit, if requested
if( !($ret_ok && $out_ok) ){
print "$_" for (@envs, @cmd_outs);
print "$_" for (@set_envs, @cmd_outs, @unset_envs);
$noexit or exit 1;
print "\n\n";
}
Expand Down

0 comments on commit 1d99733

Please sign in to comment.