From 1e9dc3ce45ac44ea51292ca964b52ce47fee3ad3 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Tue, 12 Jul 2005 04:35:13 +0000 Subject: Various minor updates and code cleanups. --- tests/test_driver.pl | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'tests/test_driver.pl') diff --git a/tests/test_driver.pl b/tests/test_driver.pl index 7cd40b5..4b4e72b 100644 --- a/tests/test_driver.pl +++ b/tests/test_driver.pl @@ -32,12 +32,35 @@ $tests_passed = 0; # Yeesh. This whole test environment is such a hack! $test_passed = 1; -sub toplevel + +# %makeENV is the cleaned-out environment. +%makeENV = (); + +# %extraENV are any extra environment variables the tests might want to set. +# These are RESET AFTER EVERY TEST! +%extraENV = (); + +# %origENV is the caller's original environment +%origENV = %ENV; + +sub resetENV { - # Get a clean environment + # We used to say "%ENV = ();" but this doesn't work in Perl 5.000 + # through Perl 5.004. It was fixed in Perl 5.004_01, but we don't + # want to require that here, so just delete each one individually. + foreach $v (keys %ENV) { + delete $ENV{$v}; + } - %makeENV = (); + %ENV = %makeENV; + foreach $v (keys %extraENV) { + $ENV{$v} = $extraENV{$v}; + delete $extraENV{$v}; + } +} +sub toplevel +{ # Pull in benign variables from the user's environment # foreach (# UNIX-specific things @@ -57,15 +80,7 @@ sub toplevel # %origENV = %ENV; - # We used to say "%ENV = ();" but this doesn't work in Perl 5.000 - # through Perl 5.004. It was fixed in Perl 5.004_01, but we don't - # want to require that here, so just delete each one individually. - - foreach $v (keys %ENV) { - delete $ENV{$v}; - } - - %ENV = %makeENV; + resetENV(); $| = 1; # unbuffered output @@ -744,6 +759,11 @@ sub run_command { local ($code); + # We reset this before every invocation. On Windows I think there is only + # one environment, not one per process, so I think that variables set in + # test scripts might leak into subsequent tests if this isn't reset--??? + resetENV(); + print "\nrun_command: @_\n" if $debug; $code = system @_; print "run_command: \"@_\" returned $code.\n" if $debug; @@ -761,6 +781,11 @@ sub run_command_with_output local ($filename) = shift; local ($code); + # We reset this before every invocation. On Windows I think there is only + # one environment, not one per process, so I think that variables set in + # test scripts might leak into subsequent tests if this isn't reset--??? + resetENV(); + &attach_default_output ($filename); $code = system @_; &detach_default_output; -- cgit v1.2.3