Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test default open mode, including failure to open nonexistent files
  • Loading branch information
cygx committed Dec 8, 2015
1 parent ad7263a commit b478eae
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion S32-io/open.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 23;
plan 27;

my \PATH = 't-S32-io-open.tmp';
my \PATH-RX = rx/'t-S32-io-open.tmp'/;
Expand Down Expand Up @@ -147,4 +147,25 @@ LEAVE unlink PATH;
'cannot use :rx to open existing file', message => PATH-RX;
}

# test default mode
{ unlink PATH;
my $fh;

ok open(PATH) ~~ Failure, 'opening nonexistent file in default mode fails';

$fh = open PATH, :w;
$fh.print('onions are tasty');
$fh.close;

$fh = open PATH;
ok defined($fh), 'can open existing file in default mode';

ok $fh.get eq 'onions are tasty', 'can read from file in default mode';

throws-like '$fh.print("42")', Exception,
'cannot write to file in default mode';

$fh.close;
}

# vim: ft=perl6

0 comments on commit b478eae

Please sign in to comment.