summaryrefslogtreecommitdiff
path: root/t/test.pl
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-08-07 08:23:13 +0000
committerNicholas Clark <nick@ccl4.org>2008-08-07 08:23:13 +0000
commitc1ddc35c47e1b3519bfe90eecd67145f73c0f30a (patch)
treed4136f1cf17652df6f3bd4826f7a125b14dbb886 /t/test.pl
parent0ae187c2299ef45fea08a054a5af0902048b539e (diff)
downloadperl-c1ddc35c47e1b3519bfe90eecd67145f73c0f30a.tar.gz
A proper tempfile function that can be used multiple times.
p4raw-id: //depot/perl@34178
Diffstat (limited to 't/test.pl')
-rw-r--r--t/test.pl11
1 files changed, 9 insertions, 2 deletions
diff --git a/t/test.pl b/t/test.pl
index 1259ed6c4c..f0b4879674 100644
--- a/t/test.pl
+++ b/t/test.pl
@@ -619,6 +619,9 @@ sub unlink_all {
}
}
+my @tmpfiles;
+END { unlink_all @tmpfiles }
+
# Avoid ++, avoid ranges, avoid split //
my @letters = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
sub tempfile {
@@ -630,14 +633,18 @@ sub tempfile {
$try .= $letters[$temp % 26];
$count = int ($temp / 26);
} while $temp;
- return $try unless -e $try;
+ if (!-e $try) {
+ # We have a winner
+ push @tmpfiles, $try;
+ return $try;
+ }
$count = $count + 1;
} while $count < 26 * 26;
die "Can't find temporary file name starting 'tmp$$'";
}
+# This is the temporary file for _fresh_perl
my $tmpfile = tempfile();
-END { unlink_all $tmpfile }
#
# _fresh_perl