Commit | Line | Data |
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. |
11 | sub 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. |
17 | skip_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. |
22 | eval 'use Test::Pod 1.00'; |
23 | skip_all "Test::Pod 1.00 required for testing POD" if $@; |
24 | eval 'use Pod::Spell'; |
25 | skip_all "Pod::Spell required to test POD spelling" if $@; |
26 | my @spell; |
2504ae52 |
27 | my %options = (aspell => [ qw(-d en_US --home-dir=./ list) ], |
28 | ispell => [ qw(-d american -l -p /dev/null) ]); |
29 | SEARCH: 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 |
37 | skip_all "aspell or ispell required to test POD spelling" unless @spell; |
0e4e3f6e |
38 | |
39 | # Run the test, one for each POD file. |
40 | $| = 1; |
41 | my @pod = all_pod_files (); |
42 | my $count = scalar @pod; |
43 | print "1..$count\n"; |
44 | my $n = 1; |
45 | for 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 | } |