1Devel::Cover(3)       User Contributed Perl Documentation      Devel::Cover(3)
2
3
4

NAME

6       Devel::Cover - Code coverage metrics for Perl
7

SYNOPSIS

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

DESCRIPTION

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

REQUIREMENTS

82       ·   Perl 5.6.1 or greater.  Perl 5.8.2 or greater is recommended.
83
84           Perl 5.7.0 is unsupported.  Perl 5.8.2 or greater is recommended.
85           Whilst Perl 5.6 should mostly work you will probably miss out on
86           coverage information which would be available using a more modern
87           version and will likely run into bugs in perl.  Perl 5.8.0 will
88           give slightly different results to more recent versions due to
89           changes in the op tree.
90
91       ·   The ability to compile XS extensions.
92
93           This means a working compiler and make program at least.
94
95       ·   Storable and Digest::MD5
96
97           Both are in the core in Perl 5.8.0 and above.
98
99       ·   Template and PPI::HTML or Perl::Tidy
100
101           if you want syntax highlighted HTML reports.
102
103       ·   Pod::Coverage
104
105           if you want Pod coverage.
106
107       ·   Test::Differences
108
109           if the tests fail and you would like nice output telling you why.
110

OPTIONS

112        -blib               - "use blib" and ignore files matching \bt/ (default true
113                              iff blib directory exists).
114        -coverage criterion - Turn on coverage for the specified criterion.  Criteria
115                              include statement, branch, condition, path, subroutine,
116                              pod, time, all and none (default all available).
117        -db cover_db        - Store results in coverage db (default ./cover_db).
118        -dir path           - Directory in which coverage will be collected (default
119                              cwd).
120        -ignore RE          - Set REs of files to ignore (default "/Devel/Cover\b").
121        +ignore RE          - Append to REs of files to ignore.
122        -inc path           - Set prefixes of files to ignore (default @INC).
123        +inc path           - Append to prefixes of files to ignore.
124        -merge val          - Merge databases, for multiple test benches (default on).
125        -select RE          - Set REs of files to select (default none).
126        +select RE          - Append to REs of files to select.
127        -silent val         - Don't print informational messages (default off)
128        -subs_only val      - Only cover code in subroutine bodies (default off)
129        -summary val        - Print summary information iff val is true (default on).
130
131   More on Coverage Options
132       You can specify options to some coverage criteria.  At the moment only
133       pod coverage takes any options.  These are the parameters which are
134       passed into the Pod::Coverage constructor.  The extra options are
135       separated by dashes, and you may specify as many as you wish.  For
136       example, to specify that all subroutines containing xx are private,
137       call Devel::Cover with the option -coverage,pod-also_private-xx.
138

SELECTING FILES TO COVER

140       You may select which files you want covered using the select, ignore
141       and inc options.  The system works as follows:
142
143       Any file matching a RE given as a select option is selected.
144
145       Otherwise, any file matching a RE given as an ignore option is ignored.
146
147       Otherwise, any file in one of the inc directories is ignored.
148
149       Otherwise the file is selected.
150
151       You may add to the REs to select by using +select, or you may reset the
152       selections using -select.  The same principle applies to the REs to
153       ignore.
154
155       The inc directories are initially populated with the contents of the
156       @INC array at the time Devel::Cover was built.  You may reset these
157       directories using -inc, or add to them using +inc.
158
159       Although these options take regular expressions, you should not enclose
160       the RE within // or any other quoting characters.
161

ENVIRONMENT

163       The -silent option is turned on when Devel::Cover is invoked via
164       $HARNESS_PERL_SWITCHES or $PERL5OPT.  Devel::Cover tries to do the
165       right thing when $MOD_PERL is set.  $DEVEL_COVER_OPTIONS is appended to
166       any options passed into Devel::Cover.
167
168       When running Devel::Cover's own test suite, $DEVEL_COVER_DEBUG turns on
169       debugging information, $DEVEL_COVER_GOLDEN_VERSION overrides
170       Devel::Cover's own idea of which golden results it should test against,
171       and $DEVEL_COVER_NO_COVERAGE runs the tests without collecting
172       coverage.
173

ACKNOWLEDGEMENTS

175       Some code and ideas cribbed from:
176
177        Devel::OpProf
178        B::Concise
179        B::Deparse
180

SEE ALSO

182        Devel::Cover::Tutorial
183        B
184        Pod::Coverage
185

LIMITATIONS

187       There are things that Devel::Cover can't cover.
188
189   Absence of shared dependencies
190       Perl keeps track of which modules have been loaded (to avoid reloading
191       them).  Because of this, it isn't possible to get coverage for a path
192       where a runtime import fails if the module being imported is one that
193       Devel::Cover uses internally.  For example, suppose your program has
194       this function:
195
196        sub foo {
197            eval { require Storable };
198            if ($@) {
199                carp "Can't find Storable";
200                return;
201            }
202            # ...
203        }
204
205       You might write a test for the failure mode as
206
207        BEGIN { @INC = () }
208        foo();
209        # check for error message
210
211       Because Devel::Cover uses Storable internally, the import will succeed
212       (and the test will fail) under a coverage run.
213
214       Modules used by Devel::Cover while gathering coverage:
215
216       ·   B
217
218       ·   B::Debug
219
220       ·   B::Deparse
221
222       ·   Carp
223
224       ·   Cwd
225
226       ·   Digest::MD5
227
228       ·   File::Path
229
230       ·   File::Spec
231
232       ·   Storable
233
234   mod_perl
235       By adding "use Devel::Cover;" to your mod_perl startup script, you
236       should be able to collect coverage information when running under
237       mod_perl.  You can also add any options you need at this point.  I
238       would suggest adding this as early as possible in your startup script
239       in order to collect as much coverage information as possible.
240
241   Redefined subroutines
242       If you redefine a subroutine you may find that the original subroutine
243       is not reported on.  This is because I haven't yet found a way to
244       locate the original CV.  Hints, tips or patches to resolve this will be
245       gladly accepted.
246

BUGS

248       Almost certainly.
249
250       See the BUGS file.  And the TODO file.
251

VERSION

253       Version 0.65 - 8th August 2009
254

LICENCE

256       Copyright 2001-2009, Paul Johnson (pjcj@cpan.org)
257
258       This software is free.  It is licensed under the same terms as Perl
259       itself.
260
261       The latest version of this software should be available from my
262       homepage: http://www.pjcj.net
263
264
265
266perl v5.10.1                      2009-08-08                   Devel::Cover(3)
Impressum