From: Craig A. Berry Date: Sun, 11 Mar 2007 21:05:08 +0000 (+0000) Subject: Upgrade inplace.t and iprefix.t to use test.pl, avoiding a lot X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=99ec4a7efd4048a25e86d8a4220d20e87e436f1e;p=p5sagit%2Fp5-mst-13.2.git Upgrade inplace.t and iprefix.t to use test.pl, avoiding a lot of OS-specific shenanigans. p4raw-id: //depot/perl@30543 --- diff --git a/t/io/inplace.t b/t/io/inplace.t index 9b5be2a..a7a21e4 100755 --- a/t/io/inplace.t +++ b/t/io/inplace.t @@ -1,38 +1,23 @@ #!./perl +use strict; +require './test.pl'; $^I = $^O eq 'VMS' ? '_bak' : '.bak'; -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 'NetWare') { - $CAT = 'perl -e "print<>"'; - `perl -le "print 'foo'" > .a`; - `perl -le "print 'foo'" > .b`; - `perl -le "print 'foo'" > .c`; -} -elsif ($^O eq 'MacOS') { - $CAT = "$^X -e \"print<>\""; - `$^X -le "print 'foo'" > .a`; - `$^X -le "print 'foo'" > .b`; - `$^X -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 = ('.a','.b','.c'); +my @tfiles_bak = (".a$^I", ".b$^I", ".c$^I"); + +END { unlink_all('.a','.b','.c',".a$^I", ".b$^I", ".c$^I"); } + +for my $file (@tfiles) { + runperl( prog => 'print qq(foo\n);', + args => ['>', $file] ); } + +@ARGV = @tfiles; + while (<>) { s/foo/bar/; } @@ -40,7 +25,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 .a$^I .b$^I .c$^I` 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', ".a$^I", ".b$^I", ".c$^I"; diff --git a/t/io/iprefix.t b/t/io/iprefix.t index a845040..25dd69d 100755 --- a/t/io/iprefix.t +++ b/t/io/iprefix.t @@ -1,40 +1,25 @@ #!./perl +use strict; +require './test.pl'; $^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 'NetWare') { - $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`; -} -elsif ($^O eq 'MacOS') { - $CAT = "$^X -e \"print<>\""; - `$^X -le "print 'foo'" > .a`; - `$^X -le "print 'foo'" > .b`; - `$^X -le "print 'foo'" > .c`; -} -else { - $CAT = 'cat'; - `echo foo | tee .a .b .c`; +my @tfiles = ('.a','.b','.c'); +my @tfiles_bak = ('bak.a', 'bak.b', 'bak.c'); + +END { unlink_all('.a','.b','.c', 'bak.a', 'bak.b', 'bak.c'); } + +for my $file (@tfiles) { + runperl( prog => 'print qq(foo\n);', + args => ['>', $file] ); } + +@ARGV = @tfiles; + while (<>) { s/foo/bar/; } @@ -42,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';