Subject: | condition coverage gets messed up by de Morgan rule |
The perl parser apparently simplifies some conditions using de Morgan's rule.
In such cases, Devel::Cover fails to count all combinations of subconditions
correctly.
In my example, there is a statement:
return 1 if !$a and !$b;
The condition here is shown in condition coverage reports as ``$a or $b'', which
suggests that de Morgan's rule has been applied.
The case $a false and $b true, however, will wrongly be counted as $a false and $b
false in this context, leading to wrong accusations of insufficient coverage.
The problem goes away when the statement is written as:
return 1 unless $a or $b;
I checked this with Devel-Cover-0.92 and 0.93.
-Martin
Subject: | Foo.pm |
package Foo;
sub Foobar {
my ($a, $b) = @_;
return 1 if !$a && !$b;
return 2;
}
1;
Subject: | Foo.t |
use strict;
use warnings;
use Foo;
use Test::More tests => 4;
is(Foo::Foobar(1, 1), 2);
is(Foo::Foobar(1, 0), 2);
is(Foo::Foobar(0, 1), 2);
is(Foo::Foobar(0, 0), 1);