and running with#!perl use 5.012; # strict, // use warnings; { my $i = 1; my $j = 2; sub get { $i + $j; } } get();
perl -MDevel::Cover x.pl cover
why does it say only 90.9% coverage?
----- ------ ------ ------ ------ ------ ------ ------ File stmt bran cond sub pod time total ----- ------ ------ ------ ------ ------ ------ ------ x.pl 90.9 n/a n/a 100.0 n/a 100.0 92.8 Total 90.9 n/a n/a 100.0 n/a 100.0 92.8 ----- ------ ------ ------ ------ ------ ------ ------
The coverage report shows the following table:
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | #!perl | ||||||
2 | 1 1 | 0 0 | use 5.012; # strict, // | ||||
3 | 1 1 1 | 0 0 0 | use warnings; | ||||
4 | |||||||
5 | { | ||||||
6 | 1 0 | 0 0 | my $i = 1; | ||||
7 | 1 | 0 | my $j = 2; | ||||
8 | sub get { | ||||||
9 | 1 | $i + $j; | |||||
10 | } | ||||||
11 | } | ||||||
12 | 1 1 | 74157 0 | get(); |
... but I cannot see why line 6 has two rows in the table, or why it says that the second row for that line was never run; there's only one statement, as far as I can tell. Removing the = 1 or changing the order of the declarations doesn't change the fact that the first row in that block claims to never run.
If I change to do { ... }; instead of just a block, then line 6 cleans up and only shows one row in the table, but now the line 4 do { shows it was run 0 times:
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | #!perl | ||||||
2 | 1 1 | 5875 0 | use 5.012; # strict, // | ||||
3 | 1 1 1 | 0 0 0 | use warnings; | ||||
4 | |||||||
5 | 0 | 0 | do { | ||||
6 | 1 | 0 | my $i = 1; | ||||
7 | 1 | 0 | my $j = 2; | ||||
8 | sub get { | ||||||
9 | 1 | $i + $j; | |||||
10 | } | ||||||
11 | 1 | 58427 | }; | ||||
12 | 1 | 0 | get(); |
If I convert the block to a sub init { ... } and then call it with init(), then the sub init { line shows as uncovered statement, just like the do { version.
I can work around it by getting rid of the block, so eliminating the coverage-flag isn't a problem (but I want the block in my real code to encapsulate the my variables to be private just for my get function, so I'm not going to do that). Or I can cheat with # uncoverable statement count:2. But my curiosity has been piqued as to why I should need a workaround at all.
In reply to mystery: Devel::Cover showing missing statement coverage on a line that is being run by pryrt
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |