/
exceptions.t
71 lines (54 loc) · 2.59 KB
/
exceptions.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use Spit::Compile;
use Test;
use Spit::Exceptions;
use Spit::Util :colorstrip;
plan 14;
my $name = 'syntax-tests';
throws-like { compile( '"', :$name) },
SX::Unbalanced,'stray "',
message => q|Couldn't find closing ‘"’ to finish double-quoted string|;
throws-like { compile( '"foo', :$name ) },
SX::Unbalanced, 'unfinished "',
message => q<Couldn't find closing ‘"’ to finish double-quoted string>;
throws-like { compile('foo',:$name) },
SX::Undeclared,'undeclared sub',
message => q|Sub 'foo' hasn't been declared.|;
throws-like { compile('foo "bar"',:$name) },
SX::Undeclared,'undeclared sub with arg',
message => q|Sub 'foo' hasn't been declared.|;
throws-like { compile('foo()',:$name) },
SX::Undeclared,'undeclared sub()',
message => q|Sub 'foo' hasn't been declared.|;
# throws-like { compile('Foo',:$name) },
# SX::Undeclared,'undeclared class',
# message => "name 'Foo' hasn't been declared.";
throws-like { compile('say $:foo',:$name) },
SX::Undeclared,'undeclared option',
message => "Option 'foo' hasn't been declared.";
throws-like { compile('my $:foo is required; say $:foo', :$name) },
SX::RequiredOption,"required option not set";
throws-like { compile('sub foo($a,$b) { }; foo("bar")',:$name)},
SX::BadCall,"too few arguments",
gist => *.&colorstrip.contains('foo("bar", $b↩)');
throws-like { compile('sub foo($a,*@b) { }; foo()',:$name)},
SX::BadCall::WrongNumber, "too few arguments with slurpy",
gist => *.&colorstrip.contains('foo($a↩)'),
message => *.contains('at least 1');
throws-like { compile('sub foo(Int $a = "foo"){ }', :$name) },
SX::TypeCheck, "default value incompatible with parameter default type";
throws-like { compile('sub foo($a,$b) { }; foo("foo","bar","baz")',:$name) },
SX::BadCall,"too many arguments",
gist => *.&colorstrip.contains('foo("foo","bar","baz")');
throws-like { compile('my $a = "foo"; $a .= "foo".${cat}',:$name) },
SX::Invalid, '.= to a command that already has input';
throws-like {
compile name => 'parameterized class bad call',
q:to/END/;
class Foo[Type] {
static method echo(Type $a)-->Type { $a }
}
Foo[Int].echo("blah");
END
}, SX::TypeCheck,"wrong type of argument to parameterized class method";
throws-like { compile('say "foo"; say "bar"; }', name => "unbalanced }") },
SX::Unexpected, 'unbalanced }';