diff options
author | Nicholas Clark <nick@ccl4.org> | 2008-08-07 15:21:57 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2008-08-07 15:21:57 +0000 |
commit | 62a28c976c312a2c7269acc71060b1037a453bea (patch) | |
tree | 03534ff61bd58514aba49f497238bb3f414018f2 /t/io/fflush.t | |
parent | 213f370f28504f3af87af602895b0afe68c0106a (diff) | |
download | perl-62a28c976c312a2c7269acc71060b1037a453bea.tar.gz |
Convert all unimaginative (ie race condition) temporary file names to
use test.pl's tempfile().
p4raw-id: //depot/perl@34182
Diffstat (limited to 't/io/fflush.t')
-rw-r--r-- | t/io/fflush.t | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/t/io/fflush.t b/t/io/fflush.t index 19143c6304..056517fd3e 100644 --- a/t/io/fflush.t +++ b/t/io/fflush.t @@ -37,14 +37,6 @@ if ($useperlio || $fflushNULL || $d_sfio) { my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X; $runperl .= qq{ "-I../lib"}; -my @delete; - -END { - for (@delete) { - unlink $_ or warn "unlink $_: $!"; - } -} - sub file_eq { my $f = shift; my $val = shift; @@ -60,7 +52,8 @@ sub file_eq { # This script will be used as the command to execute from # child processes -open PROG, "> ff-prog" or die "open ff-prog: $!"; +my $ffprog = tempfile(); +open PROG, "> $ffprog" or die "open $ffprog: $!"; print PROG <<'EOF'; my $f = shift; my $str = shift; @@ -69,8 +62,7 @@ print OUT $str; close OUT; EOF ; -close PROG or die "close ff-prog: $!";; -push @delete, "ff-prog"; +close PROG or die "close $ffprog: $!";; $| = 0; # we want buffered output @@ -78,7 +70,7 @@ $| = 0; # we want buffered output if (!$d_fork) { print "ok 1 # skipped: no fork\n"; } else { - my $f = "ff-fork-$$"; + my $f = tempfile(); open OUT, "> $f" or die "open $f: $!"; print OUT "Pe"; my $pid = fork; @@ -89,7 +81,7 @@ if (!$d_fork) { } elsif (defined $pid) { # Kid print OUT "r"; - my $command = qq{$runperl "ff-prog" "$f" "l"}; + my $command = qq{$runperl "$ffprog" "$f" "l"}; print "# $command\n"; exec $command or die $!; exit; @@ -99,7 +91,6 @@ if (!$d_fork) { } print file_eq($f, "Perl") ? "ok 1\n" : "not ok 1\n"; - push @delete, $f; } # Test flush on system/qx/pipe open @@ -121,15 +112,14 @@ my %subs = ( my $t = 2; for (qw(system qx popen)) { my $code = $subs{$_}; - my $f = "ff-$_-$$"; - my $command = qq{$runperl "ff-prog" "$f" "rl"}; + my $f = tempfile(); + my $command = qq{$runperl $ffprog "$f" "rl"}; open OUT, "> $f" or die "open $f: $!"; print OUT "Pe"; close OUT or die "close $f: $!";; print "# $command\n"; $code->($command); print file_eq($f, "Perl") ? "ok $t\n" : "not ok $t\n"; - push @delete, $f; ++$t; } |