Some of my projects have many, many tests. While we keep the entire suite runtime under 30 seconds (hopefully under 10 seconds for a parallel run), Devel::Cover imposes a measurable performance penalty. I appreciate using Dist::Zilla to manage our distributions, and the additional command to make dzil cover work is very handy, but running the entire test suite through D::C more than once seems a little silly.

If I'm improving the test coverage of a piece of code, I usually care only about that piece of code and nothing else. Thus I wrote a tiny little bash function to encapsulate the appropriate invocation to measure the code coverage of only the code I care about:

function cover_test { rm -rf cover_db/; PERL5OPT=-MDevel::Cover env perl -Ilib $* 2> /dev/null; cover }

Run it and provide one or more test files. D::C will produce a coverage report in your console and as an HTML file. (One nice feature of removing the cover_db/ directory is that the report will always be available in cover_db/coverage.html, so you can refresh your browser window.)

I added the standard error redirection to avoid the error messages the current version of D::C (0.79) emits when analyzing Moose code. That's likely to go away with a new release.

This shell function only saves me thirty seconds for each invocation, but that allows me to run coverage every five minutes—or more frequently—to verify my progress. It's improved the way I work.