[Pdx-pm] Devel::Cover, a lighting email
Randall Hansen
randall at sonofhans.net
Mon Jan 24 20:33:03 PST 2005
Devel::Cover, or, "why I can give up crack."
i ran across Devel::Cover[1] today, and wanted to share. this would
have been a lightning talk if i'd found it a couple weeks ago.
like some of you, i suppose, i've often wondered if i'm *really*
testing all my code. i try hard for best practice: always write
failing tests first; test every condition; make each line of code
justify its existence with a test.
Devel::Cover takes a lot of the guesswork out of this. i installed it
this evening from CPAN and ran it on one of my projects, a smallish
one; 12 modules, ~2k LOC including POD, ~2k tests.
Devel::Cover creates a database directory of test results which it then
parses into nicely readable output. you get plain text but also an
HTML tree, with pages for each file and a line-by-line breakdown. i'm
so tickled that i've posted the whole suite of results; take a look[2].
i started off at 98.1%, and a couple tweaks got me to 98.5%. one of
the tweaks was something non-obvious (to me) that i'd missed. i wrote
a new test and it passed, and i've made a mental note to watch out for
similar situations. another tweak allowed me to delete a couple old
lines of code that were never used or tested.
running it is simple. my dev directory is pretty standard: ./lib for
code and ./t for tests: just what ExtUtils::ModuleMaker would give
you. i ran this:
cover -delete
HARNESS_PERL_SWITCHES=-MDevel::Cover make test
cover
as i said, it's addicting. "i'll eat dinner as soon as i get to 99%,"
i've been thinking.
it has limitations. it says it likes some versions of perl better than
others; it's pretty slow; it declares itself "alpha." for all that,
it's really useful. highly recommended.
r
----
1. http://search.cpan.org/dist/Devel-Cover/lib/Devel/Cover.pm
2. http://sonofhans.net/validop/cover_db/coverage.html
More information about the Pdx-pm-list
mailing list