Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 134 lines (116 sloc) 5.139 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
30 }
4c68d1a5 » moritz
2011-12-18 skipped tests for X::Obsolete
31 }
32 } else {
8d41f565 » moritz
2012-01-24 more typed exception tests, better diagnosis
33 diag "Got: {$_.WHAT.gist}\n"
34 ~"Expected: {$ex_type.gist}";
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';
42 throws_like 'class Foo { $!bar }', X::Attribute::Undeclared,
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 => '@_';
8d41f565 » moritz
2012-01-24 more typed exception tests, better diagnosis
56 throws_like 'sub f(*@a = 2) { }', X::Parameter::Default, how => 'slurpy';
57 throws_like 'sub f($x! = 3) { }', X::Parameter::Default, how => 'required';
58 throws_like 'sub f(:$x! = 3) { }', X::Parameter::Default, how => 'required';
59 throws_like 'sub f($:x) { }', X::Parameter::Placeholder,
60 parameter => '$:x',
61 right => ':$x';
62 throws_like 'sub f($?x) { }', X::Parameter::Twigil,
63 parameter => '$?x',
64 twigil => '?';
a97dc2a5 » moritz
2012-01-26 track change of error class names; add some more redeclaration tests
65 throws_like 'sub (Int Str $x) { }', X::Parameter::MultipleTypeConstraints;
8d41f565 » moritz
2012-01-24 more typed exception tests, better diagnosis
66
67
68
a97dc2a5 » moritz
2012-01-26 track change of error class names; add some more redeclaration tests
69 # some of these redeclaration errors take different code
70 # paths in rakudo, so we over-test a bit to catch them all,
71 # even if the tests look rather boring;
0b7d7d24 » moritz
2012-01-23 more typed exception tests
72 throws_like 'my @a; my @a', X::Redeclaration, symbol => '@a';
73 throws_like 'sub a { }; sub a { }',X::Redeclaration, symbol => 'a', what => 'routine';
63626c2d » moritz
2012-02-08 another redeclaration test
74 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
75 throws_like 'my class A { }; my class A { }', X::Redeclaration, symbol => 'A';
76 throws_like 'my class B { }; my subset B { }', X::Redeclaration, symbol => 'B';
77 throws_like 'CATCH { }; CATCH { }', X::Phaser::Multiple, block => 'CATCH';
fbb78ed5 » moritz
2012-01-23 test for X::Placeholder::Block
78
c01e5d67 » moritz
2012-01-24 tests for typed private method call exceptions
79 throws_like 'class A { my @a; @a!List::foo() }',
80 X::Method::Private::Permission,
81 method => 'foo',
82 calling-package => 'A',
83 source-package => 'List';
84
85 throws_like '1!foo()',
a97dc2a5 » moritz
2012-01-26 track change of error class names; add some more redeclaration tests
86 X::Method::Private::Unqualified,
c01e5d67 » moritz
2012-01-24 tests for typed private method call exceptions
87 method => 'foo';
88
a8246984 » moritz
2012-01-25 typed binding excpetions
89 throws_like 'sub f() { }; f() := 2', X::Bind::WrongLHS;
90 throws_like 'my int $x := 2', X::Bind::NativeType;
91
dc765ebb » moritz
2012-01-25 tests for typed exceptions
92 throws_like 'for (1; 1; 1) { }', X::Obsolete,
93 old => rx/<<for>>/,
94 replacement => rx/<<loop>>/;
95 throws_like 'foreach (1..10) { }', X::Obsolete,
96 old => "'foreach'",
97 replacement => "'for'";
98 throws_like 'undef', X::Obsolete,
99 old => rx/<<undef>>/;
100
a97dc2a5 » moritz
2012-01-26 track change of error class names; add some more redeclaration tests
101 throws_like 'my $a::::b', X::Syntax::Name::Null;
d1f0fd85 » moritz
2012-01-28 tests for typed syntax errors
102 throws_like 'unless 1 { } else { }', X::Syntax::UnlessElse;
103 throws_like 'for my $x (1, 2, 3) { }', X::Syntax::P5;
104 throws_like ':!foo(3)', X::Syntax::NegatedPair;
105 throws_like 'my $0', X::Syntax::Variable::Numeric;
106 throws_like 'my $<a>', X::Syntax::Variable::Match;
33e961e4 » moritz
2012-01-30 RT #69230, my $!foo
107 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
108 throws_like 'my $::("foo")', X::Syntax::Variable::IndirectDeclaration;
171ad0a8 » moritz
2012-02-07 test X::Undeclared
109 throws_like '@a', X::Undeclared, symbol => '@a';
277e13dd » moritz
2012-01-28 more tests for typed syntax errors
110 throws_like 'augment class Any { }', X::Syntax::Augment::WithoutMonkeyTyping;
111 throws_like 'use MONKEY_TYPING; augment role Positional { }', X::Syntax::Augment::Role;
112
113 throws_like 'sub f($a?, $b) { }', X::Parameter::WrongOrder,
114 misplaced => 'required',
115 after => 'optional';
116 throws_like 'sub f(*@a, $b) { }', X::Parameter::WrongOrder,
117 misplaced => 'required',
118 after => 'variadic';
119 throws_like 'sub f(*@a, $b?) { }', X::Parameter::WrongOrder,
120 misplaced => 'optional positional',
121 after => 'variadic';
03faea74 » moritz
2012-01-26 X::Syntax::Name::NotNull
122
2002a2fe » moritz
2012-01-30 more typed exceptions
123 #?rakudo skip 'parsing regression'
124 throws_like '#`', X::Syntax::Comment::Embedded;
125 #?rakudo skip 'parsing regression'
126 throws_like '=begin', X::Syntax::Pod::BeginWithoutIdentifier;
127
128 throws_like '@', X::Syntax::SigilWithoutName;
129 throws_like '1∞', X::Syntax::Confused;
130
59f3f35d » moritz
2012-02-08 test exception type for stuff that must be known at compile time
131 throws_like 'm:i(@*ARGS[0])/foo/', X::Value::Dynamic;
132 throws_like 'my enum Foo (:x(@*ARGS[0]))', X::Value::Dynamic;
133
3d3f9a24 » moritz
2011-12-17 initial tests for typed exceptions; very unstructured for now
134 done;
Something went wrong with that request. Please try again.