This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Spelling correction for consistency with pod/perldebguts.pod.
[perl5.git] / t / porting / podcheck.t
index d267f71..da52e26 100644 (file)
@@ -29,6 +29,10 @@ BEGIN {
         print "1..0 # $^O cannot handle this test\n";
         exit(0);
     }
+    if ( $ENV{'PERL_BUILD_PACKAGING'} ) {
+        print "1..0 # This distro may have modified some files in cpan/. Skipping validation. \n";
+        exit 0;
+    }
     require '../regen/regen_lib.pl';
 }
 
@@ -93,6 +97,13 @@ missing from the C<LE<lt>E<gt>> pod command.
 A pod can't be linked to unless it has a unique name.
 And a NAME should have a dash and short description after it.
 
+=item Occurrences of the Unicode replacement character
+
+L<Pod::Simple> replaces bytes that aren't valid according to the document's
+encoding (declared or auto-detected) with C<\N{REPLACEMENT CHARACTER}>.
+
+=back
+
 If the C<PERL_POD_PEDANTIC> environment variable is set or the C<--pedantic>
 command line argument is provided then a few more checks are made.
 The pedantic checks are:
@@ -155,8 +166,6 @@ Another problem is that there is currently no check that modules listed as
 valid in the database
 actually are.  Thus any errors introduced there will remain there.
 
-=back
-
 =head2 Specially handled pods
 
 =over
@@ -361,6 +370,7 @@ my $multiple_targets = "There is more than one target";
 my $duplicate_name = "Pod NAME already used";
 my $no_name = "There is no NAME";
 my $missing_name_description = "The NAME should have a dash and short description after it";
+my $replacement_character = "Unicode replacement character found";
 # the pedantic warnings messages
 my $line_length = "Verbatim line length including indents exceeds $MAX_LINE_LENGTH by";
 my $C_not_linked = "? Should you be using L<...> instead of";
@@ -422,12 +432,14 @@ my $non_pods = qr/ (?: \.
                            | $dl_ext  # dynamic libraries
                            | gif      # GIF images (example files from CGI.pm)
                            | eg       # examples from libnet
+                           | core .*
                        )
                        $
                     ) | ~$ | \ \(Autosaved\)\.txt$ # Other editor droppings
                            | ^cxx\$demangler_db\.$ # VMS name mangler database
                            | ^typemap\.?$          # typemap files
                            | ^(?i:Makefile\.PL)$
+                           | ^core (?: $ | \. .* )
                 /x;
 
 # Matches something that looks like a file name, but is enclosed in C<...>
@@ -435,7 +447,7 @@ my $C_path_re = qr{ ^
                         # exclude various things that have slashes
                         # in them but aren't paths
                         (?!
-                            (?: (?: s | qr | m) / ) # regexes
+                            (?: (?: s | qr | m | tr | y ) / ) # regexes
                             | \d+/\d+ \b       # probable fractions
                             | (?: [LF] < )+
                             | OS/2 \b
@@ -531,16 +543,20 @@ sub suppressed {
         last SKIP;
     }
 
-    sub note {
-        my $message = shift;
+    sub _note {
+        my ($andle, $message) = @_;
 
         chomp $message;
 
-        print $message =~ s/^/# /mgr;
-        print "\n";
+        print $andle $message =~ s/^/# /mgr;
+        print $andle "\n";
         return;
     }
 
+    sub note { unshift @_, \*STDOUT; goto &_note }
+
+    sub diag { unshift @_, \*STDERR; goto &_note }
+
     END {
         if ($planned && $planned != $current_test) {
             print STDERR
@@ -848,6 +864,16 @@ package My::Pod::Checker {      # Extend Pod::Checker
             $running_CFL_text{$addr} .= $text;
         }
 
+        # do this line-by-line so we can get the right line number
+        my @lines = split /^/, $running_simple_text{$addr};
+        for my $i (0..$#lines) {
+            if ($lines[$i] =~ m/\N{REPLACEMENT CHARACTER}/) {
+                $self->poderror({ -line => $start_line{$addr} + $i,
+                    -msg => $replacement_character,
+                    parameter => "possibly invalid ". $self->encoding . " input at character " . pos $lines[$i],
+                });
+            }
+        }
         return $return;
     }
 
@@ -2095,7 +2121,8 @@ foreach my $filename (@files) {
                     $diagnostic .= " " if $problem_count == 1;
                     $diagnostic .= "\n$indent$indent";
                     $diagnostic .= "$problem->{parameter}" if $problem->{parameter};
-                    $diagnostic .= " near line $problem->{-line}";
+                    $diagnostic .= " near line $problem->{-line} of "
+                                   . $filename;
                     $diagnostic .= " $problem->{comment}" if $problem->{comment};
                 }
                 $diagnostic .= "\n";
@@ -2133,7 +2160,7 @@ foreach my $filename (@files) {
         }
         ok(@diagnostics == $thankful_diagnostics, $output);
         if (@diagnostics) {
-            note(join "", @diagnostics,
+            diag(join "", @diagnostics,
             "See end of this test output for your options on silencing this");
         }
 
@@ -2165,7 +2192,7 @@ if (%files_with_unknown_issues) {
                         : "were $were_count_files files";
     my $message = <<EOF;
 
-HOW TO GET THIS .t TO PASS
+HOW TO GET ${\__FILE__} TO PASS
 
 There $were_count_files that had new potential problems identified.
 Some of them may be real, and some of them may be false positives because
@@ -2204,9 +2231,9 @@ EOF
    and change the count of known potential problems to -1.
 EOF
 
-    note($message);
+    diag($message);
 } elsif (%files_with_fixes) {
-    note(<<EOF
+    diag(<<EOF
 To teach this test script that the potential problems have been fixed,
 $how_to
 EOF