This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix /test_bootstrap.t under -DPERL_NO_COW
[perl5.git] / t / io / iprefix.t
old mode 100755 (executable)
new mode 100644 (file)
index 10a5c5f..9e09ce0
@@ -1,28 +1,25 @@
 #!./perl
+use strict;
+require './test.pl';
 
-$^I = 'bak*';
+$^I = 'bak.*';
 
 # Modified from the original inplace.t to test adding prefixes
 
-print "1..2\n";
+plan( tests => 2 );
 
-@ARGV = ('.a','.b','.c');
-if ($^O eq 'MSWin32') {
-  $CAT = '.\perl -e "print<>"';
-  `.\\perl -le "print 'foo'" > .a`;
-  `.\\perl -le "print 'foo'" > .b`;
-  `.\\perl -le "print 'foo'" > .c`;
-}
-elsif ($^O eq 'VMS') {
-  $CAT = 'MCR []perl. -e "print<>"';
-  `MCR []perl. -le "print 'foo'" > ./.a`;
-  `MCR []perl. -le "print 'foo'" > ./.b`;
-  `MCR []perl. -le "print 'foo'" > ./.c`;
-}
-else {
-  $CAT = 'cat';
-  `echo foo | tee .a .b .c`;
+my @tfiles     = (tempfile(), tempfile(), tempfile());
+my @tfiles_bak = map "bak.$_", @tfiles;
+
+END { unlink_all(@tfiles_bak); }
+
+for my $file (@tfiles) {
+    runperl( prog => 'print qq(foo\n);', 
+             args => ['>', $file] );
 }
+
+@ARGV = @tfiles;
+
 while (<>) {
     s/foo/bar/;
 }
@@ -30,7 +27,11 @@ continue {
     print;
 }
 
-if (`$CAT .a .b .c` eq "bar\nbar\nbar\n") {print "ok 1\n";} else {print "not ok 1\n";}
-if (`$CAT bak.a bak.b bak.c` eq "foo\nfoo\nfoo\n") {print "ok 2\n";} else {print "not ok 2\n";}
+is ( runperl( prog => 'print<>;', args => \@tfiles ),
+     "bar\nbar\nbar\n", 
+     "file contents properly replaced" );
+
+is ( runperl( prog => 'print<>;', args => \@tfiles_bak ), 
+     "foo\nfoo\nfoo\n", 
+     "backup file contents stay the same" );
 
-unlink '.a', '.b', '.c', 'bak.a', 'bak.b', 'bak.c';