-
-
Notifications
You must be signed in to change notification settings - Fork 372
/
03-errors.t
93 lines (77 loc) · 3.28 KB
/
03-errors.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use lib <t/packages/>;
use Test;
use Test::Helpers;
plan 10;
subtest '.map does not explode in optimizer' => {
plan 3;
throws-like 「^4 .map: {}」, Exception,
:message{.contains: 'Cannot map a Range to a Hash.'}, 'hash';
throws-like 「^4 .map: 42」, X::Multi::NoMatch, 'Int';
sub foo ($x) { $x+2};
is-deeply ^4 .map(&foo), (2, 3, 4, 5).Seq, 'subroutine';
}
throws-like 「(lazy <a b c>).nodemap: {;}」, X::Cannot::Lazy, :action<nodemap>,
'nodemap mentions right action when throwing on lazies';
# GH#1314
throws-like 「'x'.substr: /x/, 'x'」, Exception,
message => /「did you mean 'subst'」/,
'using substr instead of subst';
# RT #132846
throws-like 「sprintf "%d", class Foo {}.new」,
X::Str::Sprintf::Directives::BadType, :gist(/«line\s+\d+$$/),
'errors from sprintf include location of error';
# https://github.com/rakudo/rakudo/issues/1560
subtest 'subsets get named in typecheck errors' => {
plan 4;
my subset MeowMix of Int where .so;
throws-like { -> MeowMix {}("x") },
X::TypeCheck::Binding::Parameter, :message{.contains: 'MeowMix'},
'type only, with wrong type given';
throws-like { -> MeowMix $ where .self {}("x") },
X::TypeCheck::Binding::Parameter, :message{.contains: 'MeowMix'},
'type + where, with wrong type given';
throws-like { -> MeowMix {}(0) },
X::TypeCheck::Binding::Parameter, :message{.contains: 'MeowMix'},
'type only, with failing constraint';
throws-like { -> MeowMix $ where .self {}(0) },
X::TypeCheck::Binding::Parameter, :message{.contains: 'MeowMix'},
'type + where, with failing constraint';
}
subtest 'like/unlike failures give useful diagnostics' => {
plan 2;
is-run 「use Test; plan 1; like 42, /43/」,
:1exitcode, :out(*), :err{.contains: 'expected a match with'},
'`like` says it wanted a match, not just "expected"';
is-run 「use Test; plan 1; unlike 42, /42/」,
:1exitcode, :out(*), :err{.contains: 'expected no match with'},
'`unlike` says it wanted no match, not just "expected"';
}
# https://github.com/rakudo/rakudo/issues/1644
throws-like 「Lock.protect: %()」, X::Multi::NoMatch,
'Lock.protect with wrong args gives sane error';
throws-like 「Lock::Async.protect: %()」, X::Multi::NoMatch,
'Lock::Async.protect with wrong args gives sane error';
# https://github.com/rakudo/rakudo/issues/1699
throws-like {
with Proc::Async.new: :out, :!err, $*EXECUTABLE, '-e', '' {
.bind-stdout: IO::Handle.new;
.start;
}
}, Exception, :message{.contains: 'handle not open'},
'trying to bind Proc::Async to unopened handle gives useful error';
# RT #132238
subtest 'unclosed hash quote index operator <> message' => {
plan 2;
throws-like "\n\nsay \$<\n\n", X::Comp::AdHoc,
'good error message for unclosed <> hash operator',
message => /:i[:s unable to parse<|w>]
.* <|w>find\s+\'\>\'
.* [:s at line 3]
/;
todo 'RT #132238 - remove "expecting any of:"';
throws-like "say \$<", X::Comp::AdHoc,
'better and shorter error message for unclosed <> hash operator',
# somewhat tricky does not contain "expecting any of"
gist => /^ [. <!before [:s expecting any of:]>]* $ /;
}
# vim: ft=perl6 expandtab sw=4