#!/usr/bin/perl
sub
skip_all {
print
"1..0 # Skipped: @_\n"
;
exit
;
}
skip_all
"Spelling tests only run for maintainer"
unless
$ENV
{RRA_MAINTAINER_TESTS};
eval
'use Test::Pod 1.00'
;
skip_all
"Test::Pod 1.00 required for testing POD"
if
$@;
eval
'use Pod::Spell'
;
skip_all
"Pod::Spell required to test POD spelling"
if
$@;
my
@spell
;
my
%options
= (
aspell
=> [
qw(-d en_US --home-dir=./ list)
],
ispell
=> [
qw(-d american -l -p /dev/null)
]);
SEARCH:
for
my
$program
(
qw/aspell ispell/
) {
for
my
$dir
(
split
':'
,
$ENV
{PATH}) {
if
(-x
"$dir/$program"
) {
@spell
= (
"$dir/$program"
, @{
$options
{
$program
} });
}
last
SEARCH
if
@spell
;
}
}
skip_all
"aspell or ispell required to test POD spelling"
unless
@spell
;
$| = 1;
my
@pod
= all_pod_files ();
my
$count
=
scalar
@pod
;
print
"1..$count\n"
;
my
$n
= 1;
for
my
$pod
(
@pod
) {
my
$child
=
open
(CHILD,
'-|'
);
if
(not
defined
$child
) {
die
"Cannot fork: $!\n"
;
}
elsif
(
$child
== 0) {
my
$pid
=
open
(SPELL,
'|-'
,
@spell
)
or
die
"Cannot run @spell: $!\n"
;
open
(POD,
'<'
,
$pod
) or
die
"Cannot open $pod: $!\n"
;
my
$parser
= Pod::Spell->new;
$parser
->parse_from_filehandle (\
*POD
, \
*SPELL
);
close
POD;
close
SPELL;
exit
($? >> 8);
}
else
{
my
@words
= <CHILD>;
close
CHILD;
if
($? != 0) {
print
"ok $n # skip - @spell failed: $?\n"
;
}
elsif
(
@words
) {
for
(
@words
) {
s/^\s+//;
s/\s+$//;
}
print
"not ok $n\n"
;
print
" - Misspelled words found in $pod\n"
;
print
" @words\n"
;
}
else
{
print
"ok $n\n"
;
}
$n
++;
}
}