Debian Codegraph @

README

raw
1 NAME
2 Test::Spelling - Check for spelling errors in POD files
3
4 SYNOPSIS
5 Place a file, "pod-spell.t" in your distribution's "xt/author"
6 directory:
7
8 use strict;
9 use warnings;
10 use Test::More;
11
12 use Test::Spelling;
13 use Pod::Wordlist;
14
15 add_stopwords(<DATA>);
16 all_pod_files_spelling_ok( qw( bin lib ) );
17
18 __DATA__
19 SomeBizarreWord
20 YetAnotherBIzarreWord
21
22 Or, you can gate the spelling test with the environment variable
23 "AUTHOR_TESTING":
24
25 use strict;
26 use warnings;
27 use Test::More;
28
29 BEGIN {
30 plan skip_all => "Spelling tests only for authors"
31 unless $ENV{AUTHOR_TESTING};
32 }
33
34 use Test::Spelling;
35 use Pod::Wordlist;
36
37 all_pod_files_spelling_ok();
38
39 DESCRIPTION
40 Test::Spelling lets you check the spelling of a "POD" file, and report
41 its results in standard Test::More fashion. This module requires a
42 spellcheck program such as Hunspell <http://hunspell.github.io/>,
43 aspell, spell, or, ispell. We suggest using Hunspell.
44
45 use Test::Spelling;
46 pod_file_spelling_ok('lib/Foo/Bar.pm', 'POD file spelling OK');
47
48 Note that it is a bad idea to run spelling tests during an ordinary CPAN
49 distribution install, or in a package that will run in an uncontrolled
50 environment. There is no way of predicting whether the word list or
51 spellcheck program used will give the same results. You can include the
52 test in your distribution, but be sure to run it only for authors of the
53 module by guarding it in a "skip_all unless $ENV{AUTHOR_TESTING}"
54 clause, or by putting the test in your distribution's xt/author
55 directory. Anyway, people installing your module really do not need to
56 run such tests, as it is unlikely that the documentation will acquire
57 typos while in transit.
58
59 You can add your own stop words, which are words that should be ignored
60 by the spell check, like so:
61
62 add_stopwords(qw(asdf thiswordiscorrect));
63
64 Adding stop words in this fashion affects all files checked for the
65 remainder of the test script. See Pod::Spell (which this module is built
66 upon) for a variety of ways to add per-file stop words to each .pm file.
67
68 If you have a lot of stop words, it's useful to put them in your test
69 file's "DATA" section like so:
70
71 use strict;
72 use warnings;
73 use Test::More;
74
75 use Test::Spelling;
76 use Pod::Wordlist;
77
78 add_stopwords(<DATA>);
79 all_pod_files_spelling_ok();
80
81 __DATA__
82 folksonomy
83 Jifty
84 Zakirov
85
86 To maintain backwards compatibility, comment markers and some whitespace
87 are ignored. In the near future, the preprocessing we do on the
88 arguments to "add_stopwords" in Test::Spelling will be changed and
89 documented properly.
90
91 FUNCTIONS
92 Test::Spelling makes the following methods available.
93
94 add_stopwords
95 add_stopwords(@words);
96 add_stopwords(<DATA>); # pull in stop words from the DATA section
97
98 Add words that should be skipped by the spell checker. Note that
99 Pod::Spell already skips words believed to be code, such as everything
100 in verbatim (indented) blocks and code marked up with "...", as well as
101 some common Perl jargon.
102
103 all_pod_files
104 all_pod_files();
105 all_pod_files(@list_of_directories);
106
107 Returns a list of all the Perl files in each directory and its
108 subdirectories, recursively. If no directories are passed, it defaults
109 to blib if blib exists, or else lib if not. Skips any files in CVS or
110 .svn directories.
111
112 A Perl file is:
113
114 * Any file that ends in .PL, .pl, .plx, .pm, .pod or .t.
115
116 * Any file that has a first line with a shebang and "perl" on it.
117
118 Furthermore, files for which the filter set by "set_pod_file_filter"
119 return false are skipped. By default, this filter passes everything
120 through.
121
122 The order of the files returned is machine-dependent. If you want them
123 sorted, you'll have to sort them yourself.
124
125 all_pod_files_spelling_ok
126 all_pod_files_spelling_ok(@list_of_files);
127 all_pod_files_spelling_ok(@list_of_directories);
128
129 Checks all the files for "POD" spelling. It gathers "all_pod_files" in
130 Test::Spelling on each file/directory, and declares a "plan" in
131 Test::More for you (one test for each file), so you must not call "plan"
132 yourself.
133
134 If @files is empty, the function finds all "POD" files in the blib
135 directory if it exists, or the lib directory if it does not. A "POD"
136 file is one that ends with .pod, .pl, .plx, or .pm; or any file where
137 the first line looks like a perl shebang line.
138
139 If there is no working spellchecker (determined by
140 <Test:Spelling/"has_working_spellchecker">), this test will issue a
141 "skip all" directive.
142
143 If you're testing a distribution, just create an xt/author/pod-spell.t
144 with the code in the "SYNOPSIS".
145
146 Returns true if every "POD" file has correct spelling, or false if any
147 of them fail. This function will show any spelling errors as
148 diagnostics.
149
150 * NOTE: This only tests using bytes. This is not decoded content, etc.
151 Do not expect this to work with Unicode content, for example. This uses
152 an open with no layers and no decoding.
153
154 get_pod_parser
155 # a Pod::Spell -like object
156 my $object = get_pod_parser();
157
158 Get the object we're using to parse the "POD". A new Pod::Spell object
159 should be used for every file. People providing custom parsers will have
160 to do this themselves.
161
162 has_working_spellchecker
163 my $cmd = has_working_spellchecker;
164
165 "has_working_spellchecker" will return "undef" if there is no working
166 spellchecker, or a true value (the spellchecker command itself) if there
167 is. The module performs a dry-run to determine whether any of the
168 spellcheckers it can will use work on the current system. You can use
169 this to skip tests if there is no spellchecker. Note that
170 "all_pod_files_spelling_ok" will do this for you.
171
172 A full list of spellcheckers which this method might test can be found
173 in the source of the "spellchecker_candidates" method.
174
175 pod_file_spelling_ok
176 pod_file_spelling_ok('/path/to/Foo.pm');
177 pod_file_spelling_ok('/path/to/Foo.pm', 'Foo is well spelled!');
178
179 "pod_file_spelling_ok" will test that the given "POD" file has no
180 spelling errors.
181
182 When it fails, "pod_file_spelling_ok" will show any spelling errors as
183 diagnostics.
184
185 The optional second argument is the name of the test. If it is omitted,
186 "pod_file_spelling_ok" chooses a default test name "POD spelling for
187 $filename".
188
189 * NOTE: This only tests using bytes. This is not decoded content, etc.
190 Do not expect this to work with Unicode content, for example. This uses
191 an open with no layers and no decoding.
192
193 set_pod_file_filter
194 # code ref
195 set_pod_file_filter(sub {
196 my $filename = shift;
197 return 0 if $filename =~ /_ja.pod$/; # skip Japanese translations
198 return 1;
199 });
200
201 If your project has "POD" documents written in languages other than
202 English, then obviously you don't want to be running a spellchecker on
203 every Perl file. "set_pod_file_filter" lets you filter out files
204 returned from "all_pod_files" (and hence, the documents tested by
205 "all_pod_files_spelling_ok").
206
207 set_pod_parser
208 my $object = Pod::Spell->new();
209 set_pod_parser($object);
210
211 By default Pod::Spell is used to generate text suitable for
212 spellchecking from the input POD. If you want to use a different parser,
213 perhaps a customized subclass of Pod::Spell, call "set_pod_parser" with
214 an object that is-a Pod::Parser. Be sure to create a fresh parser object
215 for each file (don't use this with "all_pod_files_spelling_ok").
216
217 set_spell_cmd
218 set_spell_cmd('hunspell -l'); # current preferred
219 set_spell_cmd('aspell list');
220 set_spell_cmd('spell');
221 set_spell_cmd('ispell -l');
222
223 If you want to force this module to use a particular spellchecker, then
224 you can specify which one with "set_spell_cmd". This is useful to ensure
225 a more consistent lexicon between developers, or if you have an unusual
226 environment. Any command that takes text from standard input and prints
227 a list of misspelled words, one per line, to standard output will do.
228
229 SEE ALSO
230 Pod::Spell
231
232 AUTHOR
233 Ivan Tubert-Brohman "<[email protected]>"
234
235 Heavily based on Test::Pod by Andy Lester and brian d foy.
236
237 COPYRIGHT & LICENSE
238 Copyright 2005, Ivan Tubert-Brohman, All Rights Reserved.
239
240 You may use, modify, and distribute this package under the same terms as
241 Perl itself.
242