Check POD in lib/, ext/ and pod/
[p5sagit/p5-mst-13.2.git] / t / porting / podcheck.t
1 #!/usr/bin/perl -w
2 BEGIN {
3     chdir 't' if -d 't';
4     @INC = '../lib';
5 }
6
7 use strict;
8
9 # Somewhere we chdir and can't load any more modules...
10 BEGIN {
11     if ($^O eq 'MSWin32') {
12         require Win32;
13     };
14     require overload;
15 };
16
17 use Test::More;
18 use File::Find ();
19
20 {
21     package My::Pod::Checker;
22     use strict;
23     use parent 'Pod::Checker';
24
25     use vars '@errors'; # a bad, bad hack!
26
27     sub poderror {
28         my $self = shift;
29         my $opts;
30         if (ref $_[0]) {
31             $opts = shift;
32         };
33         ++($self->{_NUM_ERRORS})
34             if(!$opts || ($opts->{-severity} && $opts->{-severity} eq 'ERROR'));
35         ++($self->{_NUM_WARNINGS})
36             if(!$opts || ($opts->{-severity} && $opts->{-severity} eq 'WARNING'));
37         push @errors, $opts;
38     };
39 }
40
41 my @files = @ARGV;
42 if (! @files) {
43     chdir '..'
44         or die "Couldn't chdir to ..: $!";
45     chomp( my @d = <DATA> );
46     File::Find::find({
47         no_chdir => 1,
48         wanted   => sub {
49                 return unless $File::Find::name =~ /(\.(pod|pm|pl))$/i;
50                 push @files, $File::Find::name;
51             },
52         }, grep { m!/$! } @d );
53     push @files, map { chomp; glob($_) } grep { ! m!/$! } @d;
54     @files = sort @files; # so we get consistent results
55 };
56
57 sub pod_ok {
58     my ($filename) = @_;
59     local @My::Pod::Checker::errors;
60     my $checker = My::Pod::Checker->new(-quiet => 1);
61     $checker->parse_from_file($filename, undef);
62     my $error_count = $checker->num_errors();
63
64     if(! ok $error_count <= 0, "POD of $filename") {
65         diag( "'$filename' contains POD errors" );
66         diag sprintf "%s %s: %s at line %s",
67              $_->{-severity}, $_->{-file}, $_->{-msg}, $_->{-line}
68             for @My::Pod::Checker::errors;
69     };
70 };
71
72 plan tests => scalar @files;
73
74 pod_ok $_
75     for @files;
76
77 __DATA__
78 lib/
79 ext/
80 pod/
81 AUTHORS
82 Changes
83 INSTALL
84 README*
85 *.pod