runperl may modify arguments passed to it.
[p5sagit/p5-mst-13.2.git] / t / porting / podcheck.t
1 #!/usr/bin/perl -w
2
3 require './test.pl';
4
5 use strict;
6
7 {
8     package My::Pod::Checker;
9     use strict;
10     use parent 'Pod::Checker';
11
12     use vars '@errors'; # a bad, bad hack!
13
14     sub poderror {
15         my $self = shift;
16         my $opts;
17         if (ref $_[0]) {
18             $opts = shift;
19         };
20         ++($self->{_NUM_ERRORS})
21             if(!$opts || ($opts->{-severity} && $opts->{-severity} eq 'ERROR'));
22         ++($self->{_NUM_WARNINGS})
23             if(!$opts || ($opts->{-severity} && $opts->{-severity} eq 'WARNING'));
24         push @errors, $opts;
25     };
26 }
27
28
29 use strict;
30 use File::Spec;
31 s{^\.\./lib$}{lib} for @INC;
32 chdir '..';
33 my @files;
34 my $manifest = 'MANIFEST';
35
36 open my $m, '<', $manifest or die "Can't open '$manifest': $!";
37
38 while (<$m>) {
39     chomp;
40     next unless /\s/;   # Ignore lines without whitespace (i.e., filename only)
41     my ($file, $separator) = /^(\S+)(\s+)/;
42         next if $file =~ /^cpan\//;
43         next unless ($file =~ /\.(?:pm|pod|pl)$/);
44     push @files, $file;
45 };
46 @files = sort @files; # so we get consistent results
47
48 sub pod_ok {
49     my ($filename) = @_;
50     local @My::Pod::Checker::errors;
51     my $checker = My::Pod::Checker->new(-quiet => 1);
52     $checker->parse_from_file($filename, undef);
53     my $error_count = $checker->num_errors();
54
55     if(! ok($error_count <= 0, "POD of $filename")) {
56         diag( "'$filename' contains POD errors" );
57         diag(sprintf "%s %s: %s at line %s",
58              $_->{-severity}, $_->{-file}, $_->{-msg}, $_->{-line})
59             for @My::Pod::Checker::errors;
60     };
61 };
62
63 plan (tests => scalar @files);
64
65 pod_ok $_
66     for @files;
67
68 __DATA__
69 lib/
70 ext/
71 pod/
72 AUTHORS
73 Changes
74 INSTALL
75 README*
76 *.pod