Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 177 lines (150 sloc) 7.415 kb
3d3f9a24 » moritz
2011-12-17 initial tests for typed exceptions; very unstructured for now
1 use v6;
2 use Test;
3
2002a2fe » moritz
2012-01-30 more typed exceptions
4 #?DOES 1
3d3f9a24 » moritz
2011-12-17 initial tests for typed exceptions; very unstructured for now
5 sub throws_like($code, $ex_type, *%matcher) {
6ff177cf » moritz
2012-01-24 even nicer test output
6 my $msg;
3d3f9a24 » moritz
2011-12-17 initial tests for typed exceptions; very unstructured for now
7 if $code ~~ Callable {
6ff177cf » moritz
2012-01-24 even nicer test output
8 $msg = 'code dies';
3d3f9a24 » moritz
2011-12-17 initial tests for typed exceptions; very unstructured for now
9 $code()
10 } else {
6ff177cf » moritz
2012-01-24 even nicer test output
11 $msg = "'$code' died";
3d3f9a24 » moritz
2011-12-17 initial tests for typed exceptions; very unstructured for now
12 eval $code;
13 }
6ff177cf » moritz
2012-01-24 even nicer test output
14 ok 0, $msg;
3d3f9a24 » moritz
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 » moritz
2012-01-24 even nicer test output
18 ok 1, $msg;
4c68d1a5 » moritz
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 » moritz
2012-01-24 more typed exception tests, better diagnosis
23 my $got = $_."$k"();
24 my $ok = $got ~~ $v,;
25 ok $ok, ".$k matches $v";
26 unless $ok {
27 diag "Got: $got\n"
28 ~"Expected: $v";
29 }
4c68d1a5 » moritz
2011-12-18 skipped tests for X::Obsolete
30 }
31 } else {
8d41f565 » moritz
2012-01-24 more typed exception tests, better diagnosis
32 diag "Got: {$_.WHAT.gist}\n"
33 ~"Expected: {$ex_type.gist}";
6467df25 » moritz
2012-02-23 test X::Attribute::Package and X::Attribute::NoPackage
34 diag "Exception message: $_.message()";
4c68d1a5 » moritz
2011-12-18 skipped tests for X::Obsolete
35 skip 'wrong exception type', %matcher.elems;
3d3f9a24 » moritz
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 » moritz
2012-02-11 fix test for X::Attribute::Undeclared
42 throws_like 'my class Foo { method a() { $!bar } }', X::Attribute::Undeclared,
3d3f9a24 » moritz
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 » moritz
2011-12-18 skipped tests for X::Obsolete
47 #?rakudo skip 'parsing of $& and other p5 variables'
48 throws_like '$&', X::Obsolete, old => '$@ variable', new => '$/ or $()';
49
f52c2ed5 » moritz
2012-01-23 test presence of placeholder attribute of X::Placeholder::Block excep…
50 throws_like 'do { $^x }', X::Placeholder::Block, placeholder => '$^x';
51 throws_like 'do { @_ }', X::Placeholder::Block, placeholder => '@_';
52 throws_like 'class { $^x }', X::Placeholder::Block, placeholder => '$^x';
8d41f565 » moritz
2012-01-24 more typed exception tests, better diagnosis
53 throws_like '$^x', X::Placeholder::Mainline, placeholder => '$^x';
d5ac5a66 » moritz
2012-02-03 RT #73502, @_ in the mainline
54 # RT #73502
55 throws_like '@_', X::Placeholder::Mainline, placeholder => '@_';
bea87e2b » moritz
2012-03-04 RT #85942
56 # RT #85942
57 throws_like '"foo".{ say $^a }', X::Placeholder::Mainline;
58
59
8d41f565 » moritz
2012-01-24 more typed exception tests, better diagnosis
60 throws_like 'sub f(*@a = 2) { }', X::Parameter::Default, how => 'slurpy';
61 throws_like 'sub f($x! = 3) { }', X::Parameter::Default, how => 'required';
62 throws_like 'sub f(:$x! = 3) { }', X::Parameter::Default, how => 'required';
63 throws_like 'sub f($:x) { }', X::Parameter::Placeholder,
64 parameter => '$:x',
65 right => ':$x';
66 throws_like 'sub f($?x) { }', X::Parameter::Twigil,
67 parameter => '$?x',
68 twigil => '?';
a97dc2a5 » moritz
2012-01-26 track change of error class names; add some more redeclaration tests
69 throws_like 'sub (Int Str $x) { }', X::Parameter::MultipleTypeConstraints;
8d41f565 » moritz
2012-01-24 more typed exception tests, better diagnosis
70
71
72
a97dc2a5 » moritz
2012-01-26 track change of error class names; add some more redeclaration tests
73 # some of these redeclaration errors take different code
74 # paths in rakudo, so we over-test a bit to catch them all,
75 # even if the tests look rather boring;
0b7d7d24 » moritz
2012-01-23 more typed exception tests
76 throws_like 'my @a; my @a', X::Redeclaration, symbol => '@a';
77 throws_like 'sub a { }; sub a { }',X::Redeclaration, symbol => 'a', what => 'routine';
63626c2d » moritz
2012-02-08 another redeclaration test
78 throws_like 'sub a { }; multi sub a { }',X::Redeclaration, symbol => 'a', what => 'routine';
a97dc2a5 » moritz
2012-01-26 track change of error class names; add some more redeclaration tests
79 throws_like 'my class A { }; my class A { }', X::Redeclaration, symbol => 'A';
80 throws_like 'my class B { }; my subset B { }', X::Redeclaration, symbol => 'B';
81 throws_like 'CATCH { }; CATCH { }', X::Phaser::Multiple, block => 'CATCH';
fbb78ed5 » moritz
2012-01-23 test for X::Placeholder::Block
82
6467df25 » moritz
2012-02-23 test X::Attribute::Package and X::Attribute::NoPackage
83 throws_like 'my class A { my @a; @a!List::foo() }',
c01e5d67 » moritz
2012-01-24 tests for typed private method call exceptions
84 X::Method::Private::Permission,
85 method => 'foo',
86 calling-package => 'A',
87 source-package => 'List';
88
89 throws_like '1!foo()',
a97dc2a5 » moritz
2012-01-26 track change of error class names; add some more redeclaration tests
90 X::Method::Private::Unqualified,
c01e5d67 » moritz
2012-01-24 tests for typed private method call exceptions
91 method => 'foo';
92
a8246984 » moritz
2012-01-25 typed binding excpetions
93 throws_like 'sub f() { }; f() := 2', X::Bind::WrongLHS;
94 throws_like 'my int $x := 2', X::Bind::NativeType;
95
dc765ebb » moritz
2012-01-25 tests for typed exceptions
96 throws_like 'for (1; 1; 1) { }', X::Obsolete,
97 old => rx/<<for>>/,
98 replacement => rx/<<loop>>/;
99 throws_like 'foreach (1..10) { }', X::Obsolete,
100 old => "'foreach'",
101 replacement => "'for'";
102 throws_like 'undef', X::Obsolete,
103 old => rx/<<undef>>/;
104
a97dc2a5 » moritz
2012-01-26 track change of error class names; add some more redeclaration tests
105 throws_like 'my $a::::b', X::Syntax::Name::Null;
d1f0fd85 » moritz
2012-01-28 tests for typed syntax errors
106 throws_like 'unless 1 { } else { }', X::Syntax::UnlessElse;
107 throws_like 'for my $x (1, 2, 3) { }', X::Syntax::P5;
108 throws_like ':!foo(3)', X::Syntax::NegatedPair;
109 throws_like 'my $0', X::Syntax::Variable::Numeric;
b2914792 » moritz
2012-02-24 test parameter variant of X::Syntax::Variable::Numeric
110 throws_like 'my sub f($0) { }', X::Syntax::Variable::Numeric, what => 'parameter';
d1f0fd85 » moritz
2012-01-28 tests for typed syntax errors
111 throws_like 'my $<a>', X::Syntax::Variable::Match;
33e961e4 » moritz
2012-01-30 RT #69230, my $!foo
112 throws_like 'my class A { my $!foo }', X::Syntax::Variable::Twigil, twigil => '!', scope => 'my';
277e13dd » moritz
2012-01-28 more tests for typed syntax errors
113 throws_like 'my $::("foo")', X::Syntax::Variable::IndirectDeclaration;
171ad0a8 » moritz
2012-02-07 test X::Undeclared
114 throws_like '@a', X::Undeclared, symbol => '@a';
277e13dd » moritz
2012-01-28 more tests for typed syntax errors
115 throws_like 'augment class Any { }', X::Syntax::Augment::WithoutMonkeyTyping;
116 throws_like 'use MONKEY_TYPING; augment role Positional { }', X::Syntax::Augment::Role;
117
118 throws_like 'sub f($a?, $b) { }', X::Parameter::WrongOrder,
119 misplaced => 'required',
120 after => 'optional';
121 throws_like 'sub f(*@a, $b) { }', X::Parameter::WrongOrder,
122 misplaced => 'required',
123 after => 'variadic';
124 throws_like 'sub f(*@a, $b?) { }', X::Parameter::WrongOrder,
125 misplaced => 'optional positional',
126 after => 'variadic';
03faea74 » moritz
2012-01-26 X::Syntax::Name::NotNull
127
2002a2fe » moritz
2012-01-30 more typed exceptions
128 #?rakudo skip 'parsing regression'
129 throws_like '#`', X::Syntax::Comment::Embedded;
1af5f7a9 » moritz
2012-03-02 RT #71814, =begin without identifier
130 # RT #71814
131 throws_like "=begin\n", X::Syntax::Pod::BeginWithoutIdentifier, line => 1, filename => rx/eval/;
2002a2fe » moritz
2012-01-30 more typed exceptions
132
133 throws_like '@', X::Syntax::SigilWithoutName;
134 throws_like '1∞', X::Syntax::Confused;
e4dee679 » moritz
2012-02-23 X::Syntax::Missing
135 throws_like 'for 1, 2', X::Syntax::Missing, what => 'block';
a78af8ce » moritz
2012-02-24 X::Syntax::Reserved
136 throws_like 'my @a()', X::Syntax::Reserved, reserved => /shape/ & /array/;
137 throws_like 'my &a()', X::Syntax::Reserved, instead => /':()'/;
2002a2fe » moritz
2012-01-30 more typed exceptions
138
59f3f35d » moritz
2012-02-08 test exception type for stuff that must be known at compile time
139 throws_like 'm:i(@*ARGS[0])/foo/', X::Value::Dynamic;
140 throws_like 'my enum Foo (:x(@*ARGS[0]))', X::Value::Dynamic;
141
5c0802db » moritz
2012-02-11 more exception tests
142 throws_like 'self', X::Syntax::Self::WithoutObject;
478ed38d » moritz
2012-02-11 more tests for availabilty-of-self related errors
143 throws_like 'class { has $.x = $.y }', X::Syntax::VirtualCall, call => '$.y';
144 throws_like '$.a', X::Syntax::NoSelf, variable => '$.a';
5c0802db » moritz
2012-02-11 more exception tests
145
6467df25 » moritz
2012-02-23 test X::Attribute::Package and X::Attribute::NoPackage
146 throws_like 'has $.x', X::Attribute::NoPackage;
147 throws_like 'my module A { has $.x }', X::Attribute::Package, package-type => 'module';
148
46f9b17d » moritz
2012-03-08 track exception name change, and add another test
149 throws_like 'has sub a() { }', X::Declaration::Scope, scope => 'has', declaration => 'sub';
150 throws_like 'has package a { }', X::Declaration::Scope, scope => 'has', declaration => 'package';
a2b6fc20 » moritz
2012-02-23 more typed exceptions
151 throws_like 'multi sub () { }', X::Anon::Multi, multiness => 'multi';
152 throws_like 'proto sub () { }', X::Anon::Multi, multiness => 'proto';
3b9a6049 » moritz
2012-02-23 more typed exceptions
153 throws_like 'class { multi method () { }}', X::Anon::Multi, routine-type => 'method';
5065e35d » moritz
2012-02-23 test X::Anon::Augment
154 throws_like 'use MONKEY_TYPING; augment class { }', X::Anon::Augment, package-type => 'class';
3804629e » moritz
2012-02-23 test X::Augment::NoSuchType
155 throws_like 'use MONKEY_TYPING; augment class NoSuchClass { }', X::Augment::NoSuchType,
156 package-type => 'class',
157 package => 'NoSuchClass';
3b9a6049 » moritz
2012-02-23 more typed exceptions
158
159 throws_like ':45<abcd>', X::Syntax::Number::RadixOutOfRange, radix => 45;
dc3de2d6 » moritz
2012-02-24 X::Syntax::Regex::Adverb
160 throws_like 'rx:g/a/', X::Syntax::Regex::Adverb, adverb => 'g', construct => 'rx';
26f68343 » moritz
2012-02-26 X::Syntax::Signature::InvocantMarker
161 throws_like 'my sub f($x, $y:) { }', X::Syntax::Signature::InvocantMarker;
a2b6fc20 » moritz
2012-02-23 more typed exceptions
162
1bf4f1dc » moritz
2012-02-26 X::OutOfRange
163 throws_like 'Date.new("2012-02-30")', X::OutOfRange,
164 range => Range, message => rx/<<1\.\.29>>/;
165
52f6db64 » moritz
2012-02-27 test for X::Routine::Unwrap
166 throws_like 'sub f() { }; &f.unwrap("foo")', X::Routine::Unwrap;
44d0aa37 » moritz
2012-02-27 test X::Constructor::Positional
167 throws_like 'Mu.new(1)', X::Constructor::Positional;
39b3eb78 » Siddhant
2012-02-28 add test for X::Hash::Store::Oddnumber
168 throws_like 'my %h = 1', X::Hash::Store::OddNumber;
52f6db64 » moritz
2012-02-27 test for X::Routine::Unwrap
169
fcd16681 » moritz
2012-03-02 Test for proper error of "sub foo;", RT #68710 and RT #111492
170 # TOOD: might be X::Syntax::Malformed too...
171 throws_like 'sub foo;', X::Syntax::Missing, what => 'block';
157d7b7c » moritz
2012-03-03 more tests for "constant" parse errors
172 throws_like 'constant foo;', X::Syntax::Missing, what => /initializer/;
173 throws_like 'constant * = 3;', X::Syntax::Missing, what => /constant/;
fcd16681 » moritz
2012-03-02 Test for proper error of "sub foo;", RT #68710 and RT #111492
174
ddc21bfd » moritz
2012-03-08 test X::Package::Stubbed
175 throws_like 'class A {...}; grammar B { ... }', X::Package::Stubbed, packages => <A B>;
176
3d3f9a24 » moritz
2011-12-17 initial tests for typed exceptions; very unstructured for now
177 done;
Something went wrong with that request. Please try again.