This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
As well as PERL5LIB, remove PERLLIB and PERL5OPT from the environment.
[perl5.git] / t / io / inplace.t
1 #!./perl
2 use strict;
3 require './test.pl';
4
5 $^I = $^O eq 'VMS' ? '_bak' : '.bak';
6
7 plan( tests => 2 );
8
9 my @tfiles     = (tempfile(), tempfile(), tempfile());
10 my @tfiles_bak = map "$_$^I", @tfiles;
11
12 END { unlink_all(@tfiles_bak); }
13
14 for my $file (@tfiles) {
15     runperl( prog => 'print qq(foo\n);', 
16              args => ['>', $file] );
17 }
18
19 @ARGV = @tfiles;
20
21 while (<>) {
22     s/foo/bar/;
23 }
24 continue {
25     print;
26 }
27
28 is ( runperl( prog => 'print<>;', args => \@tfiles ), 
29      "bar\nbar\nbar\n", 
30      "file contents properly replaced" );
31
32 is ( runperl( prog => 'print<>;', args => \@tfiles_bak ), 
33      "foo\nfoo\nfoo\n", 
34      "backup file contents stay the same" );
35