Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 217 lines (184 sloc) 9.477 kb
3d3f9a24 »
2011-12-17 initial tests for typed exceptions; very unstructured for now
1 use v6;
2 use Test;
3
2002a2fe »
2012-01-30 more typed exceptions
4 #?DOES 1
3d3f9a24 »
2011-12-17 initial tests for typed exceptions; very unstructured for now
5 sub throws_like($code, $ex_type, *%matcher) {
6ff177cf »
2012-01-24 even nicer test output
6 my $msg;
3d3f9a24 »
2011-12-17 initial tests for typed exceptions; very unstructured for now
7 if $code ~~ Callable {
6ff177cf »
2012-01-24 even nicer test output
8 $msg = 'code dies';
3d3f9a24 »
2011-12-17 initial tests for typed exceptions; very unstructured for now
9 $code()
10 } else {
6ff177cf »
2012-01-24 even nicer test output
11 $msg = "'$code' died";
3d3f9a24 »
2011-12-17 initial tests for typed exceptions; very unstructured for now
12 eval $code;
13 }
6ff177cf »
2012-01-24 even nicer test output
14 ok 0, $msg;
3d3f9a24 »
2011-12-17 initial tests for typed exceptions; very unstructured for now
15 skip 'Code did not die, can not check exception', 1 + %matcher.elems;
16 CATCH {
17 default {
6ff177cf »
2012-01-24 even nicer test output
18 ok 1, $msg;
4c68d1a5 »
2011-12-18 skipped tests for X::Obsolete
19 my $type_ok = $_.WHAT === $ex_type;
20 ok $type_ok , "right exception type ({$ex_type.^name})";
21 if $type_ok {
22 for %matcher.kv -> $k, $v {
8d41f565 »
2012-01-24 more typed exception tests, better diagnosis
23 my $got = $_."$k"();
24 my $ok = $got ~~ $v,;
5e0af50d »
2012-04-03 [throws_like] avoid undef warnings for matchers
25 ok $ok, ".$k matches {$v.defined ?? $v !! $v.gist}";
8d41f565 »
2012-01-24 more typed exception tests, better diagnosis
26 unless $ok {
27 diag "Got: $got\n"
28 ~"Expected: $v";
29 }
4c68d1a5 »
2011-12-18 skipped tests for X::Obsolete
30 }
31 } else {
8d41f565 »
2012-01-24 more typed exception tests, better diagnosis
32 diag "Got: {$_.WHAT.gist}\n"
33 ~"Expected: {$ex_type.gist}";
6467df25 »
2012-02-23 test X::Attribute::Package and X::Attribute::NoPackage
34 diag "Exception message: $_.message()";
4c68d1a5 »
2011-12-18 skipped tests for X::Obsolete
35 skip 'wrong exception type', %matcher.elems;
3d3f9a24 »
2011-12-17 initial tests for typed exceptions; very unstructured for now
36 }
37 }
38 }
39 }
40
41 throws_like { Buf.new().Str }, X::Buf::AsStr, method => 'Str';
67636640 »
2012-02-11 fix test for X::Attribute::Undeclared
42 throws_like 'my class Foo { method a() { $!bar } }', X::Attribute::Undeclared,
3d3f9a24 »
2011-12-17 initial tests for typed exceptions; very unstructured for now
43 name => '$!bar', package-name => 'Foo';
44 throws_like 'sub f() { $^x }', X::Signature::Placeholder,
45 line => 1;
46
4c68d1a5 »
2011-12-18 skipped tests for X::Obsolete
47 #?rakudo skip 'parsing of $& and other p5 variables'
9fb1b22e »
2012-03-27 test for qr obsoletion message
48 throws_like '$&', X::Obsolete, old => '$@ variable', replacement => '$, rx/<<rx>>// or $()';
49 throws_like 'qr/a/', X::Obsolete, old => rx/<<qr>>/, replacement => rx/<<rx>>/;
4c68d1a5 »
2011-12-18 skipped tests for X::Obsolete
50
f52c2ed5 »
2012-01-23 test presence of placeholder attribute of X::Placeholder::Block excep…
51 throws_like 'do { $^x }', X::Placeholder::Block, placeholder => '$^x';
52 throws_like 'do { @_ }', X::Placeholder::Block, placeholder => '@_';
53 throws_like 'class { $^x }', X::Placeholder::Block, placeholder => '$^x';
8d41f565 »
2012-01-24 more typed exception tests, better diagnosis
54 throws_like '$^x', X::Placeholder::Mainline, placeholder => '$^x';
d5ac5a66 »
2012-02-03 RT #73502, @_ in the mainline
55 # RT #73502
56 throws_like '@_', X::Placeholder::Mainline, placeholder => '@_';
bea87e2b »
2012-03-04 RT #85942
57 # RT #85942
58 throws_like '"foo".{ say $^a }', X::Placeholder::Mainline;
59
60
8d41f565 »
2012-01-24 more typed exception tests, better diagnosis
61 throws_like 'sub f(*@a = 2) { }', X::Parameter::Default, how => 'slurpy';
62 throws_like 'sub f($x! = 3) { }', X::Parameter::Default, how => 'required';
63 throws_like 'sub f(:$x! = 3) { }', X::Parameter::Default, how => 'required';
64 throws_like 'sub f($:x) { }', X::Parameter::Placeholder,
65 parameter => '$:x',
66 right => ':$x';
67 throws_like 'sub f($?x) { }', X::Parameter::Twigil,
68 parameter => '$?x',
69 twigil => '?';
a97dc2a5 »
2012-01-26 track change of error class names; add some more redeclaration tests
70 throws_like 'sub (Int Str $x) { }', X::Parameter::MultipleTypeConstraints;
8d41f565 »
2012-01-24 more typed exception tests, better diagnosis
71
72
73
a97dc2a5 »
2012-01-26 track change of error class names; add some more redeclaration tests
74 # some of these redeclaration errors take different code
75 # paths in rakudo, so we over-test a bit to catch them all,
76 # even if the tests look rather boring;
0b7d7d24 »
2012-01-23 more typed exception tests
77 throws_like 'my @a; my @a', X::Redeclaration, symbol => '@a';
78 throws_like 'sub a { }; sub a { }',X::Redeclaration, symbol => 'a', what => 'routine';
63626c2d »
2012-02-08 another redeclaration test
79 throws_like 'sub a { }; multi sub a { }',X::Redeclaration, symbol => 'a', what => 'routine';
a97dc2a5 »
2012-01-26 track change of error class names; add some more redeclaration tests
80 throws_like 'my class A { }; my class A { }', X::Redeclaration, symbol => 'A';
c9e36113 »
2012-04-14 more robust name clash tests
81 throws_like 'my class B { }; my subset B of Any;', X::Redeclaration, symbol => 'B';
a97dc2a5 »
2012-01-26 track change of error class names; add some more redeclaration tests
82 throws_like 'CATCH { }; CATCH { }', X::Phaser::Multiple, block => 'CATCH';
fbb78ed5 »
2012-01-23 test for X::Placeholder::Block
83
6467df25 »
2012-02-23 test X::Attribute::Package and X::Attribute::NoPackage
84 throws_like 'my class A { my @a; @a!List::foo() }',
c01e5d67 »
2012-01-24 tests for typed private method call exceptions
85 X::Method::Private::Permission,
86 method => 'foo',
87 calling-package => 'A',
88 source-package => 'List';
89
90 throws_like '1!foo()',
a97dc2a5 »
2012-01-26 track change of error class names; add some more redeclaration tests
91 X::Method::Private::Unqualified,
c01e5d67 »
2012-01-24 tests for typed private method call exceptions
92 method => 'foo';
93
a8246984 »
2012-01-25 typed binding excpetions
94 throws_like 'sub f() { }; f() := 2', X::Bind::WrongLHS;
95 throws_like 'my int $x := 2', X::Bind::NativeType;
709242e4 »
2012-03-29 tests for X::Bind::ZenSlice.
96 throws_like 'my @a; @a[] := <foo bar baz>', X::Bind::ZenSlice, what => 'array';
97 throws_like 'my %a; %a{} := foo=>1, bar=>2, baz=>3', X::Bind::ZenSlice, what => 'hash';
98
a8246984 »
2012-01-25 typed binding excpetions
99
dc765ebb »
2012-01-25 tests for typed exceptions
100 throws_like 'for (1; 1; 1) { }', X::Obsolete,
101 old => rx/<<for>>/,
102 replacement => rx/<<loop>>/;
103 throws_like 'foreach (1..10) { }', X::Obsolete,
104 old => "'foreach'",
105 replacement => "'for'";
106 throws_like 'undef', X::Obsolete,
107 old => rx/<<undef>>/;
108
a97dc2a5 »
2012-01-26 track change of error class names; add some more redeclaration tests
109 throws_like 'my $a::::b', X::Syntax::Name::Null;
d1f0fd85 »
2012-01-28 tests for typed syntax errors
110 throws_like 'unless 1 { } else { }', X::Syntax::UnlessElse;
111 throws_like 'for my $x (1, 2, 3) { }', X::Syntax::P5;
112 throws_like ':!foo(3)', X::Syntax::NegatedPair;
113 throws_like 'my $0', X::Syntax::Variable::Numeric;
b2914792 »
2012-02-24 test parameter variant of X::Syntax::Variable::Numeric
114 throws_like 'my sub f($0) { }', X::Syntax::Variable::Numeric, what => 'parameter';
d1f0fd85 »
2012-01-28 tests for typed syntax errors
115 throws_like 'my $<a>', X::Syntax::Variable::Match;
33e961e4 »
2012-01-30 RT #69230, my $!foo
116 throws_like 'my class A { my $!foo }', X::Syntax::Variable::Twigil, twigil => '!', scope => 'my';
d9f7caae »
2012-05-03 RT #112724, line numbers from warnings
117 throws_like 'my $?FILE', X::Syntax::Variable::Twigil, twigil => '?', scope => 'my';
277e13dd »
2012-01-28 more tests for typed syntax errors
118 throws_like 'my $::("foo")', X::Syntax::Variable::IndirectDeclaration;
171ad0a8 »
2012-02-07 test X::Undeclared
119 throws_like '@a', X::Undeclared, symbol => '@a';
277e13dd »
2012-01-28 more tests for typed syntax errors
120 throws_like 'augment class Any { }', X::Syntax::Augment::WithoutMonkeyTyping;
121 throws_like 'use MONKEY_TYPING; augment role Positional { }', X::Syntax::Augment::Role;
fd201d9a »
2012-04-05 RT #82984
122 throws_like 'sub postbla:sym<foo>() { }', X::Syntax::Extension::Category, category => 'postbla';
840bfdaa »
2012-05-13 test for X::Signature::NameClash
123 throws_like 'sub f(:in(:$in)) { }', X::Signature::NameClash, name => 'in';
296a529c »
2012-03-29 test for X::Does::TypeObject raising for 'does' operator.
124 throws_like 'my $foo does &Int', X::Does::TypeObject;
125 throws_like 'my $foo does &Int, &Bool', X::Does::TypeObject;
104f5224 »
2012-03-29 add tests for X::Role::Initialization.
126 throws_like 'role R { }; 99 but R("wrong");', X::Role::Initialization;
127 throws_like 'role R { has $.x; has $.y }; 99 but R("wrong");', X::Role::Initialization;
128 throws_like 'role R { }; 99 does R("wrong");', X::Role::Initialization;
129 throws_like 'role R { has $.x; has $.y }; 99 does R("wrong");', X::Role::Initialization;
277e13dd »
2012-01-28 more tests for typed syntax errors
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';
03faea74 »
2012-01-26 X::Syntax::Name::NotNull
140
2002a2fe »
2012-01-30 more typed exceptions
141 #?rakudo skip 'parsing regression'
142 throws_like '#`', X::Syntax::Comment::Embedded;
1af5f7a9 »
2012-03-02 RT #71814, =begin without identifier
143 # RT #71814
144 throws_like "=begin\n", X::Syntax::Pod::BeginWithoutIdentifier, line => 1, filename => rx/eval/;
2002a2fe »
2012-01-30 more typed exceptions
145
146 throws_like '@', X::Syntax::SigilWithoutName;
147 throws_like '1∞', X::Syntax::Confused;
e4dee679 »
2012-02-23 X::Syntax::Missing
148 throws_like 'for 1, 2', X::Syntax::Missing, what => 'block';
a78af8ce »
2012-02-24 X::Syntax::Reserved
149 throws_like 'my @a()', X::Syntax::Reserved, reserved => /shape/ & /array/;
150 throws_like 'my &a()', X::Syntax::Reserved, instead => /':()'/;
2002a2fe »
2012-01-30 more typed exceptions
151
59f3f35d »
2012-02-08 test exception type for stuff that must be known at compile time
152 throws_like 'm:i(@*ARGS[0])/foo/', X::Value::Dynamic;
153 throws_like 'my enum Foo (:x(@*ARGS[0]))', X::Value::Dynamic;
154
5c0802db »
2012-02-11 more exception tests
155 throws_like 'self', X::Syntax::Self::WithoutObject;
478ed38d »
2012-02-11 more tests for availabilty-of-self related errors
156 throws_like 'class { has $.x = $.y }', X::Syntax::VirtualCall, call => '$.y';
157 throws_like '$.a', X::Syntax::NoSelf, variable => '$.a';
5c0802db »
2012-02-11 more exception tests
158
6467df25 »
2012-02-23 test X::Attribute::Package and X::Attribute::NoPackage
159 throws_like 'has $.x', X::Attribute::NoPackage;
160 throws_like 'my module A { has $.x }', X::Attribute::Package, package-type => 'module';
161
46f9b17d »
2012-03-08 track exception name change, and add another test
162 throws_like 'has sub a() { }', X::Declaration::Scope, scope => 'has', declaration => 'sub';
163 throws_like 'has package a { }', X::Declaration::Scope, scope => 'has', declaration => 'package';
eb6edd64 »
2012-03-15 test X::Declaration::Scope::Multi
164 throws_like 'our multi a() { }', X::Declaration::Scope::Multi, scope => 'our';
a2b6fc20 »
2012-02-23 more typed exceptions
165 throws_like 'multi sub () { }', X::Anon::Multi, multiness => 'multi';
166 throws_like 'proto sub () { }', X::Anon::Multi, multiness => 'proto';
3b9a6049 »
2012-02-23 more typed exceptions
167 throws_like 'class { multi method () { }}', X::Anon::Multi, routine-type => 'method';
5065e35d »
2012-02-23 test X::Anon::Augment
168 throws_like 'use MONKEY_TYPING; augment class { }', X::Anon::Augment, package-type => 'class';
3804629e »
2012-02-23 test X::Augment::NoSuchType
169 throws_like 'use MONKEY_TYPING; augment class NoSuchClass { }', X::Augment::NoSuchType,
170 package-type => 'class',
171 package => 'NoSuchClass';
c9e36113 »
2012-04-14 more robust name clash tests
172 throws_like 'use MONKEY_TYPING; augment class No::Such::Class { }', X::Augment::NoSuchType,
173 package => 'No::Such::Class';
3b9a6049 »
2012-02-23 more typed exceptions
174
175 throws_like ':45<abcd>', X::Syntax::Number::RadixOutOfRange, radix => 45;
3dab5c0c »
2012-03-30 RT #112056
176 throws_like ':0<0>', X::Syntax::Number::RadixOutOfRange, message => rx/0/;
dc3de2d6 »
2012-02-24 X::Syntax::Regex::Adverb
177 throws_like 'rx:g/a/', X::Syntax::Regex::Adverb, adverb => 'g', construct => 'rx';
26f68343 »
2012-02-26 X::Syntax::Signature::InvocantMarker
178 throws_like 'my sub f($x, $y:) { }', X::Syntax::Signature::InvocantMarker;
a2b6fc20 »
2012-02-23 more typed exceptions
179
1bf4f1dc »
2012-02-26 X::OutOfRange
180 throws_like 'Date.new("2012-02-30")', X::OutOfRange,
181 range => Range, message => rx/<<1\.\.29>>/;
58512ac3 »
2012-04-04 test index out of range exception
182 throws_like 'use fatal; "foo"[2]', X::OutOfRange, what => rx:i/index/, range => 0..0, got => 2;
1bf4f1dc »
2012-02-26 X::OutOfRange
183
52f6db64 »
2012-02-27 test for X::Routine::Unwrap
184 throws_like 'sub f() { }; &f.unwrap("foo")', X::Routine::Unwrap;
44d0aa37 »
2012-02-27 test X::Constructor::Positional
185 throws_like 'Mu.new(1)', X::Constructor::Positional;
39b3eb78 »
2012-02-28 add test for X::Hash::Store::Oddnumber
186 throws_like 'my %h = 1', X::Hash::Store::OddNumber;
52f6db64 »
2012-02-27 test for X::Routine::Unwrap
187
fcd16681 »
2012-03-02 Test for proper error of "sub foo;", RT #68710 and RT #111492
188 # TOOD: might be X::Syntax::Malformed too...
189 throws_like 'sub foo;', X::Syntax::Missing, what => 'block';
157d7b7c »
2012-03-03 more tests for "constant" parse errors
190 throws_like 'constant foo;', X::Syntax::Missing, what => /initializer/;
191 throws_like 'constant * = 3;', X::Syntax::Missing, what => /constant/;
fcd16681 »
2012-03-02 Test for proper error of "sub foo;", RT #68710 and RT #111492
192
ddc21bfd »
2012-03-08 test X::Package::Stubbed
193 throws_like 'class A {...}; grammar B { ... }', X::Package::Stubbed, packages => <A B>;
194
98312337 »
2012-03-18 track phaser error changes in rakudo
195 throws_like 'my sub a { PRE 0 }; a()', X::Phaser::PrePost, phaser => 'PRE', condition => /0/;
196 throws_like 'my sub a { POST 0 }; a()', X::Phaser::PrePost, phaser => 'POST', condition => /0/;
efa96102 »
2012-03-18 typed exceptions for PRE/POST failures
197
d720afa0 »
2012-03-25 test that Str numification error message survives through infix:<+>
198 throws_like 'use fatal; my $x = "5 foo" + 8;', X::Str::Numeric, source => '5 foo', pos => 1,
199 reason => /trailing/;
200
903dffc1 »
2012-03-30 test that stubby exception generators can take an argument
201 # RT #58558
202 throws_like '!!! 42', X::AdHoc, payload => 42;
203 throws_like 'use fatal; ... 42', X::AdHoc, payload => 42;
204 {
205 my $c = 0;
206 try {
207 ??? 42;
208 CONTROL { default { $c++ } }
209 }
210 is $c, 1, '??? with argument warns';
211 }
212
ca3a210c »
2012-03-31 $!.backtrace generates a Backtrace
213 throws_like 'die "foo"', X::AdHoc, backtrace => Backtrace;
2365690f »
2012-04-05 RT #98678, error message for failed sequence deduction
214 throws_like 'use fatal; ~(1, 2, 6 ... 10)', X::Sequence::Deduction;
903dffc1 »
2012-03-30 test that stubby exception generators can take an argument
215
3d3f9a24 »
2011-12-17 initial tests for typed exceptions; very unstructured for now
216 done;
Something went wrong with that request. Please try again.