1Devel::Cover(3) User Contributed Perl Documentation Devel::Cover(3)
2
3
4
6 Devel::Cover - Code coverage metrics for Perl
7
9 To get coverage for an uninstalled module:
10
11 cover -test
12
13 or
14
15 cover -delete
16 HARNESS_PERL_SWITCHES=-MDevel::Cover make test
17 cover
18
19 To get coverage for an uninstalled module which uses Module::Build
20 (0.26 or later):
21
22 ./Build testcover
23
24 If the module does not use the t/*.t framework:
25
26 PERL5OPT=-MDevel::Cover make test
27
28 If you want to get coverage for a program:
29
30 perl -MDevel::Cover yourprog args
31 cover
32
33 perl -MDevel::Cover=-db,cover_db,-coverage,statement,time yourprog args
34
36 This module provides code coverage metrics for Perl. Code coverage
37 metrics describe how thoroughly tests exercise code. By using
38 Devel::Cover you can discover areas of code not exercised by your tests
39 and determine which tests to create to increase coverage. Code coverage
40 can be considered as an indirect measure of quality.
41
42 I consider this software to have an alpha status. By that I mean that
43 I reserve the right to alter the interface in a backwards incompatible
44 manner without incrementing the major version number. I specifically
45 do not mean that this software is full of bugs or missing key features.
46 Although I'm making no guarantees on that front either. In short, if
47 you are looking for code coverage software for Perl, you have probably
48 come to the end of your search. For more of my opinions on this
49 subject, see http://pjcj.sytes.net/notes/2007/03/14#alpha
50
51 Code coverage data are collected using a pluggable runops function
52 which counts how many times each op is executed. These data are then
53 mapped back to reality using the B compiler modules. There is also a
54 statement profiling facility which needs a better backend to be really
55 useful. This release also includes an experimental mode which replaces
56 ops instead of using a pluggable runops function. This provides a nice
57 speed increase, but needs better testing before it becomes the default.
58 You probably don't care about any of this.
59
60 The cover program can be used to generate coverage reports.
61
62 Statement, branch, condition, subroutine, pod and time coverage
63 information is reported. Statement coverage data should be reasonable,
64 although there may be some statements which are not reported. Branch
65 and condition coverage data should be mostly accurate too, although not
66 always what one might initially expect. Subroutine coverage should be
67 as accurate as statement coverage. Pod coverage comes from
68 Pod::Coverage. If Pod::Coverage::CountParents is available it will be
69 used instead. Coverage data for path coverage are not yet collected.
70
71 The gcov2perl program can be used to convert gcov files to
72 "Devel::Cover" databases.
73
74 You may find that the results don't match your expectations. I would
75 imagine that at least one of them is wrong.
76
77 The most appropriate mailing list on which to discuss this module would
78 be perl-qa. Discussion has migrated there from perl-qa-metrics which
79 is now defunct. See http://lists.perl.org/showlist.cgi?name=perl-qa
80 <http://lists.perl.org/showlist.cgi?name=perl-qa>.
81
83 · Perl 5.6.1 or greater. Perl 5.8.2 or greater is recommended.
84
85 Perl 5.7.0 is unsupported. Perl 5.8.2 or greater is recommended.
86 Whilst Perl 5.6 should mostly work you will probably miss out on
87 coverage information which would be available using a more modern
88 version and will likely run into bugs in perl. Perl 5.8.0 will
89 give slightly different results to more recent versions due to
90 changes in the op tree.
91
92 · The ability to compile XS extensions.
93
94 This means a working compiler and make program at least.
95
96 · Storable and Digest::MD5
97
98 Both are in the core in Perl 5.8.0 and above.
99
100 · Template and PPI::HTML or Perl::Tidy
101
102 if you want syntax highlighted HTML reports.
103
104 · Pod::Coverage
105
106 if you want Pod coverage.
107
108 · Test::Differences
109
110 if the tests fail and you would like nice output telling you why.
111
113 -blib - "use blib" and ignore files matching \bt/ (default true
114 iff blib directory exists).
115 -coverage criterion - Turn on coverage for the specified criterion. Criteria
116 include statement, branch, condition, path, subroutine,
117 pod, time, all and none (default all available).
118 -db cover_db - Store results in coverage db (default ./cover_db).
119 -dir path - Directory in which coverage will be collected (default
120 cwd).
121 -ignore RE - Set REs of files to ignore (default "/Devel/Cover\b").
122 +ignore RE - Append to REs of files to ignore.
123 -inc path - Set prefixes of files to ignore (default @INC).
124 +inc path - Append to prefixes of files to ignore.
125 -merge val - Merge databases, for multiple test benches (default on).
126 -select RE - Set REs of files to select (default none).
127 +select RE - Append to REs of files to select.
128 -silent val - Don't print informational messages (default off).
129 -subs_only val - Only cover code in subroutine bodies (default off).
130 -replace_ops val - Use op replacing rather than runops (default on).
131 -summary val - Print summary information iff val is true (default on).
132
133 More on Coverage Options
134 You can specify options to some coverage criteria. At the moment only
135 pod coverage takes any options. These are the parameters which are
136 passed into the Pod::Coverage constructor. The extra options are
137 separated by dashes, and you may specify as many as you wish. For
138 example, to specify that all subroutines containing xx are private,
139 call Devel::Cover with the option -coverage,pod-also_private-xx.
140
142 You may select which files you want covered using the select, ignore
143 and inc options. The system works as follows:
144
145 Any file matching a RE given as a select option is selected.
146
147 Otherwise, any file matching a RE given as an ignore option is ignored.
148
149 Otherwise, any file in one of the inc directories is ignored.
150
151 Otherwise the file is selected.
152
153 You may add to the REs to select by using +select, or you may reset the
154 selections using -select. The same principle applies to the REs to
155 ignore.
156
157 The inc directories are initially populated with the contents of the
158 @INC array at the time Devel::Cover was built. You may reset these
159 directories using -inc, or add to them using +inc.
160
161 Although these options take regular expressions, you should not enclose
162 the RE within // or any other quoting characters.
163
165 The -silent option is turned on when Devel::Cover is invoked via
166 $HARNESS_PERL_SWITCHES or $PERL5OPT. Devel::Cover tries to do the
167 right thing when $MOD_PERL is set. $DEVEL_COVER_OPTIONS is appended to
168 any options passed into Devel::Cover.
169
170 When running Devel::Cover's own test suite, $DEVEL_COVER_DEBUG turns on
171 debugging information, $DEVEL_COVER_GOLDEN_VERSION overrides
172 Devel::Cover's own idea of which golden results it should test against,
173 and $DEVEL_COVER_NO_COVERAGE runs the tests without collecting
174 coverage.
175
177 Some code and ideas cribbed from:
178
179 Devel::OpProf
180 B::Concise
181 B::Deparse
182
184 Devel::Cover::Tutorial
185 B
186 Pod::Coverage
187
189 There are things that Devel::Cover can't cover.
190
191 Absence of shared dependencies
192 Perl keeps track of which modules have been loaded (to avoid reloading
193 them). Because of this, it isn't possible to get coverage for a path
194 where a runtime import fails if the module being imported is one that
195 Devel::Cover uses internally. For example, suppose your program has
196 this function:
197
198 sub foo {
199 eval { require Storable };
200 if ($@) {
201 carp "Can't find Storable";
202 return;
203 }
204 # ...
205 }
206
207 You might write a test for the failure mode as
208
209 BEGIN { @INC = () }
210 foo();
211 # check for error message
212
213 Because Devel::Cover uses Storable internally, the import will succeed
214 (and the test will fail) under a coverage run.
215
216 Modules used by Devel::Cover while gathering coverage:
217
218 · B
219
220 · B::Debug
221
222 · B::Deparse
223
224 · Carp
225
226 · Cwd
227
228 · Digest::MD5
229
230 · File::Path
231
232 · File::Spec
233
234 · Storable
235
236 mod_perl
237 By adding "use Devel::Cover;" to your mod_perl startup script, you
238 should be able to collect coverage information when running under
239 mod_perl. You can also add any options you need at this point. I
240 would suggest adding this as early as possible in your startup script
241 in order to collect as much coverage information as possible.
242
243 Redefined subroutines
244 If you redefine a subroutine you may find that the original subroutine
245 is not reported on. This is because I haven't yet found a way to
246 locate the original CV. Hints, tips or patches to resolve this will be
247 gladly accepted.
248
250 Almost certainly.
251
252 See the BUGS file. And the TODO file.
253
255 Version 0.66 - 12th April 2010
256
258 Copyright 2001-2010, Paul Johnson (pjcj@cpan.org)
259
260 This software is free. It is licensed under the same terms as Perl
261 itself.
262
263 The latest version of this software should be available from my
264 homepage: http://www.pjcj.net
265
266
267
268perl v5.12.3 2010-04-12 Devel::Cover(3)