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 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
|
use strict; use warnings;
use lib -e 't' ? 't' : 'test';
use Test::More;
use IO::All;
use IO_All_Test;
plan((lc($^O) eq 'mswin32' and defined $ENV{PERL5_CPANPLUS_IS_RUNNING})
? (skip_all => "CPANPLUS/MSWin32 breaks this")
: ($] < 5.008003)
? (skip_all => 'Broken on older perls')
: (tests => 4)
);
{
my $log = io->file(o_dir() . "/myappend.txt")->mode('>>')->open();
$log->print("Hello World!\n");
$log->close();
}
{
# TEST
ok (scalar(-f o_dir() . "/myappend.txt"), "myappend.txt exists.");
my $contents = _slurp(o_dir() . "/myappend.txt");
# TEST
is ($contents, "Hello World!\n", "contents of the file are OK.");
}
{
my $log = io->file(o_dir() . "/myappend.txt")->mode('>>')->open();
$log->print("Message No. 2!\n");
$log->close();
}
{
# TEST
ok (scalar(-f o_dir() . "/myappend.txt"), "myappend.txt exists.");
my $contents = _slurp(o_dir() . "/myappend.txt");
# TEST
is ($contents, "Hello World!\nMessage No. 2!\n",
"Second append was ok.");
}
sub _slurp
{
my $filename = shift;
open my $in, "<", $filename
or die "Cannot open '$filename' for slurping - $!";
local $/;
my $contents = <$in>;
close($in);
return $contents;
}
del_output_dir();
|