Upgrade to podlators 2.1.2
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / pod-spelling.t
1 #!/usr/bin/perl
2 #
3 # t/pod-spelling.t -- Test POD spelling.
4
5 # Called to skip all tests with a reason.
6 sub skip_all {
7     print "1..1\n";
8     print "ok 1 # skip - @_\n";
9     exit;
10 }
11
12 # Make sure we have prerequisites.  hunspell is currently not supported due to
13 # lack of support for contractions.
14 eval 'use Test::Pod 1.00';
15 skip_all "Test::Pod 1.00 required for testing POD" if $@;
16 eval 'use Pod::Spell';
17 skip_all "Pod::Spell required to test POD spelling" if $@;
18 my @spell;
19 for my $dir (split ':', $ENV{PATH}) {
20     if (-x "$dir/ispell") {
21         @spell = ("$dir/ispell", '-d', 'american', '-l');
22     }
23     last if @spell;
24 }
25 skip_all "ispell required to test POD spelling" unless @spell;
26
27 # Run the test, one for each POD file.
28 $| = 1;
29 my @pod = all_pod_files ();
30 my $count = scalar @pod;
31 print "1..$count\n";
32 my $n = 1;
33 for my $pod (@pod) {
34     my $child = open (CHILD, '-|');
35     if (not defined $child) {
36         die "Cannot fork: $!\n";
37     } elsif ($child == 0) {
38         my $pid = open (SPELL, '|-', @spell) or die "Cannot run @spell: $!\n";
39         open (POD, '<', $pod) or die "Cannot open $pod: $!\n";
40         my $parser = Pod::Spell->new;
41         $parser->parse_from_filehandle (\*POD, \*SPELL);
42         close POD;
43         close SPELL;
44         exit ($? >> 8);
45     } else {
46         my @words = <CHILD>;
47         close CHILD;
48         if ($? != 0) {
49             print "ok $n # skip - @spell failed\n";
50         } elsif (@words) {
51             for (@words) {
52                 s/^\s+//;
53                 s/\s+$//;
54             }
55             print "not ok $n\n";
56             print " - Misspelled words found in $pod\n";
57             print "   @words\n";
58         } else {
59             print "ok $n\n";
60         }
61         $n++;
62     }
63 }