4 chdir '..' if -d '../pod' && -d '../t';
12 $SIG{__WARN__} = sub { $w = shift };
13 use_ok('diagnostics');
14 is $w, undef, 'no warnings when loading diagnostics.pm';
20 'base'->import(qw(I::do::not::exist));
23 like( $@, qr/^Base class package "I::do::not::exist" is empty/,
24 'diagnostics not tripped up by "use base qw(Dont::Exist)"');
26 open *whatever, ">", \my $warning
27 or die "Couldn't redirect STDERR to var: $!";
28 my $old_stderr = *STDERR{IO};
29 *STDERR = *whatever{IO};
31 # Test for %.0f patterns in perldiag, added in 5.11.0
32 warn('gmtime(nan) too large');
33 like $warning, qr/\(W overflow\) You called/, '%0.f patterns';
38 warn("accept() on closed socket spanner");
39 like $warning, qr/"accept" in perlfunc/, 'L<foo/bar> links';
41 # L<foo|bar/baz> links
45 'Lexing code attempted to stuff non-Latin-1 character into Latin-1 input';
46 like $warning, qr/lex_stuff_pvn or similar/, 'L<foo|bar/baz>';
48 # Multiple messages with the same description
51 warn 'Code point 0xBEE5 is not Unicode, may not be portable';
52 like $warning, qr/S utf8/,
53 'Message sharing its description with the following message';
55 # Periods at end of entries in perldiag.pod get matched correctly
58 warn "Execution of -e aborted due to compilation errors.\n";
59 like $warning, qr/The final summary message/, 'Periods at end of line';
64 warn "Bad arg length for us, is 4, should be 42";
65 like $warning, qr/In C parlance/, '%u works';
70 warn "Unicode surrogate U+C0FFEE is illegal in UTF-8";
71 like $warning, qr/You had a UTF-16 surrogate/, '%X';
76 warn "Slab leaked from cv fadedc0ffee";
77 like $warning, qr/bookkeeping of op trees/, '%p';
83 like $warning, qr/cybernetic version of 20 questions/s, 'strip S<>';
85 # Errors ending with dots
88 warn "I had compilation errors.\n";
89 like $warning, qr/final summary message/, 'dotty errors';
94 warn "Attempt to reload weapon aborted.\nCompilation failed in require";
96 qr/You tried to load a file.*Perl could not compile/s,
99 # Multiline entry in perldiag.pod
102 warn "Using just the first character returned by \\N{} in character class in regex; marked by <-- HERE in m/%s/";
104 qr/A charnames handler may return a sequence/s,
105 'multi-line entries in perldiag.pod match';
107 # ; at end of entry in perldiag.pod
110 warn "Perl folding rules are not up-to-date for 0xA; please use the perlbug utility to report; in regex; marked by <-- HERE in m/\ <-- HERE q/";
112 qr/You used a regular expression with case-insensitive matching/s,
113 '; works at the end of entries in perldiag.pod';
115 # Differences in spaces in warnings (Why not be nice and accept them?)
118 warn "Assignment to both a list and a scalar\n";
121 'spaces in warnings are matched lightly';
123 # Differences in spaces in warnings with a period at the end
126 warn "perl: warning: Setting locale failed.\n";
128 qr/The whole warning/s,
129 'spaces in warnings with periods at the end are matched lightly';
132 *STDERR = $old_stderr;
134 # These tests use a panic under the hope that the description is not likely
137 switches => [ '-Ilib', '-Mdiagnostics' ],
139 nolib => 1, # -I../lib would go outside the build dir
142 "sub foo{bar()}sub bar{baz()}sub baz{die q _panic: gremlins_}foo()";
143 is runperl(@runperl_args, prog => $subs),
144 << 'EOT', 'internal error with backtrace';
145 panic: gremlins at -e line 1 (#1)
146 (P) An internal error.
148 Uncaught exception from user code:
149 panic: gremlins at -e line 1.
150 main::baz() called at -e line 1
151 main::bar() called at -e line 1
152 main::foo() called at -e line 1
154 is runperl(@runperl_args, prog => $subs =~ s/panic\K/k/r),
155 << 'EOU', 'user error with backtrace';
156 Uncaught exception from user code:
157 panick: gremlins at -e line 1.
158 main::baz() called at -e line 1
159 main::bar() called at -e line 1
160 main::foo() called at -e line 1
162 is runperl(@runperl_args, prog => 'die q _panic: gremlins_'),
163 << 'EOV', 'no backtrace from top-level internal error';
164 panic: gremlins at -e line 1 (#1)
165 (P) An internal error.
167 Uncaught exception from user code:
168 panic: gremlins at -e line 1.
170 is runperl(@runperl_args, prog => 'die q _panick: gremlins_'),
171 << 'EOW', 'no backtrace from top-level user error';
172 Uncaught exception from user code:
173 panick: gremlins at -e line 1.
178 s[q _panic: gremlins_]
179 [qq _Attempt to reload foo aborted.\\nCompilation failed in require_]r,
181 qr/Uncaught exception from user code:
182 Attempt to reload foo aborted\.
183 Compilation failed in require at -e line \d+\.
184 main::baz\(\) called at -e line \d+
185 main::bar\(\) called at -e line \d+
186 main::foo\(\) called at -e line \d+
187 /, 'backtrace from multiline error';
188 is runperl(@runperl_args, prog => 'BEGIN { die q _panic: gremlins_ }'),
189 << 'EOX', 'BEGIN{die} does not suppress diagnostics';
190 panic: gremlins at -e line 1.
191 BEGIN failed--compilation aborted at -e line 1 (#1)
192 (P) An internal error.
194 Uncaught exception from user code:
195 panic: gremlins at -e line 1.
196 BEGIN failed--compilation aborted at -e line 1.