summaryrefslogtreecommitdiff
path: root/t/test.pl
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-08-07 10:12:09 +0000
committerNicholas Clark <nick@ccl4.org>2008-08-07 10:12:09 +0000
commit748a4b20dad489edbf351cfb9cf18f6da44f79f5 (patch)
treeaf679a4b5113705e933d237589e4b12d112dacea /t/test.pl
parentc1ddc35c47e1b3519bfe90eecd67145f73c0f30a (diff)
downloadperl-748a4b20dad489edbf351cfb9cf18f6da44f79f5.tar.gz
Fix bug in counting in tempfile().
Also we need to note file names we give out, as some callers don't create them before calling us a second time. Add a regexp that matches the tempfile() names, for tests that want to munge output. p4raw-id: //depot/perl@34179
Diffstat (limited to 't/test.pl')
-rw-r--r--t/test.pl19
1 files changed, 12 insertions, 7 deletions
diff --git a/t/test.pl b/t/test.pl
index f0b4879674..fbb65db03e 100644
--- a/t/test.pl
+++ b/t/test.pl
@@ -619,8 +619,11 @@ sub unlink_all {
}
}
-my @tmpfiles;
-END { unlink_all @tmpfiles }
+my %tmpfiles;
+END { unlink_all keys %tmpfiles }
+
+# A regexp that matches the tempfile names
+$::tempfile_regexp = 'tmp\d+[A-Z][A-Z]?';
# 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);
@@ -631,11 +634,13 @@ sub tempfile {
my $try = "tmp$$";
do {
$try .= $letters[$temp % 26];
- $count = int ($temp / 26);
+ $temp = int ($temp / 26);
} while $temp;
- if (!-e $try) {
+ # Need to note all the file names we allocated, as a second request may
+ # come before the first is created.
+ if (!-e $try && !$tmpfiles{$try}) {
# We have a winner
- push @tmpfiles, $try;
+ $tmpfiles{$try}++;
return $try;
}
$count = $count + 1;
@@ -680,8 +685,8 @@ sub _fresh_perl {
# Clean up the results into something a bit more predictable.
$results =~ s/\n+$//;
- $results =~ s/at\s+tmp\d+[A-Z][A-Z]?\s+line/at - line/g;
- $results =~ s/of\s+tmp\d+[A-Z][A-Z]?\s+aborted/of - aborted/g;
+ $results =~ s/at\s+$::tempfile_regexp\s+line/at - line/g;
+ $results =~ s/of\s+$::tempfile_regexp\s+aborted/of - aborted/g;
# bison says 'parse error' instead of 'syntax error',
# various yaccs may or may not capitalize 'syntax'.