Convert all unimaginative (ie race condition) temporary file names to
[p5sagit/p5-mst-13.2.git] / t / io / argv.t
index a602a02..d6c895d 100755 (executable)
@@ -5,9 +5,9 @@ BEGIN {
     @INC = '../lib';
 }
 
-require "./test.pl";
+BEGIN { require "./test.pl"; }
 
-plan(tests => 21);
+plan(tests => 23);
 
 use File::Spec;
 
@@ -38,6 +38,13 @@ is($x, "1a line\n2a line\n", '<> from two files');
     is($x, "foo\n", '   from just STDIN');
 }
 
+{
+    # 5.10 stopped autovivifying scalars in globs leading to a
+    # segfault when $ARGV is written to.
+    runperl( prog => 'eof()', stdin => "nothing\n" );
+    is( 0+$?, 0, q(eof() doesn't segfault) );
+}
+
 @ARGV = ('Io_argv1.tmp', 'Io_argv1.tmp', $devnull, 'Io_argv1.tmp');
 while (<>) {
     $y .= $. . $_;
@@ -56,7 +63,7 @@ close TRY or die "Could not close: $!";
 @ARGV = ('Io_argv1.tmp', 'Io_argv2.tmp');
 $^I = '_bak';   # not .bak which confuses VMS
 $/ = undef;
-my $i = 6;
+my $i = 7;
 while (<>) {
     s/^/ok $i\n/;
     ++$i;
@@ -72,13 +79,16 @@ undef $^I;
 
 ok( eof TRY );
 
-ok( eof NEVEROPENED,    'eof() true on unopened filehandle' );
+{
+    no warnings 'once';
+    ok( eof NEVEROPENED,    'eof() true on unopened filehandle' );
+}
 
 open STDIN, 'Io_argv1.tmp' or die $!;
 @ARGV = ();
 ok( !eof(),     'STDIN has something' );
 
-is( <>, "ok 6\n" );
+is( <>, "ok 7\n" );
 
 open STDIN, $devnull or die $!;
 @ARGV = ();
@@ -111,4 +121,22 @@ ok( eof(),      'eof() true after closing ARGV' );
     close F or die "Could not close: $!";
 }
 
-END { unlink 'Io_argv1.tmp', 'Io_argv1.tmp_bak', 'Io_argv2.tmp', 'Io_argv2.tmp_bak' }
+# This used to dump core
+fresh_perl_is( <<'**PROG**', "foobar", {}, "ARGV aliasing and eof()" ); 
+open OUT, ">Io_argv3.tmp" or die "Can't open temp file: $!";
+print OUT "foo";
+close OUT;
+open IN, "Io_argv3.tmp" or die "Can't open temp file: $!";
+*ARGV = *IN;
+while (<>) {
+    print;
+    print "bar" if eof();
+}
+close IN;
+unlink "Io_argv3.tmp";
+**PROG**
+
+END {
+    1 while unlink 'Io_argv1.tmp', 'Io_argv1.tmp_bak',
+       'Io_argv2.tmp', 'Io_argv2.tmp_bak', 'Io_argv3.tmp';
+}