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