| 12
 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
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 
 | #!/usr/bin/perl -w
use strict;
use warnings;
use Test2::Bundle::Extended;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test::MockFile qw< nostrict >;
{
    like(
        dies { myread() },
        qr/Missing file argument/,
        'missing file argument'
    );
    my $path      = q[/tmp/somewhere];
    my $mock_file = Test::MockFile->file($path);
    like(
        dies { myread($path) },
        qr/Failed to open file/,
        'missing file'
    );
    $mock_file->touch;
    note "empty file";
    is myread($path), [], "empty file";
    $mock_file->contents( <<'EOS' );
Some content
for your eyes only
EOS
    ok !-z $path, "file is not empty";
    ok $mock_file->contents;
    my $out = myread($path);
    is $out, [ split( /\n/, $mock_file->contents ) ], "$path file should not be empty (on second read)"
      or diag explain $out;
}
done_testing;
sub myread {
    my ($script) = @_;
    die q[Missing file argument] unless defined $script;
    my @lines;
    my $fh;
    #diag explain \%Test::MockFile::files_being_mocked;
    open( $fh, '<', $script ) or die qq[Failed to open file: $!];
    while ( my $line = readline $fh ) {
        chomp $line;
        push @lines, $line;
    }
    return \@lines;
}
1;
 |