This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Strip S<> formatting codes from diagnostics output
[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';
f5ad5489
GS
6}
7
524e9188 8use Test::More tests => 10;
f5ad5489 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
FC
24
25# Test for %.0f patterns in perldiag, added in 5.11.0
26close STDERR;
27open STDERR, ">", \my $warning
28 or die "Couldn't redirect STDERR to var: $!";
29warn('gmtime(nan) too large');
30like $warning, qr/\(W overflow\) You called/, '%0.f patterns';
4b056c06
FC
31
32# L<foo/bar> links
33seek STDERR, 0,0;
34$warning = '';
35warn("accept() on closed socket spanner");
36like $warning, qr/"accept" in perlfunc/, 'L<foo/bar> links';
37
38# L<foo|bar/baz> links
39seek STDERR, 0,0;
40$warning = '';
41warn
42 'Lexing code attempted to stuff non-Latin-1 character into Latin-1 input';
c58550c3 43like $warning, qr/using lex_stuff_pvn or similar/, 'L<foo|bar/baz>';
f4739a71
FC
44
45# Multiple messages with the same description
46seek STDERR, 0,0;
47$warning = '';
48warn 'Code point 0x%X is not Unicode, may not be portable';
49like $warning, qr/W utf8/,
50 'Message sharing its description with the following message';
51
c0d3a21f
MH
52# Periods at end of entries in perldiag.pod get matched correctly
53seek STDERR, 0,0;
54$warning = '';
55warn "Execution of -e aborted due to compilation errors.\n";
56like $warning, qr/The final summary message/, 'Periods at end of line';
e958e573 57
e958e573
MH
58# Test for %d/%u
59seek STDERR, 0,0;
60$warning = '';
61warn "Bad arg length for us, is 4, should be 42";
62like $warning, qr/In C parlance/, '%u works';
524e9188
MH
63
64# Strip S<>
65seek STDERR, 0,0;
66$warning = '';
67warn "syntax error";
68like $warning, qr/cybernetic version of 20 questions/s, 'strip S<>';