From: Jarkko Hietaniemi Date: Sun, 31 Aug 2003 15:34:43 +0000 (+0000) Subject: Add test for -i. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=feafb1eb594f32e8a3f987644204016d17007c35;p=p5sagit%2Fp5-mst-13.2.git Add test for -i. p4raw-id: //depot/perl@20973 --- diff --git a/MANIFEST b/MANIFEST index c074617..ac991f7 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2843,7 +2843,7 @@ t/run/switcha.t Test the -a switch t/run/switch_A.t Test the -A switch t/run/switchC.t Test the -C switch t/run/switchd.t Test the -d switch -t/run/switches.t Tests for the other switches (-0, -l, -c, -s, -M, -m, -V, -v, -h, -z) +t/run/switches.t Tests for the other switches (-0, -l, -c, -s, -M, -m, -V, -v, -h, -z, -i) t/run/switchF.t Test the -F switch t/run/switchI.t Test the -I switch t/run/switchn.t Test the -n switch diff --git a/t/run/switches.t b/t/run/switches.t index 0aff31c..20d8d69 100644 --- a/t/run/switches.t +++ b/t/run/switches.t @@ -1,6 +1,7 @@ #!./perl -w -# Tests for the command-line switches -0, -c, -l, -s, -m, -M, -V, -v, -h, -z +# Tests for the command-line switches: +# -0, -c, -l, -s, -m, -M, -V, -v, -h, -z, -i # Some switches have their own tests, see MANIFEST. BEGIN { @@ -10,7 +11,7 @@ BEGIN { require "./test.pl"; -plan(tests => 24); +plan(tests => 26); # due to a bug in VMS's piping which makes it impossible for runperl() # to emulate echo -n (ie. stdin always winds up with a newline), these @@ -245,3 +246,38 @@ SWTESTPM '-z correctly unknown' ); } + +# Tests for -i + +{ + local $TODO = ''; # these ones should work on VMS + + sub do_i_unlink { 1 while unlink("file", "file.bak") } + + open(FILE, ">file") or die "$0: Failed to create 'file': $!"; + print FILE <<__EOF__; +foo yada dada +bada foo bing +king kong foo +__EOF__ + close FILE; + + END { do_i_unlink() } + + runperl( switches => ['-pi.bak'], prog => 's/foo/bar/', args => ['file'] ); + + open(FILE, "file") or die "$0: Failed to open 'file': $!"; + chomp(my @file = ); + close FILE; + + open(BAK, "file.bak") or die "$0: Failed to open 'file': $!"; + chomp(my @bak = ); + close BAK; + + is(join(":", @file), + "bar yada dada:bada bar bing:king kong bar", + "-i new file"); + is(join(":", @bak), + "foo yada dada:bada foo bing:king kong foo", + "-i backup file"); +}