/
02-errors.t
286 lines (243 loc) · 10.4 KB
/
02-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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
use lib <t/packages/>;
use Test;
use Test::Helpers;
plan 35;
# RT #132295
is-run 「:2(1)」, :err{.contains: 「use 1.base(2) instead」}, :exitcode(* !== 0),
':2(1) suggests using 1.base(2)';
# RT #132291
throws-like { for [:a] X [:b] -> ($i, $j) { } },
Exception,
message => / '<anon>' /,
"anonymous subs get '<anon>' in arity error messages";
todo 'needs better error message';
throws-like {
sub l { IO::Socket::Async.listen: "localhost", 111390 }
react whenever l() {
whenever l() {} # try to listen on already open sock
}
}, X::AdHoc, message => /'something good'/;
# RT #132283
is-deeply class { has $.bar }.^methods».name.sort, <BUILDALL bar>,
'auto-generated methods present in .^methods';
# RT #124434
is-run 「Failure.new(Exception.new); Nil」, :1exitcode,
:err{ .contains: "Died with Exception" },
'Failure.new(Exception.new) does not segfault';
throws-like { (1, 2, 3)[42] = 21 }, X::Assignment::RO,
:message{ .contains: "List" & none "Str" },
'Trying to assign to immutable List element gives useful error';
# RT #126184
if $*DISTRO.is-win {
skip 「is-run() routine doesn't quite work right on Windows」;
}
else {
is-run 「
# !! NOTE !! Code's structure is important, to keep correct line number
my $supply = supply {
die 'pass' # line 4
}
react { # line 6
whenever $supply { }
}
」, :err{.contains: 'pass' & 'line 4' & 'line 6' }, :1exitcode,
'death in whenevered Supply referenced original location of throw';
}
subtest 'using wrong sigil on var suggests correct variable name' => {
plan 3;
throws-like 「my @foo; $foo[1] = 42」, X::Undeclared, :message(/'Did you mean' .+ '@foo'/),
'@array for $array';
throws-like 「my %foo; $foo<2> = 42」, X::Undeclared, :message(/'Did you mean' .+ '%foo'/),
'%hash for $hash';
throws-like 「my @foo; my %foo; $foo<2> = 42」, X::Undeclared,
:message(/'Did you mean' .+ [ '@foo' .+ '%foo' | '%foo' .+ '@foo' ]/),
'@foo and %foo for $foo, when both are declared';
}
# RT #131362
throws-like 「my $x; $x = 50; 42 = $x」, X::Assignment::RO,
:message{.contains: '42'},
'RO assignment indicates value of the thing being assigned into';
# RT #130446
is-run 「my %h = <a 1 b 2>; enum Bits (%h)」, :err{
.contains: 'No values supplied to enum'
& 'does %h need to be declared constant'
}, 'declaring enum with uninitialized hash warns about it';
{ # RT #125300
is-run 「=end MEOWS」, :err{ /«Pod»/ && .contains: '=begin MEOWS' },
:exitcode(*),
'error with `=end FOO` suggests Pod mistake and offers `=begin FOO`';
is-run 「=for」, :err(/«Pod»/), :exitcode(*),
'error for `=for` suggests it might be a Pod mistake';
}
{ # RT #125596
is-run 「say 1 if;」, :err{
1 == .comb: 'Whitespace required'
and 1 == .comb: 「keyword 'if'」
}, :1exitcode, '`say 1 if;` does not repeat error';
is-run 「say 1 unless;」, :err{
1 == .comb: 'Whitespace required'
and 1 == .comb: 「keyword 'unless'」
}, :1exitcode, '`say 1 unless;` does not repeat error';
}
# RT #126539
if $*DISTRO.is-win {
skip 「is-run() routine doesn't quite work right on Windows」;
}
else {
is-run 「
# We're lookin...
# for...
# line number
class MyInt is Any is Int { } # line 5
」, :err{.contains: ':5' }, :1exitcode,
'C3 linearization mentions line number';
}
#RT #115326
is-run '(:::[])', :err(/"No such symbol ':<>'"/), :1exitcode,
'no guts spillage with `(:::[])`';
# https://github.com/rakudo/rakudo/issues/1333
is-run 'use Test; cmp-ok 1, "!eqv", 2',
:out{.starts-with: 'not ok 1'},
:err{.contains: '!eqv' & 'pass it as a Callable' }, :1exitcode,
'cmp-ok with Str metaop comparator suggests a working alternative`';
# https://github.com/rakudo/rakudo/pull/1321
throws-like {
multi ambigu-arg-tester (Int) { say 'here' }
multi ambigu-arg-tester (Str) { say 'there' }
ambigu-arg-tester <42>
}, X::Multi::Ambiguous, :message{ .contains: 'ambigu-arg-tester' & 'IntStr' },
'an ambiguous call includes the arguments in the error message';
# RT #122907
throws-like { sprintf "%d" }, X::Str::Sprintf::Directives::Count,
:message('Your printf-style directives specify 1 argument, but no '
~ 'argument was supplied'),
'sprintf %d directive with find a corresponding argument throws';
{ # https://github.com/perl6/roast/commit/20fe657466
my int @arr;
throws-like { @arr[0] := my $a }, Exception,
:message('Cannot bind to a natively typed array'),
'error message when binding to natively typed array';
throws-like { @arr[0]:delete }, Exception,
:message('Cannot delete from a natively typed array'),
'error message when :deleting from natively typed array';
}
# https://github.com/rakudo/rakudo/issues/1346
subtest 'USAGE with subsets/where and variables with quotes' => {
plan 3;
sub uhas (\sig, Mu \c, \desc) {
is-run 「sub MAIN (」 ~ sig ~ 「) {}」,
:err{.contains: c}, :out(*), :exitcode(*), desc
}
subtest 'named params' => {
uhas 「UInt :$x!」, '<UInt>', 'mentions subset name';
uhas 「Int :$x! where 42」, '<Int where { ... }>',
'Type + where clauses shown sanely';
uhas 「UInt :$x! where 42」, '<UInt where { ... }>',
'subset + where clauses shown sanely';
}
subtest 'anon positional params' => {
uhas 「UInt $」, '<UInt>', 'mentions subset name';
uhas 「Int $ where 42」, '<Int where { ... }>',
'where clauses shown sanely';
uhas 「UInt $ where 42」, '<UInt where { ... }>',
'subset + where clauses shown sanely';
}
uhas 「$don't」, 「<don't>」,
'variable name does not get special quote treatment';
}
# RT #128039
{
throws-like { 'foo'.substr(5) }, X::OutOfRange,
:message(/'Start argument to substr' .+ 'should be in 0..3' .+ '*-5'/);
throws-like { ''.substr(1000) }, X::OutOfRange,
:message(/'should be in 0..0' .+ '*-1000'/);
}
for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
# RT #126379
is-run q[Supply.interval(1).tap(-> { say 'hi' }); sleep 3;],
:1exitcode, :err(/
'Unhandled exception in code scheduled on thread' .+
'Too many positionals' .+ 'expected 0 arguments but got 1'
/), '.tap block with incorrect signature must fail';
}
# RT #128050
is-run 「133742.print」, :compiler-args[<--rxtrace>], :out{ .ends-with: 133742 },
'--rxtrace does not crash';
# https://github.com/rakudo/rakudo/issues/1336
throws-like 「
multi z (@a, Int, :$x where 1) {}
multi z (@a, Str, :$x where 1) {}
my @a = 1..200; z(@a, <1>, :x[1..200])
」, X::Multi::NoMatch, :message{ .chars < 200 },
'X::Multi::NoMatch does not dump entire contents of variables';
# RT #132353
throws-like 「Set.new(1..300)<42> = 42」,
X::Assignment::RO, :message{ .chars < 100 },
'X::Assignment::RO does not dump entire contents of variables';
# RT #127051
subtest 'cannot use Int type object as an operand' => {
plan 14;
throws-like 「(1/1)+Int」,
X::Parameter::InvalidConcreteness,
'A Rational instance cannot be added by an Int type object';
throws-like 「Int+(1/1)」,
X::Parameter::InvalidConcreteness,
'An Int type object cannot be added by a Rational instance';
throws-like 「(1/1)-Int」,
X::Parameter::InvalidConcreteness,
'A Rational instance cannot be subtracted by an Int type object';
throws-like 「Int-(1/1)」,
X::Parameter::InvalidConcreteness,
'An Int type object cannot be subtracted by a Rational instance';
throws-like 「(1/1)*Int」,
X::Parameter::InvalidConcreteness,
'A Rational instance cannot be multiplied by an Int type object';
throws-like 「Int*(1/1)」,
X::Parameter::InvalidConcreteness,
'An Int type object cannot be multiplied by a Rational instance';
throws-like 「(1/1)/Int」,
X::Parameter::InvalidConcreteness,
'A Rational instance cannot be divided by an Int type object';
throws-like 「Int/(1/1)」,
X::Parameter::InvalidConcreteness,
'An Int type object cannot be divided by a Rational instance';
throws-like 「Int/Int」,
X::Parameter::InvalidConcreteness,
'An Int type object cannot be divided by an Int type object';
throws-like 「Int/1」,
X::Parameter::InvalidConcreteness,
'An Int type object cannot be divided by an Int instance';
throws-like 「1/Int」,
X::Parameter::InvalidConcreteness,
'An Int instance cannot be divided by an Int type object';
throws-like 「(1/1)%Int」,
X::Parameter::InvalidConcreteness,
'A Rational instance modulo an Int type object is incalculable';
throws-like 「Int%(1/1)」,
X::Parameter::InvalidConcreteness,
'An Int type object modulo a Rational instance is incalculable';
throws-like 「(1/1)**Int」,
X::Parameter::InvalidConcreteness,
'A Rational instance cannot be powered by an Int type object';
}
# https://github.com/rakudo/rakudo/issues/1364
throws-like 「sub meows;」, X::UnitScope::Invalid, :message(/
"placed a semicolon after routine's definition"
/), 'unit-scoped sub def mentions potential unwanted semicolon';
# Github Issue #1305 (https://github.com/rakudo/rakudo/issues/1305)
throws-like { my $r = 1..5; $r[42] = 21 }, X::Assignment::RO,
:message{ .contains: 'Range' & none 'Str', '(Nil)' },
'Trying to assign to immutable Range element gives useful error';
# The warning for `*+*` in void context is handled by the optimizer so
# if we turn off the optimizer, we'd get clean STDERR/STDOUT, which is what
# the this test checks.
is-run 'EVAL "*+*"', :compiler-args[<--optimize=off>],
'optimizer flag gets propagated to EVAL';
# RT126669
throws-like { EVAL "use 6.0;" }, X::Undeclared::Symbols,
:message{ .contains: 'use "v" prefix for pragma (e.g., "use v6;", "use v6.c;")' },
'suggests to use "use v6;" or "use v6.c;" when "use 6.0" is called';
throws-like { EVAL "need 6.0;" }, X::Undeclared::Symbols,
:message{ .contains: 'use "v" prefix for pragma (e.g., "need v6;", "need v6.c;")' },
'suggests to use "need v6;" or "need v6.c;" when "need 6.0" is called';
# vim: ft=perl6 expandtab sw=4