1#!./perl 2use strict; 3chdir 't' if -d 't'; 4require './test.pl'; 5 6$^I = 'bak.*'; 7 8# Modified from the original inplace.t to test adding prefixes 9 10plan( tests => 2 ); 11 12my @tfiles = (tempfile(), tempfile(), tempfile()); 13my @tfiles_bak = map "bak.$_", @tfiles; 14 15END { unlink_all(@tfiles_bak); } 16 17for my $file (@tfiles) { 18 runperl( prog => 'print qq(foo\n);', 19 args => ['>', $file] ); 20} 21 22@ARGV = @tfiles; 23 24while (<>) { 25 s/foo/bar/; 26} 27continue { 28 print; 29} 30 31is ( runperl( prog => 'print<>;', args => \@tfiles ), 32 "bar\nbar\nbar\n", 33 "file contents properly replaced" ); 34 35is ( runperl( prog => 'print<>;', args => \@tfiles_bak ), 36 "foo\nfoo\nfoo\n", 37 "backup file contents stay the same" ); 38 39