source: web/old/remctl-2.14/tests/docs/pod-spelling-t @ f6f3e91

web
Last change on this file since f6f3e91 was f6f3e91, checked in by Jessica B. Hamrick <jhamrick@…>, 15 years ago

Preserve directory hierarchy (not sure what happened to it)

  • Property mode set to 100755
File size: 2.4 KB
Line 
1#!/usr/bin/perl
2#
3# Check for spelling errors in POD documentation
4#
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>
11#
12# See LICENSE for licensing terms.
13
14use strict;
15use Test::More;
16
17# Skip all spelling tests unless the maintainer environment variable is set.
18plan skip_all => 'Spelling tests only run for maintainer'
19    unless $ENV{RRA_MAINTAINER_TESTS};
20
21# Load required Perl modules.
22eval 'use Test::Pod 1.00';
23plan skip_all => 'Test::Pod 1.00 required for testing POD' if $@;
24eval 'use Pod::Spell';
25plan skip_all => 'Pod::Spell required to test POD spelling' if $@;
26
27# Locate a spell-checker.  hunspell is not currently supported due to its lack
28# of support for contractions (at least in the version in Debian).
29my @spell;
30my %options = (aspell => [ qw(-d en_US --home-dir=./ list) ],
31               ispell => [ qw(-d american -l -p /dev/null) ]);
32SEARCH: for my $program (qw/aspell ispell/) {
33    for my $dir (split ':', $ENV{PATH}) {
34        if (-x "$dir/$program") {
35            @spell = ("$dir/$program", @{ $options{$program} });
36        }
37        last SEARCH if @spell;
38    }
39}
40plan skip_all => 'aspell or ispell required to test POD spelling'
41    unless @spell;
42
43# Prerequisites are satisfied, so we're going to do some testing.  Figure out
44# what POD files we have and from that develop our plan.
45$| = 1;
46my @pod = map { s,[^/]+/../,,; $_ }
47    (glob ("$ENV{SOURCE}/../docs/*.pod"),
48     glob ("$ENV{SOURCE}/../docs/api/*.pod"));
49plan tests => scalar @pod;
50
51# Finally, do the checks.
52for my $pod (@pod) {
53    my $child = open (CHILD, '-|');
54    if (not defined $child) {
55        die "Cannot fork: $!\n";
56    } elsif ($child == 0) {
57        my $pid = open (SPELL, '|-', @spell) or die "Cannot run @spell: $!\n";
58        open (POD, '<', $pod) or die "Cannot open $pod: $!\n";
59        my $parser = Pod::Spell->new;
60        $parser->parse_from_filehandle (\*POD, \*SPELL);
61        close POD;
62        close SPELL;
63        exit ($? >> 8);
64    } else {
65        my @words = <CHILD>;
66        close CHILD;
67      SKIP: {
68            skip "@spell failed for $pod", 1 unless $? == 0;
69            for (@words) {
70                s/^\s+//;
71                s/\s+$//;
72            }
73            is ("@words", '', $pod);
74        }
75    }
76}
Note: See TracBrowser for help on using the repository browser.