This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8_heavy.pl: Correct debugging statement
[perl5.git] / lib / diagnostics.t
... / ...
CommitLineData
1#!./perl -w
2
3BEGIN {
4 chdir '..' if -d '../pod' && -d '../t';
5 @INC = 'lib';
6}
7
8use Test::More tests => 10;
9
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}
16
17require base;
18
19eval {
20 'base'->import(qw(I::do::not::exist));
21};
22
23like( $@, qr/^Base class package "I::do::not::exist" is empty/);
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';
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';
43like $warning, qr/using lex_stuff_pvn or similar/, 'L<foo|bar/baz>';
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
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';
57
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';
63
64# Strip S<>
65seek STDERR, 0,0;
66$warning = '';
67warn "syntax error";
68like $warning, qr/cybernetic version of 20 questions/s, 'strip S<>';