开发者

Including uncovered files in Devel::Cover reports

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 开发者_StackOverflow 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?


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.


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
----------------------------------- ------ ------ ------ ------ ------ ------
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