/
error-reporting.t
181 lines (152 loc) · 4.37 KB
/
error-reporting.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use v6;
use Test;
plan 21;
use lib 't/spec/packages';
use Test::Util;
is_run "use v6;\n'a' =~ /foo/", {
status => { $_ != 0 },
out => '',
err => rx/<<2>>/
}, 'Parse error contains line number';
is_run "my \$x = 2 * 3;\ndie \$x", {
status => { $_ != 0 },
out => '',
err => all(rx/6/, rx/<<2>>/),
}, 'Runtime error contains line number';
is_run "use v6;\n\nsay 'Hello';\nsay 'a'.my_non_existent_method_6R5();",
{
status => { $_ != 0 },
out => /Hello\r?\n/,
err => all(rx/my_non_existent_method_6R5/, rx/<<4>>/),
}, 'Method not found error mentions method name and line number';
# RT #75446
is_run 'use v6;
sub bar {
pfff();
}
bar()',
{
status => { $_ != 0 },
out => '',
err => all(rx/pfff/, rx/<<3>>/),
}, 'got the right line number for nonexisting sub inside another sub';
is_run 'say 42; nosuchsub()',
{
status => { $_ != 0 },
out => '',
err => rx/nosuchsub/,
},
'non-existing subroutine is caught before run time';
# RT #74348
{
subset Even of Int where { $_ %% 2 };
sub f(Even $x) { $x };
try { EVAL 'f(3)' };
my $e = "$!";
diag "Error message: $e";
ok $e ~~ /:i 'type check'/,
'subset type check fail mentions type check';
ok $e ~~ /:i constraint/,
'subset type check fail mentions constraint';
}
# RT #76112
is_run 'use v6;
class A { has $.x is rw };
A.new.x(42);',
{
status => { $_ != 0 },
out => '',
err => rx/<<3>>/,
}, 'got the right line number for accessors';
# RT #80982
is_run 'say 0080982',
{
status => 0,
out => "80982\n",
err => rx/ octal /,
}, 'use of leading zero causes warning about octal';
# RT #76986
#?niecza todo
is_run 'my $ = 2; my $ = 3; say q[alive]',
{
status => 0,
err => '',
out => "alive\n",
}, 'multiple anonymous variables do not warn or err out';
# RT #112724
#?rakudo.jvm todo "nigh"
#?rakudo.moar todo "nigh"
is_run 'sub mysub {
+ Any # trigger an uninitialized warning
};
mysub()',
{
status => 0,
err => /<<2>>/ & /<<mysub>>/,
out => '',
}, 'warning reports correct line number and subroutine';
# RT #77736
#?niecza todo
is_run 'die "foo"; END { say "end run" }',
{
status => * != 0,
err => rx/foo/,
out => "end run\n",
},
'END phasers are run after die()';
# RT #113848
{
try EVAL 'use v6; # line 1
# another line so we three in total
(1 + 2) = 3; # line 3
';
#?niecza skip "Unable to resolve method backtrace in type Str"
ok ?( $!.backtrace.any.line == 3),
'correct line number reported for assignment to non-variable';
}
# RT #103034
#?niecza skip 'sub ucfirst($thing) is export(:DEFAULT) blows up'
#?DOES 3
{
use lib 't/spec/packages';
use Foo;
try dies();
ok $!, 'RT 103034 -- died';
my $bt = $!.backtrace;
ok any($bt>>.file) ~~ /Foo\.pm/, 'found original file name in the backtrace';
# note that fudging can change the file extension, so don't check
# for .t here
ok any($bt>>.file) ~~ /'error-reporting'\./, 'found script file name in the backtrace';
}
my $b = Backtrace.new;
ok $b.full eq $b.full eq $b.full, "Backtrace may be used more than once";
my $b1;
my $b2;
sub a {
{
try die("foo");
$b1 = $!.backtrace;
}
$b2 = $!.backtrace;
};
a();
ok $b1 === $b2, "Backtrace does not change on additional .backtrace";
# RT #125495
{
is_run 'class RT125495 {
sub foo( $class, \@args, $object_name ) is export { 42 }
}',
{
status => { $_ != 0 },
out => '',
err => all(rx:i/obsolete/, rx/'at' \N+ ':2'/),
}, 'Error for obsolete syntax contains line number';
}
is_run 'sub s1 { sub s2 { fail("foo"); }; s2()(); }; s1();', {
err => rx/sub\ss2.*sub\ss1.*thrown<-[s]>+sub\ss1/
}, "Thrown Failure outputs dual backtraces";
# see http://irclog.perlgeek.de/perl6/2015-07-24#i_10947364 and commit c683fe9
is_run 'sub foo { ({a=>1,b=>2}, {c=>3,d=>4}).map({ if (.<a>) {return $_} else { return } }) }; say foo', {
err => rx:i/Attempt\sto\sreturn\soutside\N+Routine.*in\sblock/
}, "Correct error and a backtrace for return in mainline code";
# vim: ft=perl6