/
dollar_bang.t
49 lines (36 loc) 路 980 Bytes
/
dollar_bang.t
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
use v6;
use Test;
plan 8;
=begin desc
This test tests the C<$!> builtin.
=end desc
# L<S04/"Exceptions"/"A bare die/fail takes $! as the default argument.">
#?rakudo 3 skip 'unimpl $!'
eval '&nonexisting_subroutine()';
ok $!, 'Calling a nonexisting subroutine sets $!';
undefine $!;
try { nonexisting_subroutine; };
ok $!, 'Calling a nonexisting subroutine sets $!';
undefine $!;
my $called;
sub foo(Str $s) { return $called++ };
my @a;
try { foo(@a,@a) };
ok $!, 'Calling a subroutine with a nonmatching signature sets $!';
ok !$called, 'The subroutine also was not called';
#?rakudo skip 'unimpl $!'
undefine $!;
try { 1 / 0 };
ok $!, 'Dividing one by zero sets $!';
sub incr ( $a is rw ) { $a++ };
undefine $!;
try { incr(19) };
ok $!, 'Modifying a constant sets $!';
try {
try {
die 'qwerty';
}
ok ~($!) ~~ /qwerty/, 'die sets $! properly';
die; # use the default argument
}
ok ~($!) ~~ /qwerty/, 'die without argument uses $! properly';