Change 34184 by [EMAIL PROTECTED] on 2008/08/08 09:59:45

        Convert all unimaginative (ie race condition) temporary file names to   
        use test.pl's tempfile().

Affected files ...

... //depot/perl/t/comp/multiline.t#13 edit
... //depot/perl/t/comp/script.t#14 edit
... //depot/perl/t/comp/use.t#32 edit
... //depot/perl/t/comp/utf.t#6 edit
... //depot/perl/t/run/cloexec.t#5 edit
... //depot/perl/t/run/runenv.t#13 edit
... //depot/perl/t/run/switchC.t#7 edit
... //depot/perl/t/run/switchF1.t#2 edit
... //depot/perl/t/run/switchd.t#7 edit
... //depot/perl/t/run/switches.t#27 edit
... //depot/perl/t/run/switcht.t#5 edit

Differences ...

==== //depot/perl/t/comp/multiline.t#13 (xtext) ====
Index: perl/t/comp/multiline.t
--- perl/t/comp/multiline.t#12~30971~   2007-04-17 10:12:23.000000000 -0700
+++ perl/t/comp/multiline.t     2008-08-08 02:59:45.000000000 -0700
@@ -8,7 +8,8 @@
 
 plan(tests => 6);
 
-open(TRY,'>Comp.try') || (die "Can't open temp file.");
+my $filename = tempfile();
+open(TRY,'>',$filename) || (die "Can't open $filename: $!");
 
 $x = 'now is the time
 for all good men
@@ -28,7 +29,7 @@
 print TRY $x;
 close TRY or die "Could not close: $!";
 
