Update to podlators 2.3.0
[p5sagit/p5-mst-13.2.git] / cpan / podlators / t / pod-spelling.t
CommitLineData
fe61459e 1#!/usr/bin/perl -w
0e4e3f6e 2#
fe61459e 3# Check for spelling errors in POD documentation
9f2f055a 4#
fe61459e 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.
9#
10# Copyright 2008, 2009 Russ Allbery <rra@stanford.edu>
9f2f055a 11#
12# This program is free software; you may redistribute it and/or modify it
13# under the same terms as Perl itself.
0e4e3f6e 14
fe61459e 15use strict;
16use Test::More;
0e4e3f6e 17
fe61459e 18# Skip all spelling tests unless the maintainer environment variable is set.
19plan skip_all => 'Spelling tests only run for maintainer'
9f2f055a 20 unless $ENV{RRA_MAINTAINER_TESTS};
21
fe61459e 22# Load required Perl modules.
0e4e3f6e 23eval 'use Test::Pod 1.00';
fe61459e 24plan skip_all => 'Test::Pod 1.00 required for testing POD' if $@;
0e4e3f6e 25eval 'use Pod::Spell';
fe61459e 26plan skip_all => 'Pod::Spell required to test POD spelling' if $@;
27
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).
0e4e3f6e 30my @spell;
2504ae52 31my %options = (aspell => [ qw(-d en_US --home-dir=./ list) ],
32 ispell => [ qw(-d american -l -p /dev/null) ]);
33SEARCH: for my $program (qw/aspell ispell/) {
34 for my $dir (split ':', $ENV{PATH}) {
35 if (-x "$dir/$program") {
36 @spell = ("$dir/$program", @{ $options{$program} });
37 }
38 last SEARCH if @spell;
0e4e3f6e 39 }
0e4e3f6e 40}
fe61459e 41plan skip_all => 'aspell or ispell required to test POD spelling'
42 unless @spell;
0e4e3f6e 43
fe61459e 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.
0e4e3f6e 46$| = 1;
47my @pod = all_pod_files ();
fe61459e 48plan tests => scalar @pod;
49
50# Finally, do the checks.
0e4e3f6e 51for my $pod (@pod) {
52 my $child = open (CHILD, '-|');
53 if (not defined $child) {
54 die "Cannot fork: $!\n";
55 } elsif ($child == 0) {
fe61459e 56 my $pid = open (SPELL, '|-', @spell) or die "Cannot run @spell: $!\n";
0e4e3f6e 57 open (POD, '<', $pod) or die "Cannot open $pod: $!\n";
58 my $parser = Pod::Spell->new;
59 $parser->parse_from_filehandle (\*POD, \*SPELL);
60 close POD;
61 close SPELL;
62 exit ($? >> 8);
63 } else {
64 my @words = <CHILD>;
65 close CHILD;
fe61459e 66 SKIP: {
67 skip "@spell failed for $pod", 1 unless $? == 0;
0e4e3f6e 68 for (@words) {
69 s/^\s+//;
70 s/\s+$//;
71 }
fe61459e 72 is ("@words", '', $pod);
0e4e3f6e 73 }
0e4e3f6e 74 }
75}