This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mktables: Fix-up for Unicode version 1
[perl5.git] / lib / diagnostics.t
CommitLineData
00680da2 1#!./perl -w
f5ad5489
GS
2
3BEGIN {
7b903762
RGS
4 chdir '..' if -d '../pod' && -d '../t';
5 @INC = 'lib';
f63ff350 6 require './t/test.pl';
245e6c67 7 plan(18);
f5ad5489
GS
8}
9
00680da2
FC
10BEGIN {
11 my $w;
12 $SIG{__WARN__} = sub { $w = shift };
13 use_ok('diagnostics');
14 is $w, undef, 'no warnings when loading diagnostics.pm';
15}
f5ad5489 16
d23f0205 17require base;
f5ad5489 18
d23f0205
MS
19eval {
20 'base'->import(qw(I::do::not::exist));
21};
f5ad5489 22
f0e510f6 23like( $@, qr/^Base class package "I::do::not::exist" is empty/);
8b56d6ff 24
2dde0467 25open *whatever, ">", \my $warning
8b56d6ff 26 or die "Couldn't redirect STDERR to var: $!";
2dde0467
FC
27my $old_stderr = *STDERR{IO};
28*STDERR = *whatever{IO};
29
30# Test for %.0f patterns in perldiag, added in 5.11.0
8b56d6ff
FC
31warn('gmtime(nan) too large');
32like $warning, qr/\(W overflow\) You called/, '%0.f patterns';
4b056c06
FC
33
34# L<foo/bar> links
35seek STDERR, 0,0;
36$warning = '';
37warn("accept() on closed socket spanner");
38like $warning, qr/"accept" in perlfunc/, 'L<foo/bar> links';
39
40# L<foo|bar/baz> links
41seek STDERR, 0,0;
42$warning = '';
43warn
44 'Lexing code attempted to stuff non-Latin-1 character into Latin-1 input';
c58550c3 45like $warning, qr/using lex_stuff_pvn or similar/, 'L<foo|bar/baz>';
f4739a71
FC
46
47# Multiple messages with the same description
48seek STDERR, 0,0;
49$warning = '';
b6a06234 50warn 'Code point 0xBEE5 is not Unicode, may not be portable';
f4739a71
FC
51like $warning, qr/W utf8/,
52 'Message sharing its description with the following message';
53
c0d3a21f
MH
54# Periods at end of entries in perldiag.pod get matched correctly
55seek STDERR, 0,0;
56$warning = '';
57warn "Execution of -e aborted due to compilation errors.\n";
58like $warning, qr/The final summary message/, 'Periods at end of line';
e958e573 59
e958e573
MH
60# Test for %d/%u
61seek STDERR, 0,0;
62$warning = '';
63warn "Bad arg length for us, is 4, should be 42";
64like $warning, qr/In C parlance/, '%u works';
524e9188 65
b6a06234
FC
66# Test for %X
67seek STDERR, 0,0;
68$warning = '';
69warn "Unicode surrogate U+C0FFEE is illegal in UTF-8";
70like $warning, qr/You had a UTF-16 surrogate/, '%X';
71
524e9188
MH
72# Strip S<>
73seek STDERR, 0,0;
74$warning = '';
75warn "syntax error";
76like $warning, qr/cybernetic version of 20 questions/s, 'strip S<>';
2dde0467 77
33327ed8
FC
78# Errors ending with dots
79seek STDERR, 0,0;
80$warning = '';
0a437bc9
FC
81warn "I had compilation errors.\n";
82like $warning, qr/final summary message/, 'dotty errors';
83
84# Multiline errors
85seek STDERR, 0,0;
86$warning = '';
87warn "Attempt to reload weapon aborted.\nCompilation failed in require";
88like $warning,
89 qr/You tried to load a file.*Perl could not compile/s,
90 'multiline errors';
33327ed8 91
2dde0467
FC
92*STDERR = $old_stderr;
93
94# These tests use a panic under the hope that the description is not likely
95# to change.
96@runperl_args = (
97 switches => [ '-Ilib', '-Mdiagnostics' ],
98 stderr => 1,
99 nolib => 1, # -I../lib would go outside the build dir
100);
101$subs =
102 "sub foo{bar()}sub bar{baz()}sub baz{die q _panic: gremlins_}foo()";
103is runperl(@runperl_args, prog => $subs),
104 << 'EOT', 'internal error with backtrace';
105panic: gremlins at -e line 1 (#1)
106 (P) An internal error.
107
108Uncaught exception from user code:
109 panic: gremlins at -e line 1.
110 main::baz() called at -e line 1
111 main::bar() called at -e line 1
112 main::foo() called at -e line 1
113EOT
114is runperl(@runperl_args, prog => $subs =~ s/panic\K/k/r),
115 << 'EOU', 'user error with backtrace';
116Uncaught exception from user code:
117 panick: gremlins at -e line 1.
118 main::baz() called at -e line 1
119 main::bar() called at -e line 1
120 main::foo() called at -e line 1
121EOU
122is runperl(@runperl_args, prog => 'die q _panic: gremlins_'),
123 << 'EOV', 'no backtrace from top-level internal error';
124panic: gremlins at -e line 1 (#1)
125 (P) An internal error.
126
127Uncaught exception from user code:
128 panic: gremlins at -e line 1.
129EOV
130is runperl(@runperl_args, prog => 'die q _panick: gremlins_'),
131 << 'EOW', 'no backtrace from top-level user error';
132Uncaught exception from user code:
133 panick: gremlins at -e line 1.
134EOW
245e6c67
FC
135like runperl(
136 @runperl_args,
137 prog => $subs =~
f5aea3e0
NC
138 s[q _panic: gremlins_]
139 [qq _Attempt to reload foo aborted.\\nCompilation failed in require_]r,
245e6c67
FC
140 ),
141 qr/Uncaught exception from user code:
142 Attempt to reload foo aborted\.
143 Compilation failed in require at -e line \d+\.
144 main::baz\(\) called at -e line \d+
145 main::bar\(\) called at -e line \d+
146 main::foo\(\) called at -e line \d+
147/, 'backtrace from multiline error';