Change 20973 by [EMAIL PROTECTED] on 2003/08/31 15:34:43

        Add test for -i.

Affected files ...

... //depot/perl/MANIFEST#1085 edit
... //depot/perl/t/run/switches.t#12 edit

Differences ...

==== //depot/perl/MANIFEST#1085 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST#1084~20972~   Sun Aug 31 08:12:10 2003
+++ perl/MANIFEST       Sun Aug 31 08:34:43 2003
@@ -2843,7 +2843,7 @@
 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

==== //depot/perl/t/run/switches.t#12 (text) ====
Index: perl/t/run/switches.t
--- perl/t/run/switches.t#11~20972~     Sun Aug 31 08:12:10 2003
+++ perl/t/run/switches.t       Sun Aug 31 08:34:43 2003
@@ -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 @@
 
 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 
@@ -244,4 +245,39 @@
          qr/\QUnrecognized switch: -z  (-h will show valid options)./,
           '-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");
 }
End of Patch.

Reply via email to