4 $ENV{AUTOMATED_TESTING} || $ENV{IMAGER_AUTHOR_TESTING}
5 or plan skip_all => "POD only tested under automated or author testing";
7 eval 'use Pod::Parser 1.50;';
8 plan skip_all => "Pod::Parser 1.50 required for podlinkcheck" if $@;
10 use File::Spec::Functions qw(rel2abs abs2rel splitdir);
11 use ExtUtils::Manifest qw(maniread);
13 # this test is intended to catch errors like in
14 # https://rt.cpan.org/Ticket/Display.html?id=85413
16 my @pod; # files with pod
18 my $base = rel2abs(".");
20 my $manifest = maniread();
22 my @files = sort grep /\.(pod|pm)$/ && !/^inc/, keys %$manifest;
26 for my $file (@files) {
27 my $parser = PodPreparse->new;
29 $parser->parse_from_file($file);
30 if ($parser->{is_pod}) {
35 plan tests => 3 * scalar(@pod);
37 my @req_head1s = qw(NAME DESCRIPTION AUTHOR);
40 my $parser = PodStructCheck->new;
41 my $relfile = abs2rel($file, $base);
42 $parser->{bad_quotes} = [];
43 $parser->{dup_words} = [];
44 $parser->parse_from_file($file);
47 for my $head (@req_head1s) {
48 push @missing, $head unless $parser->{head1s}{$head};
51 unless (ok(!@missing, "$relfile: check missing headers")) {
52 diag "$relfile: missing head1s @missing\n";
54 unless (ok(!@{$parser->{bad_quotes}}, "$relfile: check for bad quotes")) {
55 diag "$relfile:$_->[1]: bad quote in: $_->[0]"
56 for @{$parser->{bad_quotes}};
58 unless (ok(!@{$parser->{dup_words}}, "$relfile: check for duplicate words")) {
59 diag "$relfile:$_->[1]: dup word '$_->[0]' in: $_->[2]"
60 for @{$parser->{dup_words}};
65 BEGIN { our @ISA = qw(Pod::Parser); }
68 my ($self, $cmd, $para) = @_;
77 package PodStructCheck;
78 BEGIN { our @ISA = qw(Pod::Parser); }
81 my ($self, $command, $paragraph, $line_num) = @_;
83 if ($command eq "head1") {
84 $paragraph =~ s/\s+\z//;
85 $self->{head1s}{$paragraph} = 1;
87 if ($paragraph =~ /\A[^']*'\z/
88 || $paragraph =~ /\A[^"]*"\z/
89 || $paragraph =~ /\A'[^']*\z/
90 || $paragraph =~ /\A"[^"]*\z/) {
91 push @{$self->{bad_quotes}}, [ $paragraph, $line_num ];
99 my ($self, $text, $line_num) = @_;
101 if (my ($sample, $word) = $text =~ /(.{0,10}\b(\w+)\s+\2\b.{0,10})/s) {
102 # avoid catching "C C<something to do with C>"
104 push @{$self->{dup_words}}, [ $word, $line_num, $sample ];