views:

38

answers:

2

I have a project setup like this:

bin/fizzbuzz-game.pl
lib/FizzBuzz.pm
test/TestFizzBuzz.pm
test/TestFizzBuzz.t

When I run coverage on this, using

perl -MDevel::Cover=-db,/tmp/cover_db test/*.t

... I get the following output:

----------------------------------- ------ ------ ------ ------ ------ ------
File                                  stmt   bran   cond    sub   time  total
----------------------------------- ------ ------ ------ ------ ------ ------
lib/FizzBuzz.pm                      100.0  100.0    n/a  100.0    1.4  100.0
test/TestFizzBuzz.pm                 100.0    n/a    n/a  100.0   97.9  100.0
test/TestFizzBuzz.t                  100.0    n/a    n/a  100.0    0.7  100.0
Total                                100.0  100.0    n/a  100.0  100.0  100.0
----------------------------------- ------ ------ ------ ------ ------ ------

That is: the totally-uncovered file bin/fizzbuzz-game.pl is not included in the results.

How do I fix this?

+2  A: 

Have you checked the documentation? The section on Selecting which files to cover seems most helpful. :) It looks like the +select option is the one you are looking for.

Robert P
I think that this option comes to play too late, eg. the system has a list of all files that were touched during the execution and then selects/ignores from that list. The problem is that untouched files are absent.
Markus
A: 

I figured out a work-around for this.

The core of this problem is that the uncovered code in the main file (fizzbuzz-game.pl) is not included in the coverage report, hence the overall percentage is wrong. The underlying problem is that substantial logic resides in the main file instead of testable modules. This is a smell (don't know which, but I'm pretty sure there is a name for "lots of logic in main()").

By getting rid of this smell, eg. moving all substatial code from bin/fizzbuzz-game.pl to lib/FizzBuzzGame.pm, the code can theoretically be tested, and can definitively be included in the test run.

The coverage report after this becomes:

----------------------------------- ------ ------ ------ ------ ------ ------
File                                  stmt   bran   cond    sub   time  total
----------------------------------- ------ ------ ------ ------ ------ ------
lib/FizzBuzz.pm                      100.0  100.0    n/a  100.0    0.0  100.0
lib/FizzBuzzGame.pm                   75.0    n/a    n/a   75.0  100.0   75.0
Total                                 87.5  100.0    n/a   83.3  100.0   88.9
----------------------------------- ------ ------ ------ ------ ------ ------
Markus