Mike Malony wrote:
I'm into testing, got some nice .t files, and prove tells me things I'd
rather not hear. So, my next step on the straight and narrow path of
testing, is to gauge my testing coverage.
IN the doc, the synopsis suggests
"perl -MDevel::Cover yourprog args
cover"
But what can you use in 'yourprog'?
.t and .pl files run, do the tests and have some extra messages implying
that cover was running, but there are no stats printed.
prove also runs my tests, and produces stats, but only for the installed
modules.
Here's another example of how to use 'prove' with Devel::Cover. I am
involved with testing and refactoring those build tools for the Parrot
project which are written in Perl 5. Since these scripts run during the
'make' process, doing coverage analysis with my tests requires using
'prove' rather than 'make test' (which would be premature).
Since there are a number of different scripts with which I'm working, I
want to put the coverage analysis for different modules in different
directories (rather than opting for Devel::Cover's default directory for
coverage analysis: cover_db/). So if I'm testing the modules which
refactor a program called 'ops2pm.pl', I call the directory in which
coverage results will be placed 'coverage/ops2pm/'.
And since I, like you, don't really need a lot of .html files reporting
on the coverage of Test::More, Autoloader and other Perl core modules, I
want to limit reporting to only those modules I'm in the process of
developing to hold ops2pm.pl's functionality. They are called
Parrot::Ops2pm::Utils and Parrot::Ops2pm::Auxiliary. I'll use one of
cover's options to limit .html coverage reporting to those two modules.
Putting all these requirements into code, I proceed as follows:
$> cover -delete coverage/ops2pm/
$> PERL5OPT=-MDevel::Cover=-db,coverage/ops2pm \
> prove t/tools/ops2pmutils/*.t "$@"
$> cover coverage/ops2pm/ -select_re 'Utils|Auxiliary'
I then look at: coverage/ops2pm/coverage.html and click on links to
view the other .html files for statement, branch, condition and
subroutine coverage. You can see this for yourself here:
http://thenceforward.net/parrot/coverage/ops2pm/coverage.html
See also this perlmonks thread, where merlyn and others showed me how to
do this: http://perlmonks.org/?node_id=573367
Jim Keenan