-open(TRY,'Comp.try') || (die "Can't reopen temp file.");
+open(TRY,$filename) || (die "Can't reopen $filename: $!");
 $count = 0;
 $z = '';
 while (<TRY>) {
@@ -42,12 +43,11 @@
 is($., 7,       '    $.' );
 
 $out = (($^O eq 'MSWin32') || $^O eq 'NetWare' || $^O eq 'VMS') ? `type 
Comp.try`
-    : ($^O eq 'MacOS') ? `catenate Comp.try`
-    : `cat Comp.try`;
+    : ($^O eq 'MacOS') ? `catenate $filename`
+    : `cat $filename`;
 
 like($out, qr/.*\n.*\n.*\n$/);
 
-close(TRY) || (die "Can't close temp file.");
-unlink 'Comp.try' || `/bin/rm -f Comp.try`;
+close(TRY) || (die "Can't close $filename: $!");
 
 is($out, $y);

==== //depot/perl/t/comp/script.t#14 (xtext) ====
Index: perl/t/comp/script.t
--- perl/t/comp/script.t#13~14340~      2002-01-18 19:00:26.000000000 -0800
+++ perl/t/comp/script.t        2008-08-08 02:59:45.000000000 -0700
@@ -8,22 +8,22 @@
 
 my $Perl = which_perl();
 
+my $filename = tempfile();
+
 print "1..3\n";
 
 $x = `$Perl -le "print 'ok';"`;
 
 if ($x eq "ok\n") {print "ok 1\n";} else {print "not ok 1\n";}
 
-open(try,">Comp.script") || (die "Can't open temp file.");
+open(try,">$filename") || (die "Can't open temp file.");
 print try 'print "ok\n";'; print try "\n";
 close try or die "Could not close: $!";
 
-$x = `$Perl Comp.script`;
+$x = `$Perl $filename`;
 
 if ($x eq "ok\n") {print "ok 2\n";} else {print "not ok 2\n";}
 
-$x = `$Perl <Comp.script`;
+$x = `$Perl <$filename`;
 
 if ($x eq "ok\n") {print "ok 3\n";} else {print "not ok 3\n";}
-
-unlink 'Comp.script' || `/bin/rm -f Comp.script`;

==== //depot/perl/t/comp/use.t#32 (xtext) ====
Index: perl/t/comp/use.t
--- perl/t/comp/use.t#31~32003~ 2007-10-02 04:56:28.000000000 -0700
+++ perl/t/comp/use.t   2008-08-08 02:59:45.000000000 -0700
@@ -190,12 +190,12 @@
 {
     # Regression test for patch 14937: 
     #   Check that a .pm file with no package or VERSION doesn't core.
-    open F, ">xxx.pm" or die "Cannot open xxx.pm: $!\n";
+    open F, ">xxx$$.pm" or die "Cannot open xxx$$.pm: $!\n";
     print F "1;\n";
     close F;
-    eval "use lib '.'; use xxx 3;";
-    like ($@, qr/^xxx defines neither package nor VERSION--version check 
failed at/);
-    unlink 'xxx.pm';
+    eval "use lib '.'; use xxx$$ 3;";
+    like ($@, qr/^xxx$$ defines neither package nor VERSION--version check 
failed at/);
+    unlink "xxx$$.pm";
 }
 
 my @ver = split /\./, sprintf "%vd", $^V;

==== //depot/perl/t/comp/utf.t#6 (text) ====
Index: perl/t/comp/utf.t
--- perl/t/comp/utf.t#5~29056~  2006-10-19 13:47:53.000000000 -0700
+++ perl/t/comp/utf.t   2008-08-08 02:59:45.000000000 -0700
@@ -26,12 +26,12 @@
 
 sub test {
     my ($enc, $tag, $bom) = @_;
-    open(UTF_PL, ">:raw:encoding($enc)", "utf.pl")
+    open(UTF_PL, ">:raw:encoding($enc)", "utf$$.pl")
        or die "utf.pl($enc,$tag,$bom): $!";
     print UTF_PL $BOM if $bom;
     print UTF_PL "$tag\n";
     close(UTF_PL);
-    my $got = do "./utf.pl";
+    my $got = do "./utf$$.pl";
     is($got, $tag);
 }
 
@@ -53,5 +53,5 @@
 test("utf16be",    12345, 0);
 
 END {
-    1 while unlink "utf.pl";
+    1 while unlink "utf$$.pl";
 }

==== //depot/perl/t/run/cloexec.t#5 (text) ====
Index: perl/t/run/cloexec.t
--- perl/t/run/cloexec.t#4~31438~       2007-06-21 01:26:18.000000000 -0700
+++ perl/t/run/cloexec.t        2008-08-08 02:59:45.000000000 -0700
@@ -67,9 +67,9 @@
 my $Perl = which_perl();
 my $quote = $Is_VMS || $Is_Win32 ? '"' : "'";
 
-my $tmperr             = 'cloexece.tmp';
-my $tmpfile1           = 'cloexec1.tmp';
-my $tmpfile2           = 'cloexec2.tmp';
+my $tmperr             = tempfile();
+my $tmpfile1           = tempfile();
+my $tmpfile2           = tempfile();
 my $tmpfile1_contents  = "tmpfile1 line 1\ntmpfile1 line 2\n";
 my $tmpfile2_contents  = "tmpfile2 line 1\ntmpfile2 line 2\n";
 make_tmp_file($tmpfile1, $tmpfile1_contents);
@@ -164,9 +164,3 @@
 test_inherited($parentfd1);
 close FHPARENT1 or die "close '$tmpfile1': $!";
 close FHPARENT2 or die "close '$tmpfile2': $!";
-
-END {
-    defined $tmperr   and unlink($tmperr);
-    defined $tmpfile1 and unlink($tmpfile1);
-    defined $tmpfile2 and unlink($tmpfile2);
-}

==== //depot/perl/t/run/runenv.t#13 (text) ====
Index: perl/t/run/runenv.t
--- perl/t/run/runenv.t#12~34183~       2008-08-08 02:24:39.000000000 -0700
+++ perl/t/run/runenv.t 2008-08-08 02:59:45.000000000 -0700
@@ -17,8 +17,8 @@
 
 plan tests => 17;
 
-my $STDOUT = './results-0';
-my $STDERR = './results-1';
+my $STDOUT = tempfile();
+my $STDERR = tempfile();
 my $PERL = $ENV{PERL} || './perl';
 my $FAILURE_CODE = 119;
 

==== //depot/perl/t/run/switchC.t#7 (text) ====
Index: perl/t/run/switchC.t
--- perl/t/run/switchC.t#6~29056~       2006-10-19 13:47:53.000000000 -0700
+++ perl/t/run/switchC.t        2008-08-08 02:59:45.000000000 -0700
@@ -17,8 +17,7 @@
 
 my $r;
 
-my @tmpfiles = ();
-END { unlink @tmpfiles }
+my $tmpfile = tempfile();
 
 my $b = pack("C*", unpack("U0C*", pack("U",256)));
 
@@ -45,14 +44,12 @@
 like( $r, qr/^$b(?:\r?\n)?$/s, '-CE: UTF-8 stderr' );
 
 $r = runperl( switches => [ '-Co', '-w' ],
-             prog     => 'open(F, q(>out)); print F chr(256); close F',
+             prog     => "open(F, q(>$tmpfile)); print F chr(256); close F",
               stderr   => 1 );
 like( $r, qr/^$/s, '-Co: auto-UTF-8 open for output' );
 
-push @tmpfiles, "out";
-
 $r = runperl( switches => [ '-Ci', '-w' ],
-             prog     => 'open(F, q(<out)); print ord(<F>); close F',
+             prog     => "open(F, q(<$tmpfile)); print ord(<F>); close F",
               stderr   => 1 );
 like( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input' );
 

==== //depot/perl/t/run/switchF1.t#2 (text) ====
Index: perl/t/run/switchF1.t
--- perl/t/run/switchF1.t#1~23730~      2005-01-02 14:49:49.000000000 -0800
+++ perl/t/run/switchF1.t       2008-08-08 02:59:45.000000000 -0700
@@ -1,7 +1,7 @@
 #!perl -w
 print "1..5\n";
 
-my $file = "F-Pathological.pl";
+my $file = "Run_switchF1.pl";
 
 open F, ">$file" or die "Open $file: $!";
 

==== //depot/perl/t/run/switchd.t#7 (text) ====
Index: perl/t/run/switchd.t
--- perl/t/run/switchd.t#6~30059~       2007-01-29 08:54:38.000000000 -0800
+++ perl/t/run/switchd.t        2008-08-08 02:59:45.000000000 -0700
@@ -12,10 +12,8 @@
 plan(tests => 2);
 
 my $r;
-my @tmpfiles = ();
-END { unlink @tmpfiles }
 
-my $filename = 'swdtest.tmp';
+my $filename = tempfile();
 SKIP: {
        open my $f, ">$filename"
            or skip( "Can't write temp file $filename: $!" );
@@ -31,19 +29,18 @@
 Foo::foo(3);
 __SWDTEST__
     close $f;
-    push @tmpfiles, $filename;
     $| = 1; # Unbufferize.
     $r = runperl(
                 switches => [ '-Ilib', '-f', '-d:switchd' ],
                 progfile => $filename,
                 args => ['3'],
                );
-    like($r, 
qr/^sub<Devel::switchd::import>;import<Devel::switchd>;DB<main,swdtest.tmp,9>;sub<Foo::foo>;DB<Foo,swdtest.tmp,5>;DB<Foo,swdtest.tmp,6>;DB<Foo,swdtest.tmp,6>;sub<Bar::bar>;DB<Bar,swdtest.tmp,2>;sub<Bar::bar>;DB<Bar,swdtest.tmp,2>;sub<Bar::bar>;DB<Bar,swdtest.tmp,2>;$/);
+    like($r, 
qr/^sub<Devel::switchd::import>;import<Devel::switchd>;DB<main,$::tempfile_regexp,9>;sub<Foo::foo>;DB<Foo,$::tempfile_regexp,5>;DB<Foo,$::tempfile_regexp,6>;DB<Foo,$::tempfile_regexp,6>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;$/);
     $r = runperl(
                 switches => [ '-Ilib', '-f', '-d:switchd=a,42' ],
                 progfile => $filename,
                 args => ['4'],
                );
-    like($r, qr/^sub<Devel::switchd::import>;import<Devel::switchd a 
42>;DB<main,swdtest.tmp,9>;sub<Foo::foo>;DB<Foo,swdtest.tmp,5>;DB<Foo,swdtest.tmp,6>;DB<Foo,swdtest.tmp,6>;sub<Bar::bar>;DB<Bar,swdtest.tmp,2>;sub<Bar::bar>;DB<Bar,swdtest.tmp,2>;sub<Bar::bar>;DB<Bar,swdtest.tmp,2>;$/);
+    like($r, qr/^sub<Devel::switchd::import>;import<Devel::switchd a 
42>;DB<main,$::tempfile_regexp,9>;sub<Foo::foo>;DB<Foo,$::tempfile_regexp,5>;DB<Foo,$::tempfile_regexp,6>;DB<Foo,$::tempfile_regexp,6>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;$/);
 }
 

==== //depot/perl/t/run/switches.t#27 (text) ====
Index: perl/t/run/switches.t
--- perl/t/run/switches.t#26~34040~     2008-06-10 02:47:41.000000000 -0700
+++ perl/t/run/switches.t       2008-08-08 02:59:45.000000000 -0700
@@ -76,7 +76,7 @@
 
 # Tests for -c
 
-my $filename = 'swctest.tmp';
+my $filename = tempfile();
 SKIP: {
     local $TODO = '';   # this one works on VMS
 
@@ -105,7 +105,6 @@
        && $r !~ /\bblock 5\b/,
        '-c'
     );
-    push @tmpfiles, $filename;
 }
 
 # Tests for -l
@@ -125,7 +124,7 @@
 );
 is( $r, '21-', '-s switch parsing' );
 
