summaryrefslogtreecommitdiff
path: root/t/run
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-08-31 15:34:43 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-08-31 15:34:43 +0000
commitfeafb1eb594f32e8a3f987644204016d17007c35 (patch)
tree6a87ff2d07a7a87cab2619f684427d6509e00e40 /t/run
parentb8e3af44af1f06db397d2edf1cfbc2035e8624c1 (diff)
downloadperl-feafb1eb594f32e8a3f987644204016d17007c35.tar.gz
Add test for -i.
p4raw-id: //depot/perl@20973
Diffstat (limited to 't/run')
-rw-r--r--t/run/switches.t40
1 files changed, 38 insertions, 2 deletions
diff --git a/t/run/switches.t b/t/run/switches.t
index 0aff31cfbc..20d8d69f21 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 = <FILE>);
+ close FILE;
+
+ open(BAK, "file.bak") or die "$0: Failed to open 'file': $!";
+ chomp(my @bak = <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");
+}