Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 41 lines (35 sloc) 1.177 kb
3d3f9a2 @moritz initial tests for typed exceptions; very unstructured for now
moritz authored
1 use v6;
2 use Test;
3
4 sub throws_like($code, $ex_type, *%matcher) {
5 if $code ~~ Callable {
6 $code()
7 } else {
8 eval $code;
9 }
10 ok 0, 'code died';
11 skip 'Code did not die, can not check exception', 1 + %matcher.elems;
12 CATCH {
13 default {
14 ok 1, 'code died';
4c68d1a @moritz skipped tests for X::Obsolete
moritz authored
15 my $type_ok = $_.WHAT === $ex_type;
16 ok $type_ok , "right exception type ({$ex_type.^name})";
17 if $type_ok {
18 for %matcher.kv -> $k, $v {
19 ok $_."$k"() ~~ $v, " .$k matches $v";
20 }
21 } else {
22 skip 'wrong exception type', %matcher.elems;
3d3f9a2 @moritz initial tests for typed exceptions; very unstructured for now
moritz authored
23 }
24 }
25 }
26 }
27
28 throws_like { Buf.new().Str }, X::Buf::AsStr, method => 'Str';
29 throws_like 'class Foo { $!bar }', X::Attribute::Undeclared,
30 name => '$!bar', package-name => 'Foo';
31 throws_like 'sub f() { $^x }', X::Signature::Placeholder,
32 line => 1;
33
4c68d1a @moritz skipped tests for X::Obsolete
moritz authored
34 #?rakudo skip 'parsing of $& and other p5 variables'
35 throws_like '$&', X::Obsolete, old => '$@ variable', new => '$/ or $()';
36
fbb78ed @moritz test for X::Placeholder::Block
moritz authored
37 throws_like 'do { $^x }', X::Placeholder::Block;
38 throws_like 'class { $^x }', X::Placeholder::Block;
39
3d3f9a2 @moritz initial tests for typed exceptions; very unstructured for now
moritz authored
40 done;
Something went wrong with that request. Please try again.