$description = "Test handling of temporary file created from stdin.";
-use File::Temp qw /tempdir/;
-
-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));
-}
+# These tests rely on the test_driver checking for leftover temporary content
create_file('input.mk', "world:=1\n");
create_file('bye.mk', "moon:=2\n");
my @opts = ('-v', '-h', '--nosuchopt');
my @exit_codes = (0, 0, 512);
for my $i (0 .. $#opts) {
- my $tdir = tempdir(CLEANUP => 1);
- $ENV{'TMPDIR'} = $tdir;
- $ENV{'TMP'} = $tdir;
close(STDIN);
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
run_make_test(q!
all:; $(info hello world)
!,
"$opts[$i] -f-", "/uilt for /", $exit_codes[$i]);
- check_tempfile($tdir);
}
# sv 62118,62145.
# Test that a stdin temp file is removed.
-my $tdir = tempdir(CLEANUP => 1);
-$ENV{'TMPDIR'} = $tdir;
-$ENV{'TMP'} = $tdir;
close(STDIN);
open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!";
run_make_test(q!
all:; $(info world=$(world))
!,
'-f-', "world=1\n#MAKE#: 'all' is up to date.\n");
-check_tempfile($tdir);
# sv 62118,62145.
# Test that a stdin temp file is removed, even when make re-execs.
-# Also test that make nohors TMPDIR to create the temp file.
-$tdir = tempdir(CLEANUP => 1);
-$ENV{'TMPDIR'} = $tdir;
-$ENV{'TMP'} = $tdir;
+# Also test that make honors TMPDIR to create the temp file.
# Ensure touching bye.mk causes re-exec.
&utouch(-600, 'bye.mk');
close(STDIN);
$(MAKE_RESTARTS)bye.mk: force; touch $@
force:
!,
- '-R --debug=b -f-', "/Re-executing.+?--temp-stdin=\Q$tdir\E/");
-check_tempfile($tdir);
+ '-R --debug=b -f-', "/Re-executing.+?--temp-stdin=\Q$temppath\E/");
if ($port_type eq 'UNIX') {
# sv 62118,62145.
# 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
# directory and take away the 'x' bit.
+use File::Spec;
use File::Copy;
-my $tdir = tempdir(CLEANUP => 1);
-$ENV{'TMPDIR'} = $tdir;
-$ENV{'TMP'} = $tdir;
-my $makecopy = "$tdir/make";
+my $makecopy = File::Spec->catfile($TEMPDIR, "make");
copy("$mkpath", $makecopy);
# Set file mode bits, because perl copy won't.
chmod 0750, $makecopy;
force:
",
"-f-", "touch bye.mk && chmod -x $makecopy\nmake: $makecopy: $ERR_nonexe_file\n", 32512);
-check_tempfile($tdir);
@make_command = @make_orig;
unlink($makecopy);
use Config;
use Cwd;
use File::Spec;
+use File::Temp;
# The number of test categories we've run
$categories_run = 0;
$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') {
}
# %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
sub toplevel
{
+ %origENV = %ENV unless $^O eq 'VMS';
+
# Pull in benign variables from the user's environment
foreach (# POSIX-specific things
$makeENV{LANGUAGE} = 'C';
# Replace the environment with the new one
- #
- %origENV = %ENV unless $^O eq 'VMS';
-
resetENV();
$| = 1; # unbuffered output
$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.
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";
&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) {
rmdir ("$workpath/$dir");
}
+ rmdir ($temppath);
+
$| = 1;
$categories_failed = $categories_run - $categories_passed;
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;
&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;