|
1 | 1 | use v6;
|
2 | 2 | use Test;
|
3 |
| -plan 12; |
| 3 | +#plan 22; |
| 4 | +plan *; |
| 5 | + |
4 | 6 | # L<S32::IO/Functions/spurt>
|
5 | 7 |
|
6 | 8 | my $path = "tempfile-spurt-test";
|
7 | 9 |
|
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; |
| 10 | +# filename as str tests |
| 11 | +all-tests({ $path }); |
35 | 12 |
|
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; |
| 13 | +# filename as IO tests |
| 14 | +#?rakudo skip "does not support IO::Handle" |
| 15 | +{ |
| 16 | + all-tests({ $path.IO }); |
40 | 17 | }
|
41 | 18 |
|
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"; |
| 19 | +sub all-tests(Callable $handle) { |
| 20 | + my $buf = Buf.new(0xBE, 0xEF, 0xC0, 0xDE); |
| 21 | + my $txt = "42"; |
| 22 | + |
| 23 | + #?niecza skip ":bin option for slurp fails" |
| 24 | + { |
| 25 | + spurt $handle(), $buf; |
| 26 | + is slurp($path, :bin), $buf, "spurting Buf ok"; |
| 27 | + } |
| 28 | + spurt $handle(), $txt; |
| 29 | + is slurp($path), $txt, "spurting txt ok"; |
58 | 30 |
|
59 | 31 | #?niecza skip "Excess arguments to spurt, unused named enc"
|
60 | 32 | {
|
61 |
| - spurt $path.IO, "24", :enc("ASCII"); |
62 |
| - is slurp($path), "24", "spurt to IO with enc"; |
| 33 | + spurt $handle(), $txt, :enc("ASCII"); |
| 34 | + is slurp($path), $txt, "spurt with enc"; |
63 | 35 | }
|
64 |
| - |
| 36 | + |
| 37 | + #?niecza skip "Excess arguments to spurt, unused named append" |
| 38 | + { |
| 39 | + spurt $handle(), $buf; |
| 40 | + spurt $handle(), $buf, :append; |
| 41 | + is slurp($path, :bin), ($buf ~ $buf), "spurting Buf with append"; |
| 42 | + } |
| 43 | + |
65 | 44 | #?niecza skip "Excess arguments to spurt, unused named append"
|
66 | 45 | {
|
67 |
| - spurt $path.IO, "42"; |
68 |
| - spurt $path.IO, "24", :append; |
69 |
| - is slurp($path), "4224", "spurt to IO with append"; |
| 46 | + spurt $handle(), $txt; |
| 47 | + spurt $handle(), $txt, :append; |
| 48 | + is slurp($path), ($txt ~ $txt), "spurting txt with append"; |
70 | 49 | }
|
| 50 | + |
| 51 | + unlink $path; |
| 52 | + |
| 53 | + #?niecza skip "Excess arguments to spurt, unused named createonly" |
| 54 | + lives_ok { spurt $handle(), $buf, :createonly }, "createonly creates file with Buf"; |
| 55 | + #?niecza todo "" |
| 56 | + ok $path.IO.e, "file was created"; |
| 57 | + dies_ok { spurt $handle(), $txt, :createonly }, "createonly with Buf fails if file exists"; |
71 | 58 | unlink $path;
|
72 | 59 |
|
73 |
| - #?niecza 2 skip "Excess arguments to spurt, unused named createonly" |
74 |
| - lives_ok { spurt $path.IO, "", :createonly } |
| 60 | + #?niecza skip "Excess arguments to spurt, unused named createonly" |
| 61 | + lives_ok { spurt $handle(), $txt, :createonly }, "createonly with text creates file"; |
| 62 | + #?niecza todo "" |
75 | 63 | ok $path.IO.e, "file was created";
|
76 |
| - dies_ok { spurt $path.IO, "", :createonly } |
| 64 | + dies_ok { spurt $handle(), $txt, :createonly }, "createonly with text fails if file exists"; |
77 | 65 | unlink $path;
|
78 | 66 | }
|
79 | 67 |
|
|
0 commit comments