diff options
author | Paul Smith <psmith@gnu.org> | 2022-08-28 23:48:09 -0400 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2022-08-29 00:09:10 -0400 |
commit | 5eff618c8cbfbe1f386e3a55499cd8fe26cd35a1 (patch) | |
tree | 2e0ff7317ff6b5cfa83d42403dcc78fc821db83a /tests/test_driver.pl | |
parent | 10e130b20793f650835085d5ebe85e4ad0c83654 (diff) | |
download | make-git-5eff618c8cbfbe1f386e3a55499cd8fe26cd35a1.tar.gz |
test_driver: check for leftover temp files after each test
Reset the temp directory for every test to a local directory, then
after each test see if any new temp files were created and not
deleted: if they were then fail the test. Rather than delete the
temp files we leave them there and avoid reporting files that were
seen before, so the user can investigate them.
Rewrite the temp_stdin tests to rely on this built-in behavior
rather than implementing the checks directly.
* tests/test_driver.pl: Create a $TEMPDIR variable pointing to a
temporary directory outside the test temp directory.
(toplevel) Before starting any tests create a temp directory and set
the POSIX and Windows temp directory environment variables to use it.
(compare_output) Check the contents of the temp directory. If any
new files have appeared, fail the test.
* tests/scripts/features/temp_stdin: Remove check_tempfile() and
all users of it, plus setting of temp environment variables.
Diffstat (limited to 'tests/test_driver.pl')
-rw-r--r-- | tests/test_driver.pl | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/tests/test_driver.pl b/tests/test_driver.pl index b04dadba..2beb7c99 100644 --- a/tests/test_driver.pl +++ b/tests/test_driver.pl @@ -33,6 +33,7 @@ use Config; use Cwd; use File::Spec; +use File::Temp; # The number of test categories we've run $categories_run = 0; @@ -61,6 +62,10 @@ $test_timeout = 10 if $^O eq 'VMS'; $diff_name = undef; +# Create a temporary directory that tests can use, outside the temp +# directory that make is using. +$TEMPDIR = File::Temp->newdir(); + # Path to Perl $perl_name = $^X; if ($^O ne 'VMS') { @@ -101,7 +106,7 @@ sub which { } # %makeENV is the cleaned-out environment. Tests must not modify it. -%makeENV = (); +my %makeENV = (); sub vms_get_process_logicals { # Sorry for the long note here, but to keep this test running on @@ -188,6 +193,8 @@ sub cmd2str sub toplevel { + %origENV = %ENV unless $^O eq 'VMS'; + # Pull in benign variables from the user's environment foreach (# POSIX-specific things @@ -213,9 +220,6 @@ sub toplevel $makeENV{LANGUAGE} = 'C'; # Replace the environment with the new one - # - %origENV = %ENV unless $^O eq 'VMS'; - resetENV(); $| = 1; # unbuffered output @@ -226,6 +230,7 @@ sub toplevel $detail = 0; # detailed verbosity $keep = 0; # keep temp files around $workdir = "work"; # The directory where the test will start running + $tempdir = "_tmp"; # A temporary directory $scriptdir = "scripts"; # The directory where we find the test scripts $tmpfilesuffix = "t"; # the suffix used on tmpfiles $default_output_stack_level = 0; # used by attach_default_output, etc. @@ -249,6 +254,23 @@ sub toplevel print "OS name = '$osname'\n" if $debug; + $temppath = File::Spec->rel2abs($tempdir); + + if (-d $temppath) { + print "Clearing $temppath...\n"; + &remove_directory_tree("$temppath/") + or &error ("Couldn't wipe out $temppath: $!\n"); + } else { + mkdir ($temppath, 0777) or error ("Cannot mkdir $temppath: $!\n"); + } + + # This is used by POSIX systems + $makeENV{TMPDIR} = $temppath; + + # These are used on Windows + $makeENV{TMP} = $temppath; + $makeENV{TEMP} = $temppath; + $workpath = "$cwdslash$workdir"; $scriptpath = "$cwdslash$scriptdir"; @@ -278,7 +300,7 @@ sub toplevel &remove_directory_tree("$workpath/") or &error ("Couldn't wipe out $workpath: $!\n"); } else { - mkdir ($workpath, 0777) or &error ("Couldn't mkdir $workpath: $!\n"); + mkdir ($workpath, 0777) or &error ("Cannot mkdir $workpath: $!\n"); } if (!-d $scriptpath) { @@ -332,6 +354,8 @@ sub toplevel rmdir ("$workpath/$dir"); } + rmdir ($temppath); + $| = 1; $categories_failed = $categories_run - $categories_passed; @@ -786,13 +810,29 @@ sub error die "$caller: $message"; } +my %old_tempfiles = (); + sub compare_output { my ($answer, $logfile) = @_; - my ($slurp, $answer_matched) = ('', 0); + my ($slurp, $answer_matched, $extra) = ('', 0, 0); ++$tests_run; + my @tf = (); + foreach my $file (glob(File::Spec->catfile($temppath, "*"))) { + if (!exists $old_tempfiles{$file}) { + push @tf, $file; + $old_tempfiles{$file} = 1; + } + } + if (@tf) { + open (LOGFILE, '>>', $logfile) or die "Cannot open log file $logfile: $!\n"; + print LOGFILE "Leftover temporary files: @tf\n"; + close (LOGFILE); + $extra = 1; + } + if (! defined $answer) { print "Ignoring output ........ " if $debug; $answer_matched = 1; @@ -950,7 +990,7 @@ sub compare_output &create_file(&get_runfile, $command_string); } - if ($answer_matched && $test_passed) { + if ($answer_matched && $test_passed && !$extra) { print "ok\n" if $debug; ++$tests_passed; return 1; |