This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
State the requirement of a C89 compliant ANSI C-compiler
[perl5.git] / t / porting / diag.t
CommitLineData
fe13d51d
JM
1#!/usr/bin/perl
2use warnings;
3use strict;
f7b649f0
NC
4
5require './test.pl';
6
7plan('no_plan');
8
fe13d51d
JM
9$|=1;
10
f7223e8e 11my $make_exceptions_list = ($ARGV[0]||'') eq '--make-exceptions-list';
87a63fff 12
45f1c7ba 13chdir '..' or die "Can't chdir ..: $!";
47f6eaac 14BEGIN { defined $ENV{PERL_UNICODE} and push @INC, "lib"; }
45f1c7ba
NC
15
16open my $diagfh, "<", "pod/perldiag.pod"
17 or die "Can't open pod/perldiag.pod: $!";
fe13d51d
JM
18
19my %entries;
87a63fff
JM
20while (<DATA>) {
21 chomp;
22 $entries{$_}{todo}=1;
23}
24
fe13d51d
JM
25my $cur_entry;
26while (<$diagfh>) {
27 if (m/^=item (.*)/) {
28 $cur_entry = $1;
29 } elsif (m/^\((.)(?: ([a-z]+?))?\)/ and !$entries{$cur_entry}{severity}) {
87a63fff
JM
30 # Make sure to init this here, so an actual entry in perldiag overwrites
31 # one in DATA.
32 $entries{$cur_entry}{todo} = 0;
fe13d51d
JM
33 $entries{$cur_entry}{severity} = $1;
34 $entries{$cur_entry}{category} = $2;
35 }
36}
37
45f1c7ba 38my @todo = <*>;
fe13d51d
JM
39while (@todo) {
40 my $todo = shift @todo;
45f1c7ba 41 next if $todo ~~ ['t', 'lib', 'ext', 'dist', 'cpan'];
fe13d51d 42 # opmini.c is just a copy of op.c, so there's no need to check again.
45f1c7ba 43 next if $todo eq 'opmini.c';
fe13d51d
JM
44 if (-d $todo) {
45 push @todo, glob "$todo/*";
87a63fff 46 } elsif ($todo =~ m/\.[ch]$/) {
fe13d51d
JM
47 check_file($todo);
48 }
49}
50
51sub check_file {
52 my ($codefn) = @_;
53
f7223e8e 54 print "# $codefn\n";
fe13d51d 55
38ec24b4 56 open my $codefh, "<", $codefn
fe13d51d
JM
57 or die "Can't open $codefn: $!";
58
59 my $listed_as;
60 my $listed_as_line;
61 my $sub = 'top of file';
62 while (<$codefh>) {
63 chomp;
64 # Getting too much here isn't a problem; we only use this to skip
65 # errors inside of XS modules, which should get documented in the
66 # docs for the module.
67 if (m<^([^#\s].*)> and $1 !~ m/^[{}]*$/) {
68 $sub = $1;
69 }
70 next if $sub =~ m/^XS/;
71 if (m</\* diag_listed_as: (.*) \*/>) {
72 $listed_as = $1;
73 $listed_as_line = $.+1;
74 }
75 next if /^#/;
76 next if /^ * /;
77 while (m/\bDIE\b|Perl_(croak|die|warn(er)?)/ and not m/\);$/) {
78 my $nextline = <$codefh>;
79 # Means we fell off the end of the file. Not terribly surprising;
80 # this code tries to merge a lot of things that aren't regular C
81 # code (preprocessor stuff, long comments). That's OK; we don't
82 # need those anyway.
83 last if not defined $nextline;
84 chomp $nextline;
85 $nextline =~ s/^\s+//;
86 # Note that we only want to do this where *both* are true.
87 $_ =~ s/\\$//;
88 if ($_ =~ m/"$/ and $nextline =~ m/^"/) {
89 $_ =~ s/"$//;
90 $nextline =~ s/^"//;
91 }
92 $_ = "$_$nextline";
93 }
94 # This should happen *after* unwrapping, or we don't reformat the things
95 # in later lines.
96 # List from perlguts.pod "Formatted Printing of IVs, UVs, and NVs"
97 my %specialformats = (IVdf => 'd',
98 UVuf => 'd',
99 UVof => 'o',
100 UVxf => 'x',
101 UVXf => 'X',
102 NVef => 'f',
103 NVff => 'f',
104 NVgf => 'f',
105 SVf => 's');
106 for my $from (keys %specialformats) {
107 s/%"\s*$from\s*"/\%$specialformats{$from}/g;
108 s/%"\s*$from/\%$specialformats{$from}"/g;
109 }
110 # The %"foo" thing needs to happen *before* this regex.
111 if (m/(?:DIE|Perl_(croak|die|warn|warner))(?:_nocontext)? \s*
112 \(aTHX_ \s*
113 (?:packWARN\d*\((.*?)\),)? \s*
114 "((?:\\"|[^"])*?)"/x) {
115 # diag($_);
116 # DIE is just return Perl_die
117 my $severity = {croak => [qw/P F/],
118 die => [qw/P F/],
119 warn => [qw/W D S/],
120 }->{$1||'die'};
121 my @categories;
122 if ($2) {
123 @categories = map {s/^WARN_//; lc $_} split /\s*[|,]\s*/, $2;
124 }
125 my $name;
126 if ($listed_as and $listed_as_line == $.) {
127 $name = $listed_as;
128 } else {
129 $name = $3;
130 # The form listed in perldiag ignores most sorts of fancy printf formatting,
131 # or makes it more perlish.
132 $name =~ s/%%/\\%/g;
133 $name =~ s/%l[ud]/%d/g;
134 $name =~ s/%\.(\d+|\*)s/\%s/g;
135 $name =~ s/\\"/"/g;
136 $name =~ s/\\t/\t/g;
87a63fff
JM
137 $name =~ s/\\n/ /g;
138 $name =~ s/\s+$//;
4a68bf9d 139 $name =~ s/(\\)\\/$1/g;
fe13d51d
JM
140 }
141
87a63fff
JM
142 # Extra explanatory info on an already-listed error, doesn't
143 # need it's own listing.
fe13d51d
JM
144 next if $name =~ m/^\t/;
145
146 # Happens fairly often with PL_no_modify.
147 next if $name eq '%s';
148
87a63fff
JM
149 # Special syntax for magic comment, allows ignoring the fact
150 # that it isn't listed. Only use in very special circumstances,
151 # like this script failing to notice that the Perl_croak call is
152 # inside an #if 0 block.
fe13d51d
JM
153 next if $name eq 'SKIPME';
154
87a63fff
JM
155 if (exists $entries{$name}) {
156 if ($entries{$name}{todo}) {
157 TODO: {
f7b649f0
NC
158 no warnings 'once';
159 local $::TODO = 'in DATA';
87a63fff
JM
160 fail("Presence of '$name' from $codefn line $.");
161 }
fe13d51d 162 } else {
87a63fff 163 ok("Presence of '$name' from $codefn line $.");
fe13d51d 164 }
87a63fff
JM
165 # Later, should start checking that the severity is correct, too.
166 } elsif ($name =~ m/^panic: /) {
167 # Just too many panic:s, they are hard to diagnose, and there
168 # is a generic "panic: %s" entry. Leave these for another
169 # pass.
170 ok("Presence of '$name' from $codefn line $., covered by panic: %s entry");
fe13d51d 171 } else {
87a63fff
JM
172 if ($make_exceptions_list) {
173 print STDERR "$name\n";
174 } else {
175 fail("Presence of '$name' from $codefn line $.");
176 }
fe13d51d
JM
177 }
178
179 die if $name =~ /%$/;
180 }
181 }
182}
f7223e8e 183# Lists all missing things as of the inaguration of this script, so we
87a63fff
JM
184# don't have to go from "meh" to perfect all at once.
185__DATA__
186Ambiguous call resolved as CORE::%s(), %s
187Ambiguous use of %c resolved as operator %c
188Ambiguous use of %c{%s} resolved to %c%s
189Ambiguous use of %c{%s%s} resolved to %c%s%s
190Ambiguous use of -%s resolved as -&%s()
191Argument "%s" isn't numeric
192Argument "%s" isn't numeric in %s
87a63fff
JM
193Attempt to clear deleted array
194Attempt to free non-arena SV: 0x%x
195Attempt to free non-existent shared string '%s'%s
196Attempt to free temp prematurely: SV 0x%x
197Attempt to free unreferenced scalar: SV 0x%x
198Attempt to reload %s aborted. Compilation failed in require
199av_reify called on tied array
200Bad name after %s%s
d5713896 201Bad symbol for %s
87a63fff
JM
202bad top format reference
203Bizarre copy of %s
204Bizarre SvTYPE [%d]
205Cannot copy to %s
206Can't call method "%s" %s
207Can't coerce readonly %s to string
208Can't coerce readonly %s to string in %s
209Can't fix broken locale name "%s"
210Can't get short module name from a handle
211Can't goto subroutine from an eval-block
212Can't goto subroutine from an eval-string
213Can't locate object method "%s" via package "%s" (perhaps you forgot to load "%s"?)
214Can't modify non-existent substring
215Can't open
216Can't open perl script "%s": %s
217Can't open %s
218Can't reset \%ENV on this system
219Can't return array to lvalue scalar context
220Can't return a %s from lvalue subroutine
221Can't return hash to lvalue scalar context
222Can't spawn "%s": %s
223Can't %s script `%s' with ARGV[0] being `%s'
224Can't %s "%s": %s
225Can't %s %s%s%s
226Can't %s `%s' with ARGV[0] being `%s' (looking for executables only, not found)
227Can't take %s of %f
228Can't use '%c' after -mname
973a7615 229Can't use string ("%s"%s) as a subroutine ref while "strict refs" in use
4a68bf9d 230Can't use \%c to mean $%c in expression
87a63fff 231Can't use when() outside a topicalizer
4a68bf9d 232\%c better written as $%c
87a63fff
JM
233Character(s) in '%c' format wrapped in %s
234$%c is no longer supported
235Cloning substitution context is unimplemented
236Code missing after '/' in pack
237Code missing after '/' in unpack
238Compilation failed in require
239Corrupted regexp opcode %d > %d
240'%c' outside of string in pack
241Debug leaking scalars child failed%s%s with errno %d: %s
242Deep recursion on anonymous subroutine
243defined(\%hash) is deprecated
4a68bf9d 244Don't know how to handle magic of type \%o
87a63fff
JM
245-Dp not implemented on this platform
246entering effective gid failed
247entering effective uid failed
248Error reading "%s": %s
249Exiting %s via %s
250Filehandle opened only for %sput
251Filehandle %s opened only for %sput
252Filehandle STD%s reopened as %s only for input
253YOU HAVEN'T DISABLED SET-ID SCRIPTS IN THE KERNEL YET! FIX YOUR KERNEL, PUT A C WRAPPER AROUND THIS SCRIPT, OR USE -u AND UNDUMP!
254Format STDOUT redefined
255Free to wrong pool %p not %p
256get %s %p %p %p
257glob failed (can't start child: %s)
258glob failed (child exited with status %d%s)
259Goto undefined subroutine
260Goto undefined subroutine &%s
261Hash \%%s missing the \% in argument %d of %s()
4a68bf9d 262Illegal character \%03o (carriage return)
87a63fff
JM
263Illegal character %sin prototype for %s : %s
264Integer overflow in decimal number
265Integer overflow in version %d
266internal \%<num>p might conflict with future printf extensions
4a68bf9d 267invalid control request: '\%03o'
87a63fff
JM
268Invalid module name %s with -%c option: contains single ':'
269invalid option -D%c, use -D'' to see choices
270Invalid range "%c-%c" in transliteration operator
271Invalid separator character %c%c%c in PerlIO layer specification %s
272Invalid TOKEN object ignored
273Invalid type '%c' in pack
274Invalid type '%c' in %s
275Invalid type '%c' in unpack
276Invalid type ',' in %s
91152fc1
DG
277Invalid strict version format (0 before decimal required)
278Invalid strict version format (no leading zeros)
279Invalid strict version format (no underscores)
280Invalid strict version format (v1.2.3 required)
281Invalid strict version format (version required)
282Invalid strict version format (1.[0-9] required)
87a63fff
JM
283Invalid version format (alpha without decimal)
284Invalid version format (misplaced _ in number)
285Invalid version object
4a68bf9d 286It is proposed that "\c{" no longer be valid. It has historically evaluated to ";". If you disagree with this proposal, send email to perl5-porters@perl.org Otherwise, or in the meantime, you can work around this failure by changing "\c{" to ";"
87a63fff
JM
287'j' not supported on this platform
288'J' not supported on this platform
289Layer does not match this perl
290leaving effective gid failed
291leaving effective uid failed
292List form of piped open not implemented
293Lost precision when decrementing %f by 1
294Lost precision when incrementing %f by 1
295%lx
296Malformed UTF-16 surrogate
297Malformed UTF-8 character (fatal)
298'\%' may not be used in pack
299Missing (suid) fd script name
300More than one argument to open
301More than one argument to open(,':%s')
302mprotect for %p %d failed with %d
303mprotect RW for %p %d failed with %d
304No code specified for -%c
305No directory specified for -I
306No such class field "%s"
307Not an XSUB reference
308Not %s reference
309Offset outside string
310Opening dirhandle %s also as a file
311Opening filehandle %s also as a directory
312Operator or semicolon missing before %c%s
87a63fff
JM
313PERL_SIGNALS illegal: "%s"
314Perl %s required (did you mean %s?)--this is only %s, stopped
315Perl %s required--this is only %s, stopped
316Perls since %s too modern--this is %s, stopped
4a68bf9d 317Possible unintended interpolation of $\ in regex
87a63fff
JM
318ptr wrong %p != %p fl=%08
319Recompile perl with -DDEBUGGING to use -D switch (did you mean -d ?)
320Recursive call to Perl_load_module in PerlIO_find_layer
321refcnt_dec: fd %d < 0
322refcnt_dec: fd %d: %d <= 0
323refcnt_dec: fd %d >= refcnt_size %d
324refcnt_inc: fd %d < 0
325refcnt_inc: fd %d: %d <= 0
326Reversed %c= operator
327Runaway prototype
328%s(%.0f) failed
329%s(%.0f) too large
330Scalar value %s better written as $%s
331%sCompilation failed in regexp
332%sCompilation failed in require
333set %s %p %p %p
334%s free() ignored (RMAGIC, PERL_CORE)
335%s has too many errors.
336SIG%s handler "%s" not defined.
337%s: illegal mapping '%s'
338%s in %s
339Size magic not implemented
340%s limit (%d) exceeded
341%s method "%s" overloading "%s" in package "%s"
342%s number > %s non-portable
343%s object version %s does not match %s%s%s%s %s
344%srealloc() %signored
345%s returned from lvalue subroutine in scalar context
346%s%s has too many errors.
347%s%s on %s %s
348%s%s on %s %s %s
349Starting Full Screen process with flag=%d, mytype=%d
350Starting PM process with flag=%d, mytype=%d
351strxfrm() gets absurd
352SWASHNEW didn't return an HV ref
353-T and -B not implemented on filehandles
354The flock() function is not implemented on NetWare
355The rewinddir() function is not implemented on NetWare
356The seekdir() function is not implemented on NetWare
357The stat preceding lstat() wasn't an lstat
358The telldir() function is not implemented on NetWare
359Too deeply nested ()-groups in %s
360Too late to run CHECK block
361Too late to run INIT block
362Too many args on %s line of "%s"
363U0 mode on a byte string
364Unbalanced string table refcount: (%d) for "%s"
365Undefined top format called
366Unexpected constant lvalue entersub entry via type/targ %d:%d
6f6ac1de 367Unicode non-character 0x%04
87a63fff
JM
368Unknown PerlIO layer "scalar"
369Unknown Unicode option letter '%c'
87a63fff 370Unstable directory path, current directory changed unexpectedly
ee6ba15d
EB
371Unsupported script encoding UTF-16BE
372Unsupported script encoding UTF-16LE
373Unsupported script encoding UTF-32BE
374Unsupported script encoding UTF-32LE
87a63fff
JM
375Unterminated compressed integer in unpack
376Usage: CODE(0x%x)(%s)
377Usage: %s(%s)
378Usage: %s::%s(%s)
379Usage: VMS::Filespec::unixrealpath(spec)
380Usage: VMS::Filespec::vmsrealpath(spec)
381Use of inherited AUTOLOAD for non-method %s::%s() is deprecated
382UTF-16 surrogate 0x%04
4a68bf9d 383utf8 "\x%02X" does not map to Unicode
87a63fff
JM
384Value of logical "%s" too long. Truncating to %i bytes
385value of node is %d in Offset macro
386Value of %s%s can be "0"; test with defined()
387Variable "%c%s" is not imported
388vector argument not supported with alpha versions
389Wide character
390Wide character in $/
391Wide character in print
392Wide character in %s
393Within []-length '%c' not allowed in %s
394Wrong syntax (suid) fd script name "%s"
395'X' outside of string in unpack