Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 389 lines (321 sloc) 17.261 kb
3d3f9a2 Moritz Lenz initial tests for typed exceptions; very unstructured for now
moritz authored
1 use v6;
2 use Test;
8380ccf Moritz Lenz move throws_like to Test::Util
moritz authored
3 BEGIN { @*INC.push('t/spec/packages/') };
4 use Test::Util;
3d3f9a2 Moritz Lenz initial tests for typed exceptions; very unstructured for now
moritz authored
5
2002a2f Moritz Lenz more typed exceptions
moritz authored
6 #?DOES 1
88dbaa7 Moritz Lenz X::Buf::Pack
moritz authored
7 throws_like { Buf.new().Str }, X::Buf::AsStr, method => 'Str';;
8 throws_like 'pack("B", 1)', X::Buf::Pack, directive => 'B';
9 throws_like 'Buf.new.unpack("B")', X::Buf::Pack, directive => 'B';
7a26e13 Moritz Lenz test X::Buf::Pack::NonASCII
moritz authored
10 throws_like 'pack "A1", "mÄ"', X::Buf::Pack::NonASCII, char => 'Ä';
6763664 Moritz Lenz fix test for X::Attribute::Undeclared
moritz authored
11 throws_like 'my class Foo { method a() { $!bar } }', X::Attribute::Undeclared,
12f1b31 Moritz Lenz basic tests for sigilless params
moritz authored
12 symbol => '$!bar', package-name => 'Foo', package-kind => 'class',
13 what => 'attribute';
3d3f9a2 Moritz Lenz initial tests for typed exceptions; very unstructured for now
moritz authored
14 throws_like 'sub f() { $^x }', X::Signature::Placeholder,
bff406d Moritz Lenz update some exception tests
moritz authored
15 line => 1,
16 placeholder => '$^x',
17 ;
3d3f9a2 Moritz Lenz initial tests for typed exceptions; very unstructured for now
moritz authored
18
4c68d1a Moritz Lenz skipped tests for X::Obsolete
moritz authored
19 #?rakudo skip 'parsing of $& and other p5 variables'
9fb1b22 Moritz Lenz test for qr obsoletion message
moritz authored
20 throws_like '$&', X::Obsolete, old => '$@ variable', replacement => '$, rx/<<rx>>// or $()';
21 throws_like 'qr/a/', X::Obsolete, old => rx/<<qr>>/, replacement => rx/<<rx>>/;
ba74f5e test X::Obsolete
Moritz Lenz authored
22 throws_like '"a" . "b"', X::Obsolete, replacement => '~';
e225c9d Moritz Lenz test X::Obsolete error for s///i
moritz authored
23 throws_like 's/a/b/i', X::Obsolete;
b34a3de Moritz Lenz RT #112470, my ${a}
moritz authored
24 # RT #112470
25 throws_like 'my ${a} = 5', X::Obsolete;
4c68d1a Moritz Lenz skipped tests for X::Obsolete
moritz authored
26
f52c2ed Moritz Lenz test presence of placeholder attribute of X::Placeholder::Block exceptio...
moritz authored
27 throws_like 'do { $^x }', X::Placeholder::Block, placeholder => '$^x';
28 throws_like 'do { @_ }', X::Placeholder::Block, placeholder => '@_';
29 throws_like 'class { $^x }', X::Placeholder::Block, placeholder => '$^x';
47eec67 Tobias Leich RT #76956, linked ticket (placeholder in mainline)
FROGGS authored
30 # RT #76956
8d41f56 Moritz Lenz more typed exception tests, better diagnosis
moritz authored
31 throws_like '$^x', X::Placeholder::Mainline, placeholder => '$^x';
d5ac5a6 Moritz Lenz RT #73502, @_ in the mainline
moritz authored
32 # RT #73502
33 throws_like '@_', X::Placeholder::Mainline, placeholder => '@_';
bea87e2 Moritz Lenz RT #85942
moritz authored
34 # RT #85942
35 throws_like '"foo".{ say $^a }', X::Placeholder::Mainline;
36
37
12f1b31 Moritz Lenz basic tests for sigilless params
moritz authored
38 throws_like 'sub f(*@ = 2) { }', X::Parameter::Default, how => 'slurpy', parameter => *.not;
39 throws_like 'sub f($x! = 3) { }', X::Parameter::Default, how => 'required', parameter => '$x';
8d41f56 Moritz Lenz more typed exception tests, better diagnosis
moritz authored
40 throws_like 'sub f(:$x! = 3) { }', X::Parameter::Default, how => 'required';
41 throws_like 'sub f($:x) { }', X::Parameter::Placeholder,
42 parameter => '$:x',
43 right => ':$x';
44 throws_like 'sub f($?x) { }', X::Parameter::Twigil,
45 parameter => '$?x',
46 twigil => '?';
a97dc2a Moritz Lenz track change of error class names; add some more redeclaration tests
moritz authored
47 throws_like 'sub (Int Str $x) { }', X::Parameter::MultipleTypeConstraints;
8d41f56 Moritz Lenz more typed exception tests, better diagnosis
moritz authored
48
49
50
a97dc2a Moritz Lenz track change of error class names; add some more redeclaration tests
moritz authored
51 # some of these redeclaration errors take different code
52 # paths in rakudo, so we over-test a bit to catch them all,
53 # even if the tests look rather boring;
0b7d7d2 Moritz Lenz more typed exception tests
moritz authored
54 throws_like 'sub a { }; sub a { }',X::Redeclaration, symbol => 'a', what => 'routine';
dddf111 Moritz Lenz RT #78370, my &a; sub a { } redeclaration error
moritz authored
55 # RT #78370
cf0e342 Moritz Lenz oops, meant to test something else
moritz authored
56 #?rakudo skip 'RT 78370'
57 throws_like 'my &a; multi a { }', X::Redeclaration, symbol => 'a', what => 'routine';
63626c2 Moritz Lenz another redeclaration test
moritz authored
58 throws_like 'sub a { }; multi sub a { }',X::Redeclaration, symbol => 'a', what => 'routine';
a97dc2a Moritz Lenz track change of error class names; add some more redeclaration tests
moritz authored
59 throws_like 'my class A { }; my class A { }', X::Redeclaration, symbol => 'A';
c9e3611 Moritz Lenz more robust name clash tests
moritz authored
60 throws_like 'my class B { }; my subset B of Any;', X::Redeclaration, symbol => 'B';
a97dc2a Moritz Lenz track change of error class names; add some more redeclaration tests
moritz authored
61 throws_like 'CATCH { }; CATCH { }', X::Phaser::Multiple, block => 'CATCH';
75c081f Moritz Lenz tests for multiple return type exceptions
moritz authored
62 # multiple return types
63 throws_like 'sub f(--> List) returns Str { }', X::Redeclaration;
64 throws_like 'my Int sub f(--> Str) { }', X::Redeclaration;
b73c13b Moritz Lenz RT #115356, redeclaration of class as a role
moritz authored
65 # RT #115356
66 throws_like 'class F { }; role F { }', X::Redeclaration, symbol => 'F';
fbb78ed Moritz Lenz test for X::Placeholder::Block
moritz authored
67
6467df2 Moritz Lenz test X::Attribute::Package and X::Attribute::NoPackage
moritz authored
68 throws_like 'my class A { my @a; @a!List::foo() }',
c01e5d6 Moritz Lenz tests for typed private method call exceptions
moritz authored
69 X::Method::Private::Permission,
70 method => 'foo',
71 calling-package => 'A',
72 source-package => 'List';
73
74 throws_like '1!foo()',
a97dc2a Moritz Lenz track change of error class names; add some more redeclaration tests
moritz authored
75 X::Method::Private::Unqualified,
c01e5d6 Moritz Lenz tests for typed private method call exceptions
moritz authored
76 method => 'foo';
77
d9262ef Moritz Lenz [throws_ok] allow subtypes; Liskov applies
moritz authored
78 throws_like 'sub f() { }; f() := 2', X::Bind;
79 throws_like 'OUTER := 5', X::Bind, target => /OUTER/;
bff406d Moritz Lenz update some exception tests
moritz authored
80 throws_like 'my int $x := 2', X::Bind::NativeType, name => '$x';
c6df8c5 Moritz Lenz update and expand tests for binding to unbindable stuff
moritz authored
81 throws_like 'my @a; @a[] := <foo bar baz>', X::Bind::ZenSlice, type => Array;
82 throws_like 'my %a; %a{} := foo=>1, bar=>2, baz=>3', X::Bind::ZenSlice, type => Hash;
83 throws_like 'my @a; @a[0, 1] := (2, 3)', X::Bind::Slice, type => Array;
84 throws_like 'my %a; %a<a b> := (2, 3)', X::Bind::Slice, type => Hash;
709242e timo tests for X::Bind::ZenSlice.
timo authored
85
a824698 Moritz Lenz typed binding excpetions
moritz authored
86
dc765eb Moritz Lenz tests for typed exceptions
moritz authored
87 throws_like 'for (1; 1; 1) { }', X::Obsolete,
88 old => rx/<<for>>/,
89 replacement => rx/<<loop>>/;
90 throws_like 'foreach (1..10) { }', X::Obsolete,
91 old => "'foreach'",
92 replacement => "'for'";
93 throws_like 'undef', X::Obsolete,
94 old => rx/<<undef>>/;
49868a5 Tobias Leich RT #77118, test for obsolete use of diamond operator
FROGGS authored
95 # RT #77118
96 {
97 throws_like ':a<>', X::Obsolete, old => "<>";
98 }
0d9fc5d Moritz Lenz RT #92408: detect obsolete use of . as concatenation operator
moritz authored
99 # RT #92408
100 throws_like 'my ($a, $b); $a . $b', X::Obsolete;
dc765eb Moritz Lenz tests for typed exceptions
moritz authored
101
a97dc2a Moritz Lenz track change of error class names; add some more redeclaration tests
moritz authored
102 throws_like 'my $a::::b', X::Syntax::Name::Null;
d1f0fd8 Moritz Lenz tests for typed syntax errors
moritz authored
103 throws_like 'unless 1 { } else { }', X::Syntax::UnlessElse;
104 throws_like 'for my $x (1, 2, 3) { }', X::Syntax::P5;
425b786 Moritz Lenz test for extra information in X::Syntax::NegatedPair
moritz authored
105 throws_like ':!foo(3)', X::Syntax::NegatedPair, key => 'foo';
d1f0fd8 Moritz Lenz tests for typed syntax errors
moritz authored
106 throws_like 'my $0', X::Syntax::Variable::Numeric;
b291479 Moritz Lenz test parameter variant of X::Syntax::Variable::Numeric
moritz authored
107 throws_like 'my sub f($0) { }', X::Syntax::Variable::Numeric, what => 'parameter';
d1f0fd8 Moritz Lenz tests for typed syntax errors
moritz authored
108 throws_like 'my $<a>', X::Syntax::Variable::Match;
33e961e Moritz Lenz RT #69230, my $!foo
moritz authored
109 throws_like 'my class A { my $!foo }', X::Syntax::Variable::Twigil, twigil => '!', scope => 'my';
d9f7caa Moritz Lenz RT #112724, line numbers from warnings
moritz authored
110 throws_like 'my $?FILE', X::Syntax::Variable::Twigil, twigil => '?', scope => 'my';
277e13d Moritz Lenz more tests for typed syntax errors
moritz authored
111 throws_like 'my $::("foo")', X::Syntax::Variable::IndirectDeclaration;
171ad0a Moritz Lenz test X::Undeclared
moritz authored
112 throws_like '@a', X::Undeclared, symbol => '@a';
8b533dd Moritz Lenz RT #115396, undeclared variables in interpolating strings
moritz authored
113 # RT #115396
114 throws_like '"@a[]"', X::Undeclared, symbol => '@a';
277e13d Moritz Lenz more tests for typed syntax errors
moritz authored
115 throws_like 'augment class Any { }', X::Syntax::Augment::WithoutMonkeyTyping;
6e76108 Jonathan Worthington Update augment exception test and add another one.
jnthn authored
116 throws_like 'use MONKEY_TYPING; augment role Positional { }', X::Syntax::Augment::Illegal;
117 throws_like 'use MONKEY_TYPING; enum Weekday <Mon Tue>; augment class Weekday { }', X::Syntax::Augment::Illegal;
fd201d9 Moritz Lenz RT #82984
moritz authored
118 throws_like 'sub postbla:sym<foo>() { }', X::Syntax::Extension::Category, category => 'postbla';
ab9c613 Moritz Lenz RT #83992, proper error message for infix in term position
moritz authored
119 # RT #83992
120 throws_like 'my @a = 1, => 2', X::Syntax::InfixInTermPosition, infix => '=>';
840bfda Moritz Lenz test for X::Signature::NameClash
moritz authored
121 throws_like 'sub f(:in(:$in)) { }', X::Signature::NameClash, name => 'in';
a52f2b3 Jonathan Worthington A few minor tweaks for stdier.
jnthn authored
122 throws_like '(my $foo) does Int', X::Does::TypeObject;
123 throws_like '(my $foo) does Int, Bool', X::Does::TypeObject;
e87efa1 Tobias Leich RT #76742, added test for 'does with type object'
FROGGS authored
124 # RT #76742
125 throws_like 'Bool does role { method Str() { $.perl } };', X::Does::TypeObject;
2267094 Jonathan Worthington Fix some package/eval related issues.
jnthn authored
126 throws_like 'my role R { }; 99 but R("wrong");', X::Role::Initialization;
127 throws_like 'my role R { has $.x; has $.y }; 99 but R("wrong");', X::Role::Initialization;
128 throws_like 'my role R { }; 99 does R("wrong");', X::Role::Initialization;
129 throws_like 'my role R { has $.x; has $.y }; 99 does R("wrong");', X::Role::Initialization;
277e13d Moritz Lenz more tests for typed syntax errors
moritz authored
130
131 throws_like 'sub f($a?, $b) { }', X::Parameter::WrongOrder,
132 misplaced => 'required',
133 after => 'optional';
134 throws_like 'sub f(*@a, $b) { }', X::Parameter::WrongOrder,
135 misplaced => 'required',
136 after => 'variadic';
137 throws_like 'sub f(*@a, $b?) { }', X::Parameter::WrongOrder,
138 misplaced => 'optional positional',
139 after => 'variadic';
03faea7 Moritz Lenz X::Syntax::Name::NotNull
moritz authored
140
2002a2f Moritz Lenz more typed exceptions
moritz authored
141 #?rakudo skip 'parsing regression'
142 throws_like '#`', X::Syntax::Comment::Embedded;
1af5f7a Moritz Lenz RT #71814, =begin without identifier
moritz authored
143 # RT #71814
144 throws_like "=begin\n", X::Syntax::Pod::BeginWithoutIdentifier, line => 1, filename => rx/eval/;
2002a2f Moritz Lenz more typed exceptions
moritz authored
145
146 throws_like '@', X::Syntax::SigilWithoutName;
147 throws_like '1∞', X::Syntax::Confused;
e4dee67 Moritz Lenz X::Syntax::Missing
moritz authored
148 throws_like 'for 1, 2', X::Syntax::Missing, what => 'block';
a78af8c Moritz Lenz X::Syntax::Reserved
moritz authored
149 throws_like 'my @a()', X::Syntax::Reserved, reserved => /shape/ & /array/;
150 throws_like 'my &a()', X::Syntax::Reserved, instead => /':()'/;
2002a2f Moritz Lenz more typed exceptions
moritz authored
151
98bd346 Tobias Leich test for "\u" X::Backslash::UnrecognizedSequence
FROGGS authored
152 # RT #115922
153 throws_like '"\u"', X::Backslash::UnrecognizedSequence, sequence => 'u';
8d88d57 Tobias Leich test for "$" X::Backslash::NonVariableDollar
FROGGS authored
154 throws_like '"$"', X::Backslash::NonVariableDollar;
155
59f3f35 Moritz Lenz test exception type for stuff that must be known at compile time
moritz authored
156 throws_like 'm:i(@*ARGS[0])/foo/', X::Value::Dynamic;
157
5c0802d Moritz Lenz more exception tests
moritz authored
158 throws_like 'self', X::Syntax::Self::WithoutObject;
478ed38 Moritz Lenz more tests for availabilty-of-self related errors
moritz authored
159 throws_like 'class { has $.x = $.y }', X::Syntax::VirtualCall, call => '$.y';
160 throws_like '$.a', X::Syntax::NoSelf, variable => '$.a';
b3c2006 Moritz Lenz RT #59118
moritz authored
161 # RT #59118
162 throws_like 'my class B0Rk { $.a }', X::Syntax::NoSelf, variable => '$.a';
5c0802d Moritz Lenz more exception tests
moritz authored
163
6467df2 Moritz Lenz test X::Attribute::Package and X::Attribute::NoPackage
moritz authored
164 throws_like 'has $.x', X::Attribute::NoPackage;
12f1b31 Moritz Lenz basic tests for sigilless params
moritz authored
165 throws_like 'my module A { has $.x }', X::Attribute::Package, package-kind => 'module';
6467df2 Moritz Lenz test X::Attribute::Package and X::Attribute::NoPackage
moritz authored
166
46f9b17 Moritz Lenz track exception name change, and add another test
moritz authored
167 throws_like 'has sub a() { }', X::Declaration::Scope, scope => 'has', declaration => 'sub';
168 throws_like 'has package a { }', X::Declaration::Scope, scope => 'has', declaration => 'package';
eb6edd6 Moritz Lenz test X::Declaration::Scope::Multi
moritz authored
169 throws_like 'our multi a() { }', X::Declaration::Scope::Multi, scope => 'our';
a2b6fc2 Moritz Lenz more typed exceptions
moritz authored
170 throws_like 'multi sub () { }', X::Anon::Multi, multiness => 'multi';
171 throws_like 'proto sub () { }', X::Anon::Multi, multiness => 'proto';
3b9a604 Moritz Lenz more typed exceptions
moritz authored
172 throws_like 'class { multi method () { }}', X::Anon::Multi, routine-type => 'method';
12f1b31 Moritz Lenz basic tests for sigilless params
moritz authored
173 throws_like 'use MONKEY_TYPING; augment class { }', X::Anon::Augment, package-kind => 'class';
3804629 Moritz Lenz test X::Augment::NoSuchType
moritz authored
174 throws_like 'use MONKEY_TYPING; augment class NoSuchClass { }', X::Augment::NoSuchType,
12f1b31 Moritz Lenz basic tests for sigilless params
moritz authored
175 package-kind => 'class',
3804629 Moritz Lenz test X::Augment::NoSuchType
moritz authored
176 package => 'NoSuchClass';
c9e3611 Moritz Lenz more robust name clash tests
moritz authored
177 throws_like 'use MONKEY_TYPING; augment class No::Such::Class { }', X::Augment::NoSuchType,
178 package => 'No::Such::Class';
3b9a604 Moritz Lenz more typed exceptions
moritz authored
179
180 throws_like ':45<abcd>', X::Syntax::Number::RadixOutOfRange, radix => 45;
3dab5c0 Moritz Lenz RT #112056
moritz authored
181 throws_like ':0<0>', X::Syntax::Number::RadixOutOfRange, message => rx/0/;
dc3de2d Moritz Lenz X::Syntax::Regex::Adverb
moritz authored
182 throws_like 'rx:g/a/', X::Syntax::Regex::Adverb, adverb => 'g', construct => 'rx';
26f6834 Moritz Lenz X::Syntax::Signature::InvocantMarker
moritz authored
183 throws_like 'my sub f($x, $y:) { }', X::Syntax::Signature::InvocantMarker;
a2b6fc2 Moritz Lenz more typed exceptions
moritz authored
184
1bf4f1d Moritz Lenz X::OutOfRange
moritz authored
185 throws_like 'Date.new("2012-02-30")', X::OutOfRange,
186 range => Range, message => rx/<<1\.\.29>>/;
c04814d Moritz Lenz test leap second exception
moritz authored
187 throws_like 'DateTime.new(year => 2012, month => 5, day => 22, hour => 18, minute => 3, second => 60)',
188 X::OutOfRange, comment => /'leap second'/;
58512ac Moritz Lenz test index out of range exception
moritz authored
189 throws_like 'use fatal; "foo"[2]', X::OutOfRange, what => rx:i/index/, range => 0..0, got => 2;
1bf4f1d Moritz Lenz X::OutOfRange
moritz authored
190
52f6db6 Moritz Lenz test for X::Routine::Unwrap
moritz authored
191 throws_like 'sub f() { }; &f.unwrap("foo")', X::Routine::Unwrap;
2018e14 Tobias Leich X::Constructor::Positional's attribute is the type object
FROGGS authored
192
193 # X::Constructor::Positional
194 {
195 class Foo { };
196 throws_like 'Mu.new(1)', X::Constructor::Positional, type => Mu;
197 throws_like 'Foo.new(1, 2, 3);', X::Constructor::Positional, type => Foo;
198 }
199
39b3eb7 Siddhant Saraf add test for X::Hash::Store::Oddnumber
Siddhant authored
200 throws_like 'my %h = 1', X::Hash::Store::OddNumber;
52f6db6 Moritz Lenz test for X::Routine::Unwrap
moritz authored
201
fcd1668 Moritz Lenz Test for proper error of "sub foo;", RT #68710 and RT #111492
moritz authored
202 # TOOD: might be X::Syntax::Malformed too...
203 throws_like 'sub foo;', X::Syntax::Missing, what => 'block';
db2d40c Moritz Lenz RT #75776, correct syntax error for missing block
moritz authored
204 # RT #75776
205 throws_like 'my $d; my class A {method x { $d }}; for () { sub }', X::Syntax::Missing, what => 'block';
157d7b7 Moritz Lenz more tests for "constant" parse errors
moritz authored
206 throws_like 'constant foo;', X::Syntax::Missing, what => /initializer/;
207 throws_like 'constant * = 3;', X::Syntax::Missing, what => /constant/;
ee14752 Moritz Lenz test X::Syntax::NonAssociative
moritz authored
208 throws_like '1 <=> 2 <=> 3', X::Syntax::NonAssociative, left => '<=>', right => '<=>';
fcd1668 Moritz Lenz Test for proper error of "sub foo;", RT #68710 and RT #111492
moritz authored
209
ddc21bf Moritz Lenz test X::Package::Stubbed
moritz authored
210 throws_like 'class A {...}; grammar B { ... }', X::Package::Stubbed, packages => <A B>;
211
9831233 Moritz Lenz track phaser error changes in rakudo
moritz authored
212 throws_like 'my sub a { PRE 0 }; a()', X::Phaser::PrePost, phaser => 'PRE', condition => /0/;
213 throws_like 'my sub a { POST 0 }; a()', X::Phaser::PrePost, phaser => 'POST', condition => /0/;
efa9610 Moritz Lenz typed exceptions for PRE/POST failures
moritz authored
214
d720afa Moritz Lenz test that Str numification error message survives through infix:<+>
moritz authored
215 throws_like 'use fatal; my $x = "5 foo" + 8;', X::Str::Numeric, source => '5 foo', pos => 1,
216 reason => /trailing/;
7bac3ca Patrick R. Michaud Update a .match failure test.
pmichaud authored
217 throws_like '"a".match(:x([1, 2, 3]), /a/).Str', X::Str::Match::x, got => Array;
7d371b6 Moritz Lenz test X::Str::Trans::IllegalKey, sorear++
moritz authored
218 throws_like '"a".trans([Any.new] => [Any.new])', X::Str::Trans::IllegalKey, key => Any;
7b9ba33 Moritz Lenz test X::Str::Trans::InvalidArg
moritz authored
219 throws_like '"a".trans(rx/a/)', X::Str::Trans::InvalidArg, got => Regex;
d720afa Moritz Lenz test that Str numification error message survives through infix:<+>
moritz authored
220
d701cfa Moritz Lenz text X::Method::NotFound on normal and .+ dispatches
moritz authored
221 throws_like '1.foo', X::Method::NotFound, method => 'foo', typename => 'Int';
222 throws_like '1.+foo', X::Method::NotFound, method => 'foo', typename => 'Int';
16238cd Moritz Lenz test private method not found error
moritz authored
223 throws_like 'my class Priv { method x { self!foo } }; Priv.x',
224 X::Method::NotFound,
225 method => '!foo',
226 typename => 'Priv',
227 private => { $_ === True };
b428149 Moritz Lenz RT #77582, error message when method is not found on a Hash
moritz authored
228 # RT #77582
229 throws_like 'my %h; %h.nosuchmethods', X::Method::NotFound, typename => 'Hash';
230
eff5942 Moritz Lenz more typed exception tests (X::ControlFlow, X::Method::InvalidQualifier)
moritz authored
231 throws_like '1.List::join', X::Method::InvalidQualifier,
232 method => 'join',
233 invocant => 1,
234 qualifier-type => List;
d701cfa Moritz Lenz text X::Method::NotFound on normal and .+ dispatches
moritz authored
235
903dffc Moritz Lenz test that stubby exception generators can take an argument
moritz authored
236 # RT #58558
237 throws_like '!!! 42', X::AdHoc, payload => 42;
238 throws_like 'use fatal; ... 42', X::AdHoc, payload => 42;
239 {
240 my $c = 0;
241 try {
242 ??? 42;
243 CONTROL { default { $c++ } }
244 }
245 is $c, 1, '??? with argument warns';
246 }
247
ca3a210 Moritz Lenz $!.backtrace generates a Backtrace
moritz authored
248 throws_like 'die "foo"', X::AdHoc, backtrace => Backtrace;
2365690 Moritz Lenz RT #98678, error message for failed sequence deduction
moritz authored
249 throws_like 'use fatal; ~(1, 2, 6 ... 10)', X::Sequence::Deduction;
903dffc Moritz Lenz test that stubby exception generators can take an argument
moritz authored
250
2267094 Jonathan Worthington Fix some package/eval related issues.
jnthn authored
251 throws_like 'my class B does Int { }', X::Composition::NotComposable, target-name => 'B', composer => Int;
cb7e988 Moritz Lenz test X::TypeCheck::Binding and X::TypeCheck::Return
moritz authored
252 throws_like 'my Str $x := 3', X::TypeCheck::Binding, got => Int, expected => Str;
253 throws_like 'sub f() returns Str { 5 }; f', X::TypeCheck::Return, got => Int, expected => Str;
6625f6f Moritz Lenz test X::TypeCheck::Assignment
moritz authored
254 throws_like 'my Int $x = "foo"', X::TypeCheck::Assignment, got => 'foo',
255 expected => Int, symbol => '$x';
cb7e988 Moritz Lenz test X::TypeCheck::Binding and X::TypeCheck::Return
moritz authored
256
61b24d9 Moritz Lenz test X::Assignment::RO, and add tests for RT #113534
moritz authored
257 throws_like 'sub f() { }; f() = 3', X::Assignment::RO;
258 throws_like '1.0 = 3', X::Assignment::RO;
259 # RT #113534
260 throws_like '120 = 3', X::Assignment::RO;
261 throws_like '1e0 = 3', X::Assignment::RO;
262 throws_like '"a" = 3', X::Assignment::RO;
263
b585e67 Moritz Lenz test for method not found exception
moritz authored
264 throws_like '1.foo', X::Method::NotFound, method => 'foo', typename => 'Int';
d4fa5e8 Moritz Lenz follow exception class rename
moritz authored
265 throws_like 'my class NC { }; NC.new does NC', X::Mixin::NotComposable,
5a8433b Moritz Lenz test X::Mixin::NonComposable
moritz authored
266 :target(*.defined), :rolish(*.^name eq 'NC');
d4fa5e8 Moritz Lenz follow exception class rename
moritz authored
267 throws_like 'my class NC { }; NC.new but NC', X::Mixin::NotComposable,
5a8433b Moritz Lenz test X::Mixin::NonComposable
moritz authored
268 :target(*.defined), :rolish(*.^name eq 'NC');
269
eff5942 Moritz Lenz more typed exception tests (X::ControlFlow, X::Method::InvalidQualifier)
moritz authored
270 throws_like 'last', X::ControlFlow,
271 illegal => 'last', enclosing => 'loop construct';
272 throws_like 'next', X::ControlFlow,
273 illegal => 'next', enclosing => 'loop construct';
274 throws_like 'redo', X::ControlFlow,
275 illegal => 'redo', enclosing => 'loop construct';
b585e67 Moritz Lenz test for method not found exception
moritz authored
276
c147454 Moritz Lenz test X::Inheritance::Unsupported
moritz authored
277 throws_like 'my package A { }; my class B is A { }', X::Inheritance::Unsupported;
d701cfa Moritz Lenz text X::Method::NotFound on normal and .+ dispatches
moritz authored
278
5eefbf8 Moritz Lenz test X::Export::NameClash
moritz authored
279 throws_like 'my module Expo { sub f is export { }; { sub f is export { } } }',
280 X::Export::NameClash, symbol => '&f';
281
385370f Moritz Lenz label and unfudge test for RT #113408, and remove nearly identical secon...
moritz authored
282 # RT #113408
78d560a Moritz Lenz test for X::HyperOp::NonDWIM
moritz authored
283 throws_like '<a b> »+« <c>', X::HyperOp::NonDWIM,
284 left-elems => 2, right-elems => 1,
285 operator => { .name eq 'infix:<+>' };
286
e708a8c Moritz Lenz test X::ControlFlow::Return
moritz authored
287 throws_like 'my sub f() { gather { return } }; ~f()', X::ControlFlow::Return;
288
a1248db Moritz Lenz test X::Temporal::InvalidFormat
moritz authored
289 throws_like 'DateTime.new("2012/04")', X::Temporal::InvalidFormat,
290 invalid-str => '2012/04',
291 target => 'DateTime';
292
293 throws_like 'Date.new("2012/04")', X::Temporal::InvalidFormat,
294 invalid-str => '2012/04',
295 target => 'Date';
296
6aa9f56 Moritz Lenz test X::Eval::NoSuchLang
moritz authored
297 throws_like 'eval("foo", :lang<no-such-language>)',
298 X::Eval::NoSuchLang,
299 lang => 'no-such-language';
300
7a77b2a Moritz Lenz test X::DateTime::TimezoneClash
moritz authored
301 throws_like 'DateTime.new("1998-12-31T23:59:60+0200", :timezone<Z>)', X::DateTime::TimezoneClash;
7d371b6 Moritz Lenz test X::Str::Trans::IllegalKey, sorear++
moritz authored
302
85f737a Moritz Lenz test X::Set::Coerce
moritz authored
303 throws_like 'Set(Any.new)', X::Set::Coerce;
304
a47ed9f Moritz Lenz test X::Numeric::Real
moritz authored
305 throws_like 'use fatal; (1+2i).Num', X::Numeric::Real, target => Num;
306 throws_like 'use fatal; (1+2i).Real', X::Numeric::Real, target => Real;
307
edf27d4 svatsan Added test for #114134
svatsan authored
308 #RT #114134
309 {
be54170 Moritz Lenz fudge test for RT #114134
moritz authored
310 #?rakudo skip 'RT 114134'
a6be9c5 Moritz Lenz avoid a redeclaration error that shadows the error we actually want to t...
moritz authored
311 throws_like 'my class A {}; (-> &c, $m { A.new()(); CATCH { default { $m } } } )(A, "")', X::TypeCheck::Binding;
edf27d4 svatsan Added test for #114134
svatsan authored
312
313 dies_ok {eval(class A{}; (-> &c, $m { A.new()(); CATCH { default { $m } } } )(A, "")) }, "Should fail type check with unbound variable";
314 }
315
28a82e8 Moritz Lenz RT #75640
moritz authored
316 # RT #75640
317 # cannot use dies_ok, because it puts the call in the dynamic scope of a
318 # dispatcher
319 try {
320 proto a() { nextsame };
321 a();
322 }
323 ok $! ~~ X::NoDispatcher, 'nextsame in proto';
324
6d4ae89 Moritz Lenz RT #79162: two terms in a row error message
moritz authored
325 # probably not quite spec, but good enough for now
326 # RT #79162
327 throws_like '["a" "b"]', X::Syntax::Confused, reason => 'Two terms in a row';
328
f71c502 timo added a few tests for suggestion exceptions
timo authored
329 # suggestions
330 my $emits_suggestions = False;
331 {
332 try eval('my $foo = 10; say $Foo');
333 $emits_suggestions = True if $!.^can("suggestions");
334 }
335
336 if $emits_suggestions {
337 throws_like 'my $foo = 10; say $Foo;', X::Undeclared, suggestions => '$foo';
338 throws_like 'my @barf = 1, 2, 3; say $barf[2]', X::Undeclared, suggestions => '@barf';
339
340 throws_like 'my $intergalactic-planetary = "planetary intergalactic"; say $IntergalacticPlanetary', X::Undeclared, suggestions => '$intergalactic-planetary';
341
342 throws_like 'class Foo is Junktion {}', X::Inheritance::UnknownParent, suggestions => 'Junction';
343 throws_like 'class Bar is junction {}', X::Inheritance::UnknownParent, suggestions => 'Junction';
344 throws_like 'class Baz is Juntcion {}', X::Inheritance::UnknownParent, suggestions => 'Junction';
345
346 {
347 try eval('say huc("foo")');
348 ok $! ~~ X::Undeclared::Symbols, "huc throws X::Undeclared::Symbols";
349 is $!.routine_suggestion<huc>, ["&uc"], '&uc is a suggestion';
350 }
dce99e0 timo if no suggestions, then no "did you mean".
timo authored
351
352 try eval('toolongtomatchanything()');
353 is +($!.routine_suggestion<toolongtomatchanything>), 0, "no suggestions for a strange name";
354 ok $!.message !~~ /Did you mean/, "doesn't show suggestions if there are none.";
355
356 try eval('class TestClassFactoryInterfaceBridgeMock is TooLongOfANameToBeConsideredGoodPerl { }');
357 is +($!.suggestions), 0, "no suggestions for a strange class";
358 ok $!.message !~~ /Did you mean/, "doesn't show suggestions if there are none.";
359
360 try eval('$i-just-made-this-up = "yup"');
361 is +($!.suggestions), 0, "no suggestions for a strange variable";
362 ok $!.message !~~ /Did you mean/, "doesn't suggest if there's no suggestions.";
0acfc00 timo a test for X::Parameter::InvalidType.
timo authored
363
364 throws_like 'sub yoink(Junctoin $barf) { }', X::Parameter::InvalidType, suggestions => 'Junction';
73618a5 timo "my cool $a" -> X::Undeclared + suggestions
timo authored
365
b059711 timo undeclared types in my are now Come::Group.
timo authored
366 {
367 try eval('my cool $a');
368 ok $! ~~ X::Comp::Group, 'my cool $a throws an X::Comp::Group.';
369 ok $!.sorrows[0] ~~ X::Undeclared, "the first sorrow is X::Undeclared.";
370 is $!.sorrows[0].suggestions, <Cool Bool>, "the suggestions are Cool and Bool";
371 }
cc878f5 timo check for Type suggestions in Undeclared::Symbols.
timo authored
372
373 {
374 try eval('Ecxeption.new("wrong!")');
375 ok $! ~~ X::Undeclared::Symbols, "Ecxeption.new throws X::Undeclared::Symbols";
376 is $!.type_suggestion<Ecxeption>, ["Exception"], 'Exception is a suggestion';
377 }
f71c502 timo added a few tests for suggestion exceptions
timo authored
378 }
379
95a13d7 timo check for X::Inheritance::SelfInherit.
timo authored
380 throws_like 'class Foobar is Foobar', X::Inheritance::SelfInherit, name => "Foobar";
381
7d2d272 timo add a test for RT #69760
timo authored
382 {
383 # RT #69760
384 my $code = q{class GrammarUserClass { method bar { PostDeclaredGrammar.parse('OH HAI'); } }; grammar PostDeclaredGrammar { rule TOP { .* } }; GrammarUserClass.bar;};
ed956b4 timo properly match post declared grammars.
timo authored
385 throws_like $code, X::Undeclared::Symbols, post_types => { .{"PostDeclaredGrammar"} :exists };
7d2d272 timo add a test for RT #69760
timo authored
386 }
387
3d3f9a2 Moritz Lenz initial tests for typed exceptions; very unstructured for now
moritz authored
388 done;
Something went wrong with that request. Please try again.