[Melbourne-pm] [adelaide.pm] Creating a baseline for Devel::Cover

Toby Corkindale toby.corkindale at strategicdata.com.au
Wed Jun 30 21:30:43 PDT 2010

On 01/07/10 14:21, Mike Bruins wrote:
> Hi Mongers,
> I'm hoping for some pointers on a question relating to Devel::Cover -
> http://search.cpan.org/dist/Devel-Cover/lib/Devel/Cover.pm
> Say I am about to embark on adding/fixing unit tests, and I wish to
> accurately measure the improvement in code coverage.
> At the start I will need a baseline that shows the all the files (e.g.
> scripts and modules) and the amount of coverage in each case.
> The trick is to have the all perl files represented in the baseline, not
> just those exercised by the unit tests.
> Illustration:
> Say I have 100 files, but my unit tests use 10 of these files.  Say the
> coverage was reported at 50%.
> True coverage would be about 5%, not the 50% reported (*).
> My thoughts so far:
> On day one it is not practical to write unit tests for all the files,
> but it might be possible to write a perl script to pre-load the cover_db
> with knowledge that the files exist.
> The overall process may look like the following:
> 1) cover --delete --silent
> 2) something_to_set_cover_db_baseline.pl
> 3) make test  HARNESS_PERL_SWITCHES=-MDevel::Cover
> 4) cover
> Is there an easy way to tell Devel::Cover about a file ?
> Perhaps there is an easier way to achieve the whole process?

I solve this problem by having a test which simply finds every .pm file 
in the lib directory and attempts to load it with require_ok($filename);

More information about the Melbourne-pm mailing list