-$filename = 'swstest.tmp';
+$filename = tempfile();
 SKIP: {
     open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
     print $f <<'SWTEST';
@@ -138,11 +137,10 @@
        args        => [ '-x=foo -y' ],
     );
     is( $r, 'foo1', '-s on the shebang line' );
-    push @tmpfiles, $filename;
 }
 
 # Bug ID 20011106.084
-$filename = 'swsntest.tmp';
+$filename = tempfile();
 SKIP: {
     open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
     print $f <<'SWTEST';
@@ -155,32 +153,32 @@
        args        => [ '-x=foo' ],
     );
     is( $r, 'foo', '-sn on the shebang line' );
-    push @tmpfiles, $filename;
 }
 
 # Tests for -m and -M
 
-$filename = 'swtest.pm';
+my $package = tempfile();
+$filename = "$package.pm";
 SKIP: {
     open my $f, ">$filename" or skip( "Can't write temp file $filename: $!",4 
);
-    print $f <<'SWTESTPM';
-package swtest;
-sub import { print map "<$_>", @_ }
+    print $f <<"SWTESTPM";
+package $package;
+sub import { print map "<\$_>", [EMAIL PROTECTED] }
 1;
 SWTESTPM
     close $f or die "Could not close: $!";
     $r = runperl(
-       switches    => [ '-Mswtest' ],
+       switches    => [ "-M$package" ],
        prog        => '1',
     );
-    is( $r, '<swtest>', '-M' );
+    is( $r, "<$package>", '-M' );
     $r = runperl(
-       switches    => [ '-Mswtest=foo' ],
+       switches    => [ "-M$package=foo" ],
        prog        => '1',
     );
-    is( $r, '<swtest><foo>', '-M with import parameter' );
+    is( $r, "<$package><foo>", '-M with import parameter' );
     $r = runperl(
-       switches    => [ '-mswtest' ],
+       switches    => [ "-m$package" ],
        prog        => '1',
     );
 
@@ -189,16 +187,16 @@
         is( $r, '', '-m' );
     }
     $r = runperl(
-       switches    => [ '-mswtest=foo,bar' ],
+       switches    => [ "-m$package=foo,bar" ],
        prog        => '1',
     );
