use test.pl's tempfile().
p4raw-id: //depot/perl@34184
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
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>) {
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);
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`;
{
# 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;
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);
}
test("utf16be", 12345, 0);
END {
- 1 while unlink "utf.pl";
+ 1 while unlink "utf$$.pl";
}
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);
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);
-}
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;
my $r;
-my @tmpfiles = ();
-END { unlink @tmpfiles }
+my $tmpfile = tempfile();
my $b = pack("C*", unpack("U0C*", pack("U",256)));
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' );
#!perl -w
print "1..5\n";
-my $file = "F-Pathological.pl";
+my $file = "Run_switchF1.pl";
open F, ">$file" or die "Open $file: $!";
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: $!" );
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>;$/);
}
# Tests for -c
-my $filename = 'swctest.tmp';
+my $filename = tempfile();
SKIP: {
local $TODO = ''; # this one works on VMS
&& $r !~ /\bblock 5\b/,
'-c'
);
- push @tmpfiles, $filename;
}
# Tests for -l
);
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';
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';
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 "<\$_>", \@_ }
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',
);
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" );
}
# 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;