1Test::Spelling(3) User Contributed Perl Documentation Test::Spelling(3)
2
3
4
6 Test::Spelling - check for spelling errors in POD files
7
9 use Test::More;
10 BEGIN {
11 plan skip_all => "Spelling tests only for authors"
12 unless -d 'inc/.author';
13 }
14
15 use Test::Spelling;
16 all_pod_files_spelling_ok();
17
19 "Test::Spelling" lets you check the spelling of a POD file, and report
20 its results in standard "Test::More" fashion. This module requires a
21 spellcheck program such as spell, aspell, ispell, or hunspell.
22
23 use Test::Spelling;
24 pod_file_spelling_ok('lib/Foo/Bar.pm', 'POD file spelling OK');
25
26 Note that it is a bad idea to run spelling tests during an ordinary
27 CPAN distribution install, or in a package that will run in an
28 uncontrolled environment. There is no way of predicting whether the
29 word list or spellcheck program used will give the same results. You
30 can include the test in your distribution, but be sure to run it only
31 for authors of the module by guarding it in a "skip_all unless -d
32 'inc/.author'" clause, or by putting the test in your distribution's
33 xt/ directory. Anyway, people installing your module really do not need
34 to run such tests, as it is unlikely that the documentation will
35 acquire typos while in transit. :-)
36
37 You can add your own stopwords, which are words that should be ignored
38 by the spell check, like so:
39
40 add_stopwords(qw(asdf thiswordiscorrect));
41
42 Adding stopwards in this fashion affects all files checked for the
43 remainder of the test script. See Pod::Spell (which this module is
44 built upon) for a variety of ways to add per-file stopwords to each .pm
45 file.
46
47 If you have a lot of stopwords, it's useful to put them in your test
48 file's "DATA" section like so:
49
50 use Test::Spelling;
51 add_stopwords(<DATA>);
52 all_pod_files_spelling_ok();
53
54 __END__
55 folksonomy
56 Jifty
57 Zakirov
58
59 To maintain backwards compatibility, comment markers and some
60 whitespace are ignored. In the near future, the preprocessing we do on
61 the arguments to add_stopwords will be changed and documented properly.
62
64 all_pod_files_spelling_ok( [@files/@directories] )
65 Checks all the files for POD spelling. It gathers all_pod_files() on
66 each file/directory, and declares a "plan" in Test::More for you (one
67 test for each file), so you must not call "plan" yourself.
68
69 If @files is empty, the function finds all POD files in the blib
70 directory if it exists, or the lib directory if it does not. A POD file
71 is one that ends with .pod, .pl, .plx, or .pm; or any file where the
72 first line looks like a perl shebang line.
73
74 If there is no working spellchecker (determined by
75 "has_working_spellchecker"), this test will issue a "skip all"
76 directive.
77
78 If you're testing a distribution, just create a t/pod-spell.t with the
79 code in the "SYNOPSIS".
80
81 Returns true if every POD file has correct spelling, or false if any of
82 them fail. This function will show any spelling errors as diagnostics.
83
84 pod_file_spelling_ok( FILENAME[, TESTNAME ] )
85 "pod_file_spelling_ok" will test that the given POD file has no
86 spelling errors.
87
88 When it fails, "pod_file_spelling_ok" will show any spelling errors as
89 diagnostics.
90
91 The optional second argument TESTNAME is the name of the test. If it
92 is omitted, "pod_file_spelling_ok" chooses a default test name "POD
93 spelling for FILENAME".
94
95 all_pod_files( [@dirs] )
96 Returns a list of all the Perl files in each directory and its
97 subdirectories, recursively. If no directories are passed, it defaults
98 to blib if blib exists, or else lib if not. Skips any files in CVS or
99 .svn directories.
100
101 A Perl file is:
102
103 · Any file that ends in .PL, .pl, .plx, .pm, .pod or .t.
104
105 · Any file that has a first line with a shebang and "perl" on it.
106
107 Furthermore, files for which the filter set by "set_pod_file_filter"
108 return false are skipped. By default, this filter passes everything
109 through.
110
111 The order of the files returned is machine-dependent. If you want them
112 sorted, you'll have to sort them yourself.
113
114 add_stopwords(@words)
115 Add words that should be skipped by the spellcheck. Note that
116 Pod::Spell already skips words believed to be code, such as everything
117 in verbatim (indented) blocks and code marked up with ""..."", as well
118 as some common Perl jargon.
119
120 has_working_spellchecker
121 "has_working_spellchecker" will return "undef" if there is no working
122 spellchecker, or a true value (the spellchecker command itself) if
123 there is. The module performs a dry-run to determine whether any of
124 the spellcheckers it can will use work on the current system. You can
125 use this to skip tests if there is no spellchecker. Note that
126 "all_pod_files_spelling_ok" will do this for you.
127
128 set_spell_cmd($command)
129 If you want to force this module to use a particular spellchecker, then
130 you can specify which one with "set_spell_cmd". This is useful to
131 ensure a more consistent lexicon between developers, or if you have an
132 unusual environment. Any command that takes text from standard input
133 and prints a list of misspelled words, one per line, to standard output
134 will do.
135
136 set_pod_file_filter($code)
137 If your project has POD documents written in languages other than
138 English, then obviously you don't want to be running a spellchecker on
139 every Perl file. "set_pod_file_filter" lets you filter out files
140 returned from "all_pod_files" (and hence, the documents tested by
141 "all_pod_files_spelling_ok").
142
143 set_pod_file_filter(sub {
144 my $filename = shift;
145 return 0 if $filename =~ /_ja.pod$/; # skip Japanese translations
146 return 1;
147 });
148
150 Pod::Spell
151
153 Ivan Tubert-Brohman "<itub@cpan.org>"
154
155 Heavily based on Test::Pod by Andy Lester and brian d foy.
156
158 Shawn M Moore "<sartak@bestpractical.com>"
159
161 Copyright 2005, Ivan Tubert-Brohman, All Rights Reserved.
162
163 You may use, modify, and distribute this package under the same terms
164 as Perl itself.
165
166
167
168perl v5.12.3 2011-08-11 Test::Spelling(3)