14 # --make-exceptions-list outputs the list of strings that don't have
15 # perldiag.pod entries to STDERR without TAP formatting, so they can
16 # easily be put in the __DATA__ section of this file. This was done
17 # initially so as to not create new test failures upon the initial
18 # creation of this test file. You probably shouldn't do it again.
19 # Just add the documentation instead.
20 my $make_exceptions_list = ($ARGV[0]||'') eq '--make-exceptions-list';
22 chdir '..' or die "Can't chdir ..: $!";
23 BEGIN { defined $ENV{PERL_UNICODE} and push @INC, "lib"; }
27 open my $func_fh, "<", "embed.fnc" or die "Can't open embed.fnc: $!";
29 # Look for functions in embed.fnc that look like they could be diagnostic ones.
33 while (s/\s*\\$//) { # Grab up all continuation lines, these end in \
34 my $next = <$func_fh>;
39 next if /^:/; # Lines beginning with colon are comments.
40 next unless /\|/; # Lines without a vertical bar are something we can't deal
42 my @fields = split /\s*\|\s*/;
43 next unless $fields[2] =~ /warn|err|(\b|_)die|croak/i;
44 push @functions, $fields[2];
46 # The flag p means that this function may have a 'Perl_' prefix
47 # The flag s means that this function may have a 'S_' prefix
48 push @functions, "Perl_$fields[2]", if $fields[0] =~ /p/;
49 push @functions, "S_$fields[2]", if $fields[0] =~ /s/;
54 my $regcomp_re = "(?<routine>(?:ckWARN(?:\\d+)?reg\\w*|vWARN\\d+))";
55 my $function_re = join '|', @functions;
56 my $regcomp_fail_re = '\b(?:(?:Simple_)?v)?FAIL[2-4]?\b';
58 "(?<routine>\\bDIE\\b|$function_re|$regcomp_fail_re)";
59 my $text_re = '"(?<text>(?:\\\\"|[^"]|"\s*[A-Z_]+\s*")*)"';
60 my $source_msg_call_re = qr/$source_msg_re(?:_nocontext)? \s*
62 (?:packWARN\d*\((?<category>.*?)\),)? \s*
64 my $bad_version_re = qr{BADVERSION\([^"]*$text_re};
65 $regcomp_fail_re = qr/$regcomp_fail_re\([^"]*$text_re/;
66 my $regcomp_call_re = qr/$regcomp_re.*?$text_re/;
70 # Get the ignores that are compiled into this file
71 my $reading_categorical_exceptions;
74 $entries{$_}{$reading_categorical_exceptions ? 'cattodo' : 'todo'}=1;
75 /__CATEGORIES__/ and ++$reading_categorical_exceptions;
78 my $pod = "pod/perldiag.pod";
80 open my $diagfh, "<", $pod
81 or die "Can't open $pod: $!";
83 my $category_re = qr/ [a-z0-9_:]+?/; # Note: requires an initial space
84 my $severity_re = qr/ . (?: \| . )* /x; # A severity is a single char, but can
85 # be of the form 'S|P|W'
91 # Allow multi-line headers
100 $cur_entry =~ s/\n/ /gs; # Fix multi-line headers if they have \n's
101 $cur_entry =~ s/\s+\z//;
103 if (exists $entries{$cur_entry} && $entries{$cur_entry}{todo}) {
105 local $::TODO = "Remove the TODO entry \"$cur_entry\" from DATA as it is already in $pod near line $.";
109 # Make sure to init this here, so an actual entry in perldiag
110 # overwrites one in DATA.
111 $entries{$cur_entry}{todo} = 0;
112 $entries{$cur_entry}{line_number} = $.;
115 next if ! defined $cur_entry;
117 if (! $entries{$cur_entry}{severity}) {
118 if (/^ \( ( $severity_re )
120 # Can have multiple categories separated by commas
121 ( $category_re (?: , $category_re)* )? \) /x)
123 $entries{$cur_entry}{severity} = $1;
124 $entries{$cur_entry}{category} =
125 $2 && join ", ", sort split " ", $2 =~ y/,//dr;
127 # Record it also for other messages sharing the same description
128 @$_{qw<severity category>} =
129 @{$entries{$cur_entry}}{qw<severity category>}
132 elsif (! $entries{$cur_entry}{first_line} && $_ =~ /\S/) {
134 # Keep track of first line of text if doesn't contain a severity, so
135 # that can later examine it to determine if that is ok or not
136 $entries{$cur_entry}{first_line} = $_;
142 push @same_descr, $entries{$cur_entry};
147 foreach my $cur_entry ( keys %entries) {
148 next if $entries{$cur_entry}{todo}; # If in this file, won't have a severity
149 if (! exists $entries{$cur_entry}{severity}
151 # If there is no first line, it was two =items in a row, so the
152 # second one is the one with with text, not this one.
153 && exists $entries{$cur_entry}{first_line}
155 # If the first line refers to another message, no need for severity
156 && $entries{$cur_entry}{first_line} !~ /^See/)
160 " $pod entry at line $entries{$cur_entry}{line_number}\n"
161 . " \"$cur_entry\"\n"
162 . " is missing a severity and/or category"
167 # List from perlguts.pod "Formatted Printing of IVs, UVs, and NVs"
168 # Convert from internal formats to ones that the readers will be familiar
169 # with, while removing any format modifiers, such as precision, the
170 # presence of which would just confuse the pod's explanation
171 my %specialformats = (IVdf => 'd',
184 my $format_modifiers = qr/ [#0\ +-]* # optional flags
185 (?: [1-9][0-9]* | \* )? # optional field width
186 (?: \. \d* )? # optional precision
187 (?: h|l )? # optional length modifier
191 join '|', sort { length $b cmp length $a } keys %specialformats;
192 my $specialformats_re = qr/%$format_modifiers"\s*($specialformats)(\s*")?/;
194 open my $fh, '<', 'MANIFEST' or die "Can't open MANIFEST: $!";
195 while (my $file = <$fh>) {
196 next if $file =~ m!\A(?:ext|dist|cpan|lib|t)/!;
199 next unless $file =~ /\.(?:c|cpp|h|y)\z/ or $file =~ /^perly\./;
204 # Standardize messages with variants into the form that appears
205 # in perldiag.pod -- useful for things without a diag_listed_as annotation
209 if ( $name =~ m/^(Invalid strict version format) \([^\)]*\)/ ) {
212 elsif ( $name =~ m/^(Invalid version format) \([^\)]*\)/ ) {
215 elsif ($name =~ m/^panic: /) {
216 $name = "panic: \%s";
225 print "# Checking $codefn\n";
227 open my $codefh, "<", $codefn
228 or die "Can't open $codefn: $!";
232 my $sub = 'top of file';
235 # Getting too much here isn't a problem; we only use this to skip
236 # errors inside of XS modules, which should get documented in the
237 # docs for the module.
238 if (m<^[^#\s]> and $_ !~ m/^[{}]*$/) {
241 next if $sub =~ m/^XS/;
242 if (m</\*\s*diag_listed_as: (.*?)\s*\*/>) {
244 $listed_as_line = $.+1;
249 # Loop to accumulate the message text all on one line.
250 if (m/(?:$source_msg_re(?:_nocontext)?|$regcomp_re)\s*\(/) {
251 while (not m/\);$/) {
252 my $nextline = <$codefh>;
253 # Means we fell off the end of the file. Not terribly surprising;
254 # this code tries to merge a lot of things that aren't regular C
255 # code (preprocessor stuff, long comments). That's OK; we don't
257 last if not defined $nextline;
259 $nextline =~ s/^\s+//;
261 # Note that we only want to do this where *both* are true.
262 if ($_ =~ m/"$/ and $nextline =~ m/^"/) {
270 # This should happen *after* unwrapping, or we don't reformat the things
273 s/$specialformats_re/"%$specialformats{$1}" . (defined $2 ? '' : '"')/ge;
275 # Remove any remaining format modifiers, but not in %%
276 s/ (?<!%) % $format_modifiers ( [dioxXucsfeEgGp] ) /%$1/xg;
278 # The %"foo" thing needs to happen *before* this regex.
280 # DIE is just return Perl_die
281 my ($name, $category, $routine);
282 if (/$source_msg_call_re/) {
283 ($name, $category, $routine) = ($+{'text'}, $+{'category'}, $+{'routine'});
284 # Sometimes the regexp will pick up too much for the category
285 # e.g., WARN_UNINITIALIZED), PL_warn_uninit_sv ... up to the next )
286 $category && $category =~ s/\).*//s;
288 elsif (/$bad_version_re/) {
289 ($name, $category) = ($+{'text'}, undef);
291 elsif (/$regcomp_fail_re/) {
292 # FAIL("foo") -> "foo in regex m/%s/"
293 # vFAIL("foo") -> "foo in regex; marked by <-- HERE in m/%s/"
294 ($name, $category) = ($+{'text'}, undef);
296 " in regex" . ("; marked by <-- HERE in" x /vFAIL/) . " m/%s/";
298 elsif (/$regcomp_call_re/) {
299 # vWARN/ckWARNreg("foo") -> "foo in regex; marked by <-- HERE in m/%s/
300 ($name, $category, $routine) = ($+{'text'}, undef, $+{'routine'});
301 $name .= " in regex; marked by <-- HERE in m/%s/";
302 $category = 'WARN_REGEXP';
303 if ($routine =~ /dep/) {
304 $category .= ',WARN_DEPRECATED';
311 # Try to guess what the severity should be. In the case of
312 # Perl_ck_warner and other _ck_ functions, we can tell whether it is
313 # a severe/default warning or no by the _d suffix. In the case of
314 # other warn functions we cannot tell, because Perl_warner may be pre-
315 # ceded by if(ckWARN) or if(ckWARN_d).
316 my $severity = !$routine ? '[PFX]'
317 : $routine =~ /warn.*_d\z/ ? '[DS]'
318 : $routine =~ /ck_warn/ ? 'W'
319 : $routine =~ /warn/ ? '[WDS]'
320 : $routine =~ /ckWARN.*dep/ ? 'D'
321 : $routine =~ /ckWARN\d*reg/ ? 'W'
322 : $routine =~ /vWARN\d/ ? '[WDS]'
325 if (defined $category) {
326 $category =~ s/__/::/g;
329 sort map {s/^WARN_//; lc $_} split /\s*[|,]\s*/, $category;
331 if ($listed_as and $listed_as_line == $. - $multiline) {
334 # The form listed in perldiag ignores most sorts of fancy printf
335 # formatting, or makes it more perlish.
337 $name =~ s/%l[ud]/%d/g;
338 $name =~ s/%\.(\d+|\*)s/\%s/g;
339 $name =~ s/(?:%s){2,}/%s/g;
340 $name =~ s/(\\")|("\s*[A-Z_]+\s*")/$1 ? '"' : '%s'/egg;
344 $name =~ s/(\\)\\/$1/g;
347 # Extra explanatory info on an already-listed error, doesn't
348 # need it's own listing.
349 next if $name =~ m/^\t/;
351 # Happens fairly often with PL_no_modify.
352 next if $name eq '%s';
354 # Special syntax for magic comment, allows ignoring the fact
355 # that it isn't listed. Only use in very special circumstances,
356 # like this script failing to notice that the Perl_croak call is
357 # inside an #if 0 block.
358 next if $name eq 'SKIPME';
360 check_message(standardize($name),$codefn,$severity,$categories);
365 my($name,$codefn,$severity,$categories,$partial) = @_;
366 my $key = $name =~ y/\n/ /r;
369 # Try to reduce printf() formats to simplest forms
370 # Really this should be matching %s, etc like diagnostics.pm does
373 $key =~ s/%[#0\-+]/%/g;
376 $key =~ s/\%(\d+|\*)/%/g;
379 $key =~ s/\%\.(\d+|\*)/%/g;
381 if (exists $entries{$key}) {
383 if ( $entries{$key}{seen}++ ) {
384 # no need to repeat entries we've tested
385 } elsif ($entries{$key}{todo}) {
388 local $::TODO = 'in DATA';
389 # There is no listing, but it is in the list of exceptions. TODO FAIL.
392 " Message '$name'\n from $codefn line $. is not listed in $pod\n".
393 " (but it wasn't documented in 5.10 either, so marking it TODO)."
397 # We found an actual valid entry in perldiag.pod for this error.
400 # Now check the category and severity
402 # Cache our severity qr thingies
405 my $qr = $qrs{$severity} ||= qr/$severity/;
408 if $entries{$key}{cattodo};
410 like $entries{$key}{severity}, $qr,
412 ? "severity is one of $severity for $key"
413 : "severity is $severity for $key";
415 is $entries{$key}{category}, $categories,
416 ($categories ? "categories are [$categories]" : "no category")
419 # Later, should start checking that the severity is correct, too.
426 check_message($_,$codefn,$severity,$categories,1) or $ok = 0, last
427 for split /\n/, $name;
431 } elsif ($make_exceptions_list) {
432 # We're making an updated version of the exception list, to
433 # stick in the __DATA__ section. I honestly can't think of
434 # a situation where this is the right thing to do, but I'm
435 # leaving it here, just in case one of my descendents thinks
437 print STDERR "$key\n";
439 # No listing found, and no excuse either.
440 # Find the correct place in perldiag.pod, and add a stanza beginning =item $name.
442 diag(" Message '$name'\n from $codefn line $. is not listed in $pod");
444 # seen it, so only fail once for this message
445 $entries{$name}{seen}++;
448 die if $name =~ /%$/;
452 # Lists all missing things as of the inauguration of this script, so we
453 # don't have to go from "meh" to perfect all at once.
455 # PLEASE DO NOT ADD TO THIS LIST. Instead, write an entry in
456 # pod/perldiag.pod for your new (warning|error).
458 # Entries after __CATEGORIES__ are those that are in perldiag but fail the
459 # severity/category test.
461 # Also FIXME this test, as the first entry in TODO *is* covered by the
462 # description: Malformed UTF-8 character (%s)
464 Malformed UTF-8 character (unexpected non-continuation byte 0x%x, immediately after start byte 0x%x)
466 '%c' allowed only after types %s in %s
467 bad top format reference
468 Cannot apply "%s" in non-PerlIO perl
469 Can't %s big-endian %ss on this
470 Can't call mro_isa_changed_in() on anonymous symbol table
471 Can't call mro_method_changed_in() on anonymous symbol table
472 Can't coerce readonly %s to string
473 Can't coerce readonly %s to string in %s
474 Can't find string terminator %c%s%c anywhere before EOF
475 Can't fix broken locale name "%s"
476 Can't get short module name from a handle
477 Can't locate object method "%s" via package "%s" (perhaps you forgot to load "%s"?)
481 Can't %s script `%s' with ARGV[0] being `%s'
483 Can't %s `%s' with ARGV[0] being `%s' (looking for executables only, not found)
484 Can't use string ("%s"%s) as a subroutine ref while "strict refs" in use
485 \%c better written as $%c
486 Character(s) in '%c' format wrapped in %s
487 chown not implemented!
489 Code missing after '/' in pack
490 Code missing after '/' in unpack
491 Corrupted regexp opcode %d > %d
492 '%c' outside of string in pack
493 Debug leaking scalars child failed%s with errno %d: %s
494 '/' does not take a repeat count in %s
495 Don't know how to get file name
496 Don't know how to handle magic of type \%o
497 -Dp not implemented on this platform
498 Empty \%c{} in regex; marked by <-- HERE in m/%s/
499 Error reading "%s": %s
500 execl not implemented!
501 EVAL without pos change exceeded limit in regex
502 Expecting close bracket in regex; marked by <-- HERE in m/%s/
503 Filehandle opened only for %sput
504 Filehandle %s opened only for %sput
505 Filehandle STD%s reopened as %s only for input
506 filter_del can only delete in reverse order (currently)
507 YOU 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!
508 fork() not implemented!
510 Free to wrong pool %p not %p
512 gethostent not implemented!
513 getpwnam returned invalid UIC %o for user "%s"
514 glob failed (can't start child: %s)
515 glob failed (child exited with status %d%s)
516 Goto undefined subroutine
517 Goto undefined subroutine &%s
519 ()-group starts with a count in %s
520 Illegal binary digit '%c' ignored
521 Illegal character %sin prototype for %s : %s
522 Illegal hexadecimal digit '%c' ignored
523 Illegal octal digit '%c' ignored
524 Illegal pattern in regex; marked by <-- HERE in m/%s/
525 Infinite recursion in regex
526 internal %<num>p might conflict with future printf extensions
527 Invalid argument to sv_cat_decode
528 Invalid [] range "%*.*s" in regex; marked by <-- HERE in m/%s/
529 Invalid range "%c-%c" in transliteration operator
530 Invalid separator character %c%c%c in PerlIO layer specification %s
531 Invalid TOKEN object ignored
532 Invalid type '%c' in pack
533 Invalid type '%c' in %s
534 Invalid type '%c' in unpack
535 Invalid type ',' in %s
536 ioctlsocket not implemented!
537 'j' not supported on this platform
538 'J' not supported on this platform
539 killpg not implemented!
540 length() used on %s (did you mean "scalar(%s)"?)
541 length() used on %hash (did you mean "scalar(keys %hash)"?)
542 length() used on @array (did you mean "scalar(@array)"?)
543 List form of pipe open not implemented
544 Malformed integer in [] in %s
545 Malformed UTF-8 character (fatal)
546 Missing (suid) fd script name
547 More than one argument to open
548 More than one argument to open(,':%s')
549 mprotect for %p %u failed with %d
550 mprotect RW for %p %u failed with %d
551 No %s allowed while running setgid
552 No %s allowed with (suid) fdscript
553 No such class field "%s"
554 Not an XSUB reference
555 Operator or semicolon missing before %c%s
556 Pattern subroutine nesting without pos change exceeded limit in regex
557 Perl %s required--this is only %s, stopped
558 PerlApp::TextQuery: no arguments, please
559 POSIX syntax [%c %c] is reserved for future extensions in regex; marked by <-- HERE in m/%s/
560 ptr wrong %p != %p fl=%x nl=%p e=%p for %d
561 Recompile perl with -DDEBUGGING to use -D switch (did you mean -d ?)
562 Regexp modifier "%c" may appear a maximum of twice in regex; marked by <-- HERE in m/%s/
563 Regexp modifier "%c" may not appear twice in regex; marked by <-- HERE in m/%s/
564 Regexp modifiers "%c" and "%c" are mutually exclusive in regex; marked by <-- HERE in m/%s/
565 Regexp *+ operand could be empty in regex; marked by <-- HERE in m/%s/
566 Repeated format line will never terminate (~~ and @#)
567 Reversed %c= operator
569 %sCompilation failed in require
570 Sequence (?%c...) not implemented in regex; marked by <-- HERE in m/%s/
571 Sequence (%s...) not recognized in regex; marked by <-- HERE in m/%s/
572 Sequence %s... not terminated in regex; marked by <-- HERE in m/%s/
573 Sequence (?%c... not terminated in regex; marked by <-- HERE in m/%s/
574 Sequence (?(%c... not terminated in regex; marked by <-- HERE in m/%s/
575 Sequence (?R) not terminated in regex m/%s/
577 %s free() ignored (RMAGIC, PERL_CORE)
578 %s has too many errors.
579 SIG%s handler "%s" not defined.
581 Size magic not implemented
582 %s number > %s non-portable
583 %srealloc() %signored
586 socketpair not implemented!
587 Starting Full Screen process with flag=%d, mytype=%d
588 Starting PM process with flag=%d, mytype=%d
589 sv_2iv assumed (U_V(fabs((double)SvNVX(sv))) < (UV)IV_MAX) but SvNVX(sv)=%f U_V is 0x%x, IV_MAX is 0x%x
590 SWASHNEW didn't return an HV ref
591 switching effective gid is not implemented
592 switching effective uid is not implemented
593 System V IPC is not implemented on this machine
594 -T and -B not implemented on filehandles
595 Terminating on signal SIG%s(%d)
596 The crypt() function is not implemented on NetWare
597 The flock() function is not implemented on NetWare
598 The rewinddir() function is not implemented on NetWare
599 The seekdir() function is not implemented on NetWare
600 The telldir() function is not implemented on NetWare
601 Too deeply nested ()-groups in %s
602 Too many args on %s line of "%s"
603 U0 mode on a byte string
604 unable to find VMSPIPE.COM for i/o piping
605 Unknown Unicode option value %d
606 Unrecognized character %s; marked by <-- HERE after %s<-- HERE near column %d
607 Unstable directory path, current directory changed unexpectedly
608 Unterminated compressed integer in unpack
609 Unterminated \g... pattern in regex; marked by <-- HERE in m/%s/
610 Usage: CODE(0x%x)(%s)
613 Usage: File::Copy::rmscopy(from,to[,date_flag])
614 Usage: VMS::Filespec::candelete(spec)
615 Usage: VMS::Filespec::fileify(spec)
616 Usage: VMS::Filespec::pathify(spec)
617 Usage: VMS::Filespec::rmsexpand(spec[,defspec])
618 Usage: VMS::Filespec::unixify(spec)
619 Usage: VMS::Filespec::unixpath(spec)
620 Usage: VMS::Filespec::unixrealpath(spec)
621 Usage: VMS::Filespec::vmsify(spec)
622 Usage: VMS::Filespec::vmspath(spec)
623 Usage: VMS::Filespec::vmsrealpath(spec)
624 Use of inherited AUTOLOAD for non-method %s::%s() is deprecated
625 utf8 "\x%X" does not map to Unicode
626 Value of logical "%s" too long. Truncating to %i bytes
627 waitpid: process %x is not a child of process %x
630 Within []-length '*' not allowed in %s
631 Within []-length '%c' not allowed in %s
632 Wrong syntax (suid) fd script name "%s"
633 'X' outside of string in %s
634 'X' outside of string in unpack
635 Useless (%s%c) - %suse /%c modifier in regex; marked by <-- HERE in m/%s/
636 Useless (%sc) - %suse /gc modifier in regex; marked by <-- HERE in m/%s/
637 Useless use of (?-p) in regex; marked by <-- HERE in m/%s/
638 Unmatched '%c' in POSIX class in regex; marked by <-- HERE in m/%s/
639 Unmatched '[' in POSIX class in regex; marked by <-- HERE in m/%s/
640 (?[...]) not valid in locale in regex; marked by <-- HERE in m/%s/
641 The regex_sets feature is experimental
642 Syntax error in (?[...]) in regex m/%s/
643 Unexpected character in regex; marked by <-- HERE in m/%s/
644 Unexpected binary operator '%c' with no preceding operand in regex; marked by <-- HERE in m/%s/
645 Unexpected '(' with no preceding operator in regex; marked by <-- HERE in m/%s/
646 Unexpected ')' in regex; marked by <-- HERE in m/%s/
647 Operand with no preceding operator in regex; marked by <-- HERE in m/%s/
648 Property '%s' is unknown in regex; marked by <-- HERE in m/%s/
649 Need exactly 3 octal digits in regex; marked by <-- HERE in m/%s/
650 Unrecognized escape \%c in character class in regex; marked by <-- HERE in m/%s/
651 Incomplete expression within '(?[ ])' in regex; marked by <-- HERE in m/%s/
652 Non-octal character in regex; marked by <-- HERE in m/%s/
653 Non-hex character in regex; marked by <-- HERE in m/%s/
654 Use \\x{...} for more than two hex characters in regex; marked by <-- HERE in m/%s/
657 Code point 0x%X is not Unicode, all \p{} matches fail; all \P{} matches succeed
658 Code point 0x%X is not Unicode, may not be portable
659 Illegal character \%o (carriage return)
660 Missing argument in %s
661 Unicode non-character U+%X is illegal for open interchange
662 Operation "%s" returns its argument for non-Unicode code point 0x%X
663 Operation "%s" returns its argument for UTF-16 surrogate U+%X
664 Unicode surrogate U+%X is illegal in UTF-8
665 UTF-16 surrogate U+%X
666 False [] range "%s" in regex; marked by <-- HERE in m/%s/
667 \N{} in character class restricted to one character in regex; marked by <-- HERE in m/%s/
668 Zero length \N{} in regex; marked by <-- HERE in m/%s/
669 Expecting '(?flags:(?[...' in regex; marked by <-- HERE in m/%s/