Commit | Line | Data |
---|---|---|
00680da2 | 1 | #!./perl -w |
f5ad5489 GS |
2 | |
3 | BEGIN { | |
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 |
10 | BEGIN { |
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 | 17 | require base; |
f5ad5489 | 18 | |
d23f0205 MS |
19 | eval { |
20 | 'base'->import(qw(I::do::not::exist)); | |
21 | }; | |
f5ad5489 | 22 | |
f0e510f6 | 23 | like( $@, qr/^Base class package "I::do::not::exist" is empty/); |
8b56d6ff | 24 | |
2dde0467 | 25 | open *whatever, ">", \my $warning |
8b56d6ff | 26 | or die "Couldn't redirect STDERR to var: $!"; |
2dde0467 FC |
27 | my $old_stderr = *STDERR{IO}; |
28 | *STDERR = *whatever{IO}; | |
29 | ||
30 | # Test for %.0f patterns in perldiag, added in 5.11.0 | |
8b56d6ff FC |
31 | warn('gmtime(nan) too large'); |
32 | like $warning, qr/\(W overflow\) You called/, '%0.f patterns'; | |
4b056c06 FC |
33 | |
34 | # L<foo/bar> links | |
35 | seek STDERR, 0,0; | |
36 | $warning = ''; | |
37 | warn("accept() on closed socket spanner"); | |
38 | like $warning, qr/"accept" in perlfunc/, 'L<foo/bar> links'; | |
39 | ||
40 | # L<foo|bar/baz> links | |
41 | seek STDERR, 0,0; | |
42 | $warning = ''; | |
43 | warn | |
44 | 'Lexing code attempted to stuff non-Latin-1 character into Latin-1 input'; | |
c58550c3 | 45 | like $warning, qr/using lex_stuff_pvn or similar/, 'L<foo|bar/baz>'; |
f4739a71 FC |
46 | |
47 | # Multiple messages with the same description | |
48 | seek STDERR, 0,0; | |
49 | $warning = ''; | |
b6a06234 | 50 | warn 'Code point 0xBEE5 is not Unicode, may not be portable'; |
f4739a71 FC |
51 | like $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 |
55 | seek STDERR, 0,0; | |
56 | $warning = ''; | |
57 | warn "Execution of -e aborted due to compilation errors.\n"; | |
58 | like $warning, qr/The final summary message/, 'Periods at end of line'; | |
e958e573 | 59 | |
e958e573 MH |
60 | # Test for %d/%u |
61 | seek STDERR, 0,0; | |
62 | $warning = ''; | |
63 | warn "Bad arg length for us, is 4, should be 42"; | |
64 | like $warning, qr/In C parlance/, '%u works'; | |
524e9188 | 65 | |
b6a06234 FC |
66 | # Test for %X |
67 | seek STDERR, 0,0; | |
68 | $warning = ''; | |
69 | warn "Unicode surrogate U+C0FFEE is illegal in UTF-8"; | |
70 | like $warning, qr/You had a UTF-16 surrogate/, '%X'; | |
71 | ||
524e9188 MH |
72 | # Strip S<> |
73 | seek STDERR, 0,0; | |
74 | $warning = ''; | |
75 | warn "syntax error"; | |
76 | like $warning, qr/cybernetic version of 20 questions/s, 'strip S<>'; | |
2dde0467 | 77 | |
33327ed8 FC |
78 | # Errors ending with dots |
79 | seek STDERR, 0,0; | |
80 | $warning = ''; | |
0a437bc9 FC |
81 | warn "I had compilation errors.\n"; |
82 | like $warning, qr/final summary message/, 'dotty errors'; | |
83 | ||
84 | # Multiline errors | |
85 | seek STDERR, 0,0; | |
86 | $warning = ''; | |
87 | warn "Attempt to reload weapon aborted.\nCompilation failed in require"; | |
88 | like $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()"; | |
103 | is runperl(@runperl_args, prog => $subs), | |
104 | << 'EOT', 'internal error with backtrace'; | |
105 | panic: gremlins at -e line 1 (#1) | |
106 | (P) An internal error. | |
107 | ||
108 | Uncaught 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 | |
113 | EOT | |
114 | is runperl(@runperl_args, prog => $subs =~ s/panic\K/k/r), | |
115 | << 'EOU', 'user error with backtrace'; | |
116 | Uncaught 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 | |
121 | EOU | |
122 | is runperl(@runperl_args, prog => 'die q _panic: gremlins_'), | |
123 | << 'EOV', 'no backtrace from top-level internal error'; | |
124 | panic: gremlins at -e line 1 (#1) | |
125 | (P) An internal error. | |
126 | ||
127 | Uncaught exception from user code: | |
128 | panic: gremlins at -e line 1. | |
129 | EOV | |
130 | is runperl(@runperl_args, prog => 'die q _panick: gremlins_'), | |
131 | << 'EOW', 'no backtrace from top-level user error'; | |
132 | Uncaught exception from user code: | |
133 | panick: gremlins at -e line 1. | |
134 | EOW | |
245e6c67 FC |
135 | like 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'; |