mirror of
https://github.com/mirror/make.git
synced 2025-02-05 17:20:15 +08:00
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.
This commit is contained in:
parent
10e130b207
commit
5eff618c8c
@ -2,16 +2,7 @@
|
|||||||
|
|
||||||
$description = "Test handling of temporary file created from stdin.";
|
$description = "Test handling of temporary file created from stdin.";
|
||||||
|
|
||||||
use File::Temp qw /tempdir/;
|
# These tests rely on the test_driver checking for leftover temporary content
|
||||||
|
|
||||||
sub check_tempfile
|
|
||||||
{
|
|
||||||
my ($tdir) = @_;
|
|
||||||
my @left = glob $tdir . '/Gm*';
|
|
||||||
scalar @left == 0 && return;
|
|
||||||
my $answer = "temporary file $left[0] is left behind\n";
|
|
||||||
compare_output($answer, &get_logfile(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
create_file('input.mk', "world:=1\n");
|
create_file('input.mk', "world:=1\n");
|
||||||
create_file('bye.mk', "moon:=2\n");
|
create_file('bye.mk', "moon:=2\n");
|
||||||
@ -22,37 +13,26 @@ create_file('bye.mk', "moon:=2\n");
|
|||||||
my @opts = ('-v', '-h', '--nosuchopt');
|
my @opts = ('-v', '-h', '--nosuchopt');
|
||||||
my @exit_codes = (0, 0, 512);
|
my @exit_codes = (0, 0, 512);
|
||||||
for my $i (0 .. $#opts) {
|
for my $i (0 .. $#opts) {
|
||||||
my $tdir = tempdir(CLEANUP => 1);
|
|
||||||
$ENV{'TMPDIR'} = $tdir;
|
|
||||||
$ENV{'TMP'} = $tdir;
|
|
||||||
close(STDIN);
|
close(STDIN);
|
||||||
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
|
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
|
||||||
run_make_test(q!
|
run_make_test(q!
|
||||||
all:; $(info hello world)
|
all:; $(info hello world)
|
||||||
!,
|
!,
|
||||||
"$opts[$i] -f-", "/uilt for /", $exit_codes[$i]);
|
"$opts[$i] -f-", "/uilt for /", $exit_codes[$i]);
|
||||||
check_tempfile($tdir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# sv 62118,62145.
|
# sv 62118,62145.
|
||||||
# Test that a stdin temp file is removed.
|
# Test that a stdin temp file is removed.
|
||||||
my $tdir = tempdir(CLEANUP => 1);
|
|
||||||
$ENV{'TMPDIR'} = $tdir;
|
|
||||||
$ENV{'TMP'} = $tdir;
|
|
||||||
close(STDIN);
|
close(STDIN);
|
||||||
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
|
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
|
||||||
run_make_test(q!
|
run_make_test(q!
|
||||||
all:; $(info world=$(world))
|
all:; $(info world=$(world))
|
||||||
!,
|
!,
|
||||||
'-f-', "world=1\n#MAKE#: 'all' is up to date.\n");
|
'-f-', "world=1\n#MAKE#: 'all' is up to date.\n");
|
||||||
check_tempfile($tdir);
|
|
||||||
|
|
||||||
# sv 62118,62145.
|
# sv 62118,62145.
|
||||||
# Test that a stdin temp file is removed, even when make re-execs.
|
# Test that a stdin temp file is removed, even when make re-execs.
|
||||||
# Also test that make nohors TMPDIR to create the temp file.
|
# Also test that make honors TMPDIR to create the temp file.
|
||||||
$tdir = tempdir(CLEANUP => 1);
|
|
||||||
$ENV{'TMPDIR'} = $tdir;
|
|
||||||
$ENV{'TMP'} = $tdir;
|
|
||||||
# Ensure touching bye.mk causes re-exec.
|
# Ensure touching bye.mk causes re-exec.
|
||||||
&utouch(-600, 'bye.mk');
|
&utouch(-600, 'bye.mk');
|
||||||
close(STDIN);
|
close(STDIN);
|
||||||
@ -63,20 +43,17 @@ all:; $(info hello)
|
|||||||
$(MAKE_RESTARTS)bye.mk: force; touch $@
|
$(MAKE_RESTARTS)bye.mk: force; touch $@
|
||||||
force:
|
force:
|
||||||
!,
|
!,
|
||||||
'-R --debug=b -f-', "/Re-executing.+?--temp-stdin=\Q$tdir\E/");
|
'-R --debug=b -f-', "/Re-executing.+?--temp-stdin=\Q$temppath\E/");
|
||||||
check_tempfile($tdir);
|
|
||||||
|
|
||||||
if ($port_type eq 'UNIX') {
|
if ($port_type eq 'UNIX') {
|
||||||
# sv 62118,62145.
|
# sv 62118,62145.
|
||||||
# Test that a stdin temp file is removed, when execvp fails to re-exec make.
|
# Test that a stdin temp file is removed, when execvp fails to re-exec make.
|
||||||
# In order to cause execvp to fail, copy the tested make binary to the temp
|
# In order to cause execvp to fail, copy the tested make binary to the temp
|
||||||
# directory and take away the 'x' bit.
|
# directory and take away the 'x' bit.
|
||||||
|
use File::Spec;
|
||||||
use File::Copy;
|
use File::Copy;
|
||||||
|
|
||||||
my $tdir = tempdir(CLEANUP => 1);
|
my $makecopy = File::Spec->catfile($TEMPDIR, "make");
|
||||||
$ENV{'TMPDIR'} = $tdir;
|
|
||||||
$ENV{'TMP'} = $tdir;
|
|
||||||
my $makecopy = "$tdir/make";
|
|
||||||
copy("$mkpath", $makecopy);
|
copy("$mkpath", $makecopy);
|
||||||
# Set file mode bits, because perl copy won't.
|
# Set file mode bits, because perl copy won't.
|
||||||
chmod 0750, $makecopy;
|
chmod 0750, $makecopy;
|
||||||
@ -95,7 +72,6 @@ all:; \$(info hello)
|
|||||||
force:
|
force:
|
||||||
",
|
",
|
||||||
"-f-", "touch bye.mk && chmod -x $makecopy\nmake: $makecopy: $ERR_nonexe_file\n", 32512);
|
"-f-", "touch bye.mk && chmod -x $makecopy\nmake: $makecopy: $ERR_nonexe_file\n", 32512);
|
||||||
check_tempfile($tdir);
|
|
||||||
|
|
||||||
@make_command = @make_orig;
|
@make_command = @make_orig;
|
||||||
unlink($makecopy);
|
unlink($makecopy);
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
use Config;
|
use Config;
|
||||||
use Cwd;
|
use Cwd;
|
||||||
use File::Spec;
|
use File::Spec;
|
||||||
|
use File::Temp;
|
||||||
|
|
||||||
# The number of test categories we've run
|
# The number of test categories we've run
|
||||||
$categories_run = 0;
|
$categories_run = 0;
|
||||||
@ -61,6 +62,10 @@ $test_timeout = 10 if $^O eq 'VMS';
|
|||||||
|
|
||||||
$diff_name = undef;
|
$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
|
# Path to Perl
|
||||||
$perl_name = $^X;
|
$perl_name = $^X;
|
||||||
if ($^O ne 'VMS') {
|
if ($^O ne 'VMS') {
|
||||||
@ -101,7 +106,7 @@ sub which {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# %makeENV is the cleaned-out environment. Tests must not modify it.
|
# %makeENV is the cleaned-out environment. Tests must not modify it.
|
||||||
%makeENV = ();
|
my %makeENV = ();
|
||||||
|
|
||||||
sub vms_get_process_logicals {
|
sub vms_get_process_logicals {
|
||||||
# Sorry for the long note here, but to keep this test running on
|
# Sorry for the long note here, but to keep this test running on
|
||||||
@ -188,6 +193,8 @@ sub cmd2str
|
|||||||
|
|
||||||
sub toplevel
|
sub toplevel
|
||||||
{
|
{
|
||||||
|
%origENV = %ENV unless $^O eq 'VMS';
|
||||||
|
|
||||||
# Pull in benign variables from the user's environment
|
# Pull in benign variables from the user's environment
|
||||||
|
|
||||||
foreach (# POSIX-specific things
|
foreach (# POSIX-specific things
|
||||||
@ -213,9 +220,6 @@ sub toplevel
|
|||||||
$makeENV{LANGUAGE} = 'C';
|
$makeENV{LANGUAGE} = 'C';
|
||||||
|
|
||||||
# Replace the environment with the new one
|
# Replace the environment with the new one
|
||||||
#
|
|
||||||
%origENV = %ENV unless $^O eq 'VMS';
|
|
||||||
|
|
||||||
resetENV();
|
resetENV();
|
||||||
|
|
||||||
$| = 1; # unbuffered output
|
$| = 1; # unbuffered output
|
||||||
@ -226,6 +230,7 @@ sub toplevel
|
|||||||
$detail = 0; # detailed verbosity
|
$detail = 0; # detailed verbosity
|
||||||
$keep = 0; # keep temp files around
|
$keep = 0; # keep temp files around
|
||||||
$workdir = "work"; # The directory where the test will start running
|
$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
|
$scriptdir = "scripts"; # The directory where we find the test scripts
|
||||||
$tmpfilesuffix = "t"; # the suffix used on tmpfiles
|
$tmpfilesuffix = "t"; # the suffix used on tmpfiles
|
||||||
$default_output_stack_level = 0; # used by attach_default_output, etc.
|
$default_output_stack_level = 0; # used by attach_default_output, etc.
|
||||||
@ -249,6 +254,23 @@ sub toplevel
|
|||||||
|
|
||||||
print "OS name = '$osname'\n" if $debug;
|
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";
|
$workpath = "$cwdslash$workdir";
|
||||||
$scriptpath = "$cwdslash$scriptdir";
|
$scriptpath = "$cwdslash$scriptdir";
|
||||||
|
|
||||||
@ -278,7 +300,7 @@ sub toplevel
|
|||||||
&remove_directory_tree("$workpath/")
|
&remove_directory_tree("$workpath/")
|
||||||
or &error ("Couldn't wipe out $workpath: $!\n");
|
or &error ("Couldn't wipe out $workpath: $!\n");
|
||||||
} else {
|
} else {
|
||||||
mkdir ($workpath, 0777) or &error ("Couldn't mkdir $workpath: $!\n");
|
mkdir ($workpath, 0777) or &error ("Cannot mkdir $workpath: $!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!-d $scriptpath) {
|
if (!-d $scriptpath) {
|
||||||
@ -332,6 +354,8 @@ sub toplevel
|
|||||||
rmdir ("$workpath/$dir");
|
rmdir ("$workpath/$dir");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rmdir ($temppath);
|
||||||
|
|
||||||
$| = 1;
|
$| = 1;
|
||||||
|
|
||||||
$categories_failed = $categories_run - $categories_passed;
|
$categories_failed = $categories_run - $categories_passed;
|
||||||
@ -786,13 +810,29 @@ sub error
|
|||||||
die "$caller: $message";
|
die "$caller: $message";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my %old_tempfiles = ();
|
||||||
|
|
||||||
sub compare_output
|
sub compare_output
|
||||||
{
|
{
|
||||||
my ($answer, $logfile) = @_;
|
my ($answer, $logfile) = @_;
|
||||||
my ($slurp, $answer_matched) = ('', 0);
|
my ($slurp, $answer_matched, $extra) = ('', 0, 0);
|
||||||
|
|
||||||
++$tests_run;
|
++$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) {
|
if (! defined $answer) {
|
||||||
print "Ignoring output ........ " if $debug;
|
print "Ignoring output ........ " if $debug;
|
||||||
$answer_matched = 1;
|
$answer_matched = 1;
|
||||||
@ -950,7 +990,7 @@ sub compare_output
|
|||||||
&create_file(&get_runfile, $command_string);
|
&create_file(&get_runfile, $command_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($answer_matched && $test_passed) {
|
if ($answer_matched && $test_passed && !$extra) {
|
||||||
print "ok\n" if $debug;
|
print "ok\n" if $debug;
|
||||||
++$tests_passed;
|
++$tests_passed;
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user