File: in-place.t

package info (click to toggle)
libio-all-perl 0.87-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 712 kB
  • sloc: perl: 2,017; makefile: 5
file content (37 lines) | stat: -rw-r--r-- 603 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 5;
use IO::All;
use File::Temp qw/tempdir/;

{
    my $tempdir = tempdir( CLEANUP => 1);

    my $f = sub { return io->catfile($tempdir, 'test.txt') };

    $f->()->print(<<'EOF');
#One
#Two
#Three
#Four
EOF

    # Test that the array overloading of IO::All can be modified to
    # produce new contents.
    foreach my $line (@{$f->()})
    {
        # TEST*4
        ok (($line =~ s{\A#}{}), 'Done substitution.');
    }

    # TEST
    is (scalar($f->()->slurp()), <<'EOF', 'File contents were modified.');
One
Two
Three
Four
EOF
}