sort @files once, outside the loop.
[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 # Somewhere we chdir and can't load any more modules...
8 BEGIN {
9     if ($^O eq 'MSWin32') {
10         require Win32;
11     };
12     require overload;
13 };
14
15 {
16     package My::Pod::Checker;
17     use strict;
18     use parent 'Pod::Checker';
19
20     use vars '@errors'; # a bad, bad hack!
21
22     sub poderror {
23         my $self = shift;
24         my $opts;
25         if (ref $_[0]) {
26             $opts = shift;
27         };
28         ++($self->{_NUM_ERRORS})
29             if(!$opts || ($opts->{-severity} && $opts->{-severity} eq 'ERROR'));
30         ++($self->{_NUM_WARNINGS})
31             if(!$opts || ($opts->{-severity} && $opts->{-severity} eq 'WARNING'));
32         push @errors, $opts;
33     };
34 }
35
36
37 use strict;
38 use File::Spec;
39 chdir '..';
40 my @files;
41 my $manifest = 'MANIFEST';
42
43 open my $m, '<', $manifest or die "Can't open '$manifest': $!";
44
45 while (<$m>) {
46     chomp;
47     next unless /\s/;   # Ignore lines without whitespace (i.e., filename only)
48     my ($file, $separator) = /^(\S+)(\s+)/;
49         next if $file =~ /^cpan\//;
50         next unless ($file =~ /\.(?:pm|pod|pl)$/);
51     push @files, $file;
52 };
53 @files = sort @files; # so we get consistent results
54
55 sub pod_ok {
56     my ($filename) = @_;
57     local @My::Pod::Checker::errors;
58     my $checker = My::Pod::Checker->new(-quiet => 1);
59     $checker->parse_from_file($filename, undef);
60     my $error_count = $checker->num_errors();
61
62     if(! ok($error_count <= 0, "POD of $filename")) {
63         diag( "'$filename' contains POD errors" );
64         diag(sprintf "%s %s: %s at line %s",
65              $_->{-severity}, $_->{-file}, $_->{-msg}, $_->{-line})
66             for @My::Pod::Checker::errors;
67     };
68 };
69
70 plan (tests => scalar @files);
71
72 pod_ok $_
73     for @files;
74
75 __DATA__
76 lib/
77 ext/
78 pod/
79 AUTHORS
80 Changes
81 INSTALL
82 README*
83 *.pod