I have this module which has a Readonly
constant for a default value that is used if the caller does not specify a value.
package Mcve;
use strict;
use warnings;
use Readonly;
Readonly our $CONST => 123;
sub new {
my ($class, %args) = @_;
my $self = bless{}, $class;
# uncoverable condition right
# uncoverable condition false
# uncoverable branch false
$self->{'CONST'} = $args{'CONST'} || $CONST;
return $self;
}
And a test case:
use strict;
use warnings;
use base 'Test::Class';
use Test::More;
use Mcve;
__PACKAGE__->runtests() unless caller;
sub uses_default_arg: Test {
my $mcve = Mcve->new();
is($mcve->{'CONST'}, 123);
}
sub overrides_default_arg: Test {
my $mcve = Mcve->new('CONST' => 456);
is($mcve->{'CONST'}, 456);
}
When I collect test coverage with Devel::Cover
, it does not see that $COVER
is always defined, so the condition "both values are false" can never be covered. I tried to add the # uncoverable ...
comments as per the documentation (see above), but still the coverage report shows only 66% conditional coverage:
~$ HARNESS_PERL_SWITCHES=-MDevel::Cover prove -Ilib t/ && cover
...
----------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
----------- ------ ------ ------ ------ ------ ------ ------
lib/Mcve.pm 100.0 n/a 66.6 100.0 0.0 0.5 90.4
t/mcve.t 100.0 n/a n/a 100.0 n/a 99.4 100.0
Total 100.0 n/a 66.6 100.0 0.0 100.0 96.3
----------- ------ ------ ------ ------ ------ ------ ------
The html report shows that Devel::Cover
thinks that both values being false is not covered:
How do I tell Devel::Cover
that this condition is uncoverable?
(This is with Perl 5.34 and Devel::Cover version 1.36)