3 # Check for spelling errors in POD documentation
5 # Checks all POD files in the tree for spelling problems using Pod::Spell and
6 # either aspell or ispell. aspell is preferred. This test is disabled unless
7 # RRA_MAINTAINER_TESTS is set, since spelling dictionaries vary too much
8 # between environments.
10 # Copyright 2008, 2009 Russ Allbery <rra@stanford.edu>
12 # This program is free software; you may redistribute it and/or modify it
13 # under the same terms as Perl itself.
18 # Skip all spelling tests unless the maintainer environment variable is set.
19 plan skip_all => 'Spelling tests only run for maintainer'
20 unless $ENV{RRA_MAINTAINER_TESTS};
22 # Load required Perl modules.
23 eval 'use Test::Pod 1.00';
24 plan skip_all => 'Test::Pod 1.00 required for testing POD' if $@;
25 eval 'use Pod::Spell';
26 plan skip_all => 'Pod::Spell required to test POD spelling' if $@;
28 # Locate a spell-checker. hunspell is not currently supported due to its lack
29 # of support for contractions (at least in the version in Debian).
31 my %options = (aspell => [ qw(-d en_US --home-dir=./ list) ],
32 ispell => [ qw(-d american -l -p /dev/null) ]);
33 SEARCH: for my $program (qw/aspell ispell/) {
34 for my $dir (split ':', $ENV{PATH}) {
35 if (-x "$dir/$program") {
36 @spell = ("$dir/$program", @{ $options{$program} });
38 last SEARCH if @spell;
41 plan skip_all => 'aspell or ispell required to test POD spelling'
44 # Prerequisites are satisfied, so we're going to do some testing. Figure out
45 # what POD files we have and from that develop our plan.
47 my @pod = all_pod_files ();
48 plan tests => scalar @pod;
50 # Finally, do the checks.
52 my $child = open (CHILD, '-|');
53 if (not defined $child) {
54 die "Cannot fork: $!\n";
55 } elsif ($child == 0) {
56 my $pid = open (SPELL, '|-', @spell) or die "Cannot run @spell: $!\n";
57 open (POD, '<', $pod) or die "Cannot open $pod: $!\n";
58 my $parser = Pod::Spell->new;
59 $parser->parse_from_filehandle (\*POD, \*SPELL);
67 skip "@spell failed for $pod", 1 unless $? == 0;
72 is ("@words", '', $pod);