summaryrefslogtreecommitdiff
path: root/t/io/iprefix.t
blob: f011eba427c7f069b90c1fdc1c6494658a00fc8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!./perl
use strict;
chdir 't' if -d 't';
require './test.pl';

$^I = 'bak.*';

# Modified from the original inplace.t to test adding prefixes

plan( tests => 2 );

my @tfiles     = (tempfile(), tempfile(), tempfile());
my @tfiles_bak = map "bak.$_", @tfiles;

END { unlink_all(@tfiles_bak); }

for my $file (@tfiles) {
    runperl( prog => 'print qq(foo\n);', 
             args => ['>', $file] );
}

@ARGV = @tfiles;

while (<>) {
    s/foo/bar/;
}
continue {
    print;
}

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" );