From: Nicholas Clark Date: Thu, 7 Aug 2008 10:12:09 +0000 (+0000) Subject: Fix bug in counting in tempfile(). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=748a4b20dad489edbf351cfb9cf18f6da44f79f5;p=p5sagit%2Fp5-mst-13.2.git 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 --- diff --git a/t/test.pl b/t/test.pl index f0b4879..fbb65db 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'.