-    is( $r, '<swtest><foo><bar>', '-m with import parameters' );
+    is( $r, "<$package><foo><bar>", '-m with import parameters' );
     push @tmpfiles, $filename;
 
     is( runperl( switches => [ '-MTie::Hash' ], stderr => 1, prog => 1 ),
          '', "-MFoo::Bar allowed" );
 
-    like( runperl( switches => [ '-M:swtest' ], stderr => 1,
+    like( runperl( switches => [ "-M:$package" ], stderr => 1,
                   prog => 'die "oops"' ),
          qr/Invalid module name [\w:]+ with -M option\b/,
           "-M:Foo not allowed" );

==== //depot/perl/t/run/switcht.t#5 (text) ====
Index: perl/t/run/switcht.t
--- perl/t/run/switcht.t#4~18453~       2003-01-06 12:31:43.000000000 -0800
+++ perl/t/run/switcht.t        2008-08-08 02:59:45.000000000 -0700
@@ -29,8 +29,9 @@
 }
 
 # Get ourselves a tainted variable.
+my $filename = tempfile();
 $file = $0;
-$file =~ s/.*/some.tmp/;
+$file =~ s/.*/$filename/;
 ok( open(FILE, ">$file"),   'open >' ) or DIE $!;
 print FILE "Stuff\n";
 close FILE;
End of Patch.

Reply via email to