Move podlators from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / podlators / t / pod-spelling.t
CommitLineData
0e4e3f6e 1#!/usr/bin/perl
2#
3# t/pod-spelling.t -- Test POD spelling.
9f2f055a 4#
5# Copyright 2008 Russ Allbery <rra@stanford.edu>
6#
7# This program is free software; you may redistribute it and/or modify it
8# under the same terms as Perl itself.
0e4e3f6e 9
10# Called to skip all tests with a reason.
11sub skip_all {
9f2f055a 12 print "1..0 # Skipped: @_\n";
0e4e3f6e 13 exit;
14}
15
9f2f055a 16# Skip all spelling tests unless flagged to run maintainer tests.
17skip_all "Spelling tests only run for maintainer"
18 unless $ENV{RRA_MAINTAINER_TESTS};
19
0e4e3f6e 20# Make sure we have prerequisites. hunspell is currently not supported due to
21# lack of support for contractions.
22eval 'use Test::Pod 1.00';
23skip_all "Test::Pod 1.00 required for testing POD" if $@;
24eval 'use Pod::Spell';
25skip_all "Pod::Spell required to test POD spelling" if $@;
26my @spell;
2504ae52 27my %options = (aspell => [ qw(-d en_US --home-dir=./ list) ],
28 ispell => [ qw(-d american -l -p /dev/null) ]);
29SEARCH: for my $program (qw/aspell ispell/) {
30 for my $dir (split ':', $ENV{PATH}) {
31 if (-x "$dir/$program") {
32 @spell = ("$dir/$program", @{ $options{$program} });
33 }
34 last SEARCH if @spell;
0e4e3f6e 35 }
0e4e3f6e 36}
2504ae52 37skip_all "aspell or ispell required to test POD spelling" unless @spell;
0e4e3f6e 38
39# Run the test, one for each POD file.
40$| = 1;
41my @pod = all_pod_files ();
42my $count = scalar @pod;
43print "1..$count\n";
44my $n = 1;
45for my $pod (@pod) {
46 my $child = open (CHILD, '-|');
47 if (not defined $child) {
48 die "Cannot fork: $!\n";
49 } elsif ($child == 0) {
2504ae52 50 my $pid = open (SPELL, '|-', @spell)
51 or die "Cannot run @spell: $!\n";
0e4e3f6e 52 open (POD, '<', $pod) or die "Cannot open $pod: $!\n";
53 my $parser = Pod::Spell->new;
54 $parser->parse_from_filehandle (\*POD, \*SPELL);
55 close POD;
56 close SPELL;
57 exit ($? >> 8);
58 } else {
59 my @words = <CHILD>;
60 close CHILD;
61 if ($? != 0) {
2504ae52 62 print "ok $n # skip - @spell failed: $?\n";
0e4e3f6e 63 } elsif (@words) {
64 for (@words) {
65 s/^\s+//;
66 s/\s+$//;
67 }
68 print "not ok $n\n";
69 print " - Misspelled words found in $pod\n";
70 print " @words\n";
71 } else {
72 print "ok $n\n";
73 }
74 $n++;
75 }
76}