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