-
Notifications
You must be signed in to change notification settings - Fork 3
/
exceptions.t
122 lines (112 loc) · 2.56 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env perl6
use v6;
use Test;
use Inline::Perl5;
my $p5 = Inline::Perl5.new();
{
try $p5.run(q/
die "foo";
/);
ok 1, 'survived P5 die';
ok $!.isa('X::AdHoc'), 'got an exception';
ok $!.Str() ~~ m/foo/, 'exception message found';
}
{
$p5.run(q/
sub perish {
die "foo";
}
/);
try $p5.call('perish');
ok 1, 'survived P5 die in function call';
ok $!.isa('X::AdHoc'), 'got an exception from function call';
ok $!.Str() ~~ m/foo/, 'exception message found from function call';
}
{
$p5.run(q/
package Foo;
sub depart {
die "foo";
}
/);
my $foo = $p5.invoke('Foo', 'depart');
CATCH {
ok 1, 'survived P5 die in method call';
when X::AdHoc {
ok $_.isa('X::AdHoc'), 'got an exception from method call';
ok $_.Str() ~~ m/foo/, 'exception message found from method call';
}
}
}
{
$p5.run(q/
package Foo;
sub new {
return bless {};
}
sub depart {
die "foo";
}
/);
my $foo = $p5.invoke('Foo', 'new');
$foo.depart;
CATCH {
ok 1, 'survived P5 die in method call';
when X::AdHoc {
ok $_.isa('X::AdHoc'), 'got an exception from method call';
ok $_.Str() ~~ m/foo/, 'exception message found from method call';
}
}
}
{
$p5.run(q/
package Foo;
sub new {
return bless {};
}
/);
my $foo = $p5.invoke('Foo', 'new');
$foo.non_existing;
CATCH {
ok 1, 'survived P5 missing method';
when X::AdHoc {
ok $_.isa('X::AdHoc'), 'got an exception from method call';
ok $_.Str().index('Could not find method "non_existing" of "Foo" object') == 0, 'exception message found from method call';
}
}
}
class Foo {
method depart {
die "foo";
}
}
$p5.run(q/
sub test_foo {
my ($foo) = @_;
eval {
$foo->depart;
};
if ($@) {
return $@;
}
}
/);
is $p5.call('test_foo', Foo.new), 'foo';
{
$p5.run(q/
sub pass_through {
my ($foo) = @_;
$foo->depart;
}
/);
$p5.call('pass_through', Foo.new);
CATCH {
ok 1, 'P6 exception made it through P5 code';
when X::AdHoc {
ok $_.isa('X::AdHoc'), 'got an exception from method call';
ok $_.Str() ~~ m/foo/, 'exception message found from method call';
}
}
}
done-testing;
# vim: ft=perl6