Skip to content

Commit f95307c

Browse files
committed
Added tests for spurt
1 parent 3fe5dba commit f95307c

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

S32-io/spurt.t

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
use v6;
2+
use Test;
3+
plan 12;
4+
# L<S32::IO/Functions/spurt>
5+
6+
my $path = "tempfile-spurt-test";
7+
8+
# Tests for:
9+
# multi spurt (Str $filename,
10+
# Buf $contents,
11+
# Bool :append = False,
12+
# Bool :$createonly = False)
13+
#
14+
# and
15+
#
16+
# multi spurt (Str $filename,
17+
# Str $contents,
18+
# Str :$enc = $?ENC,
19+
# Bool :append = False,
20+
# Bool :$createonly = False,
21+
#?niecza skip "does not like Buf.new"
22+
{
23+
my $buf = Buf.new(0xBE, 0xEF, 0xC0, 0xDE);
24+
25+
spurt($path, $buf);
26+
is slurp($path, :bin), $buf, "spurting Buf ok";
27+
28+
spurt $path, "24", :enc("ASCII");
29+
is slurp($path), "24", "spurt to IO with enc";
30+
31+
spurt $path, $buf;
32+
spurt $path, $buf, :append;
33+
is slurp($path, :bin), ($buf ~ $buf), "spurting Buf with append";
34+
unlink $path;
35+
36+
lives_ok { spurt $path, $buf, :createonly }, "createonly creates file";
37+
ok $path.IO.e, "file was created";
38+
dies_ok { spurt $path, :createonly }, "createonly fails if file exists";
39+
unlink $path;
40+
}
41+
42+
# Tests for:
43+
# multi spurt (IO $fh,
44+
# Str $contents,
45+
# Str :$enc = $?ENC,
46+
# Bool :append = False,
47+
# Bool :$createonly = False)
48+
# and
49+
#
50+
# multi spurt (IO $fh,
51+
# Buf $contents,
52+
# Bool :append = False,
53+
# Bool :$createonly = False)
54+
#?rakudo skip "No matching signature"
55+
{
56+
spurt $path.IO, "42";
57+
is slurp($path), "42", "spurt to IO";
58+
59+
#?niecza skip "Excess arguments to spurt, unused named enc"
60+
{
61+
spurt $path.IO, "24", :enc("ASCII");
62+
is slurp($path), "24", "spurt to IO with enc";
63+
}
64+
65+
#?niecza skip "Excess arguments to spurt, unused named append"
66+
{
67+
spurt $path.IO, "42";
68+
spurt $path.IO, "24", :append;
69+
is slurp($path), "4224", "spurt to IO with append";
70+
}
71+
unlink $path;
72+
73+
#?niecza 2 skip "Excess arguments to spurt, unused named createonly"
74+
lives_ok { spurt $path.IO, "", :createonly }
75+
ok $path.IO.e, "file was created";
76+
dies_ok { spurt $path.IO, "", :createonly }
77+
unlink $path;
78+
}
79+
80+
done;
81+
82+
CATCH {
83+
unlink $path;
84+
}
85+
86+
if $path.IO.e {
87+
say "Warn: '$path shouldn't exist";
88+
unlink $path;
89+
}

0 commit comments

Comments
 (0)