Devel::Cover - Impossible to mark branch as uncoverable

139 Views Asked by At

I'm honestly not sure if this is a bug or me missing something.

Devel::Cover ignores my # uncoverable branch true based on a previous condition somehow.

I have 2 files - Test and Test2 - the uncoverable is in Test.

Now when the trigger condition (see below) is not commented out I get 50% branch coverage that looks like this:

messed up coverage

Now comment out the trigger condition and run everything again and I get:

expected coverage

The branch is now properly ignored as uncoverable. The only thing that was changed was commenting out the trigger condition.

I really don't understand this behavior - if anybody would be willing to try this out to see if this is me not understanding something or a bug.

Disclaimer: I'm no perl guru :) I tried to simplify this more but I could not reproduce it otherwise - even simplification of this is appreciated - maybe it will help trace to the root cause of it.

EDIT: I made this repo to make this easier to reproduce: https://github.com/lukaskuzmiak/Devel--Cover_coverage_issue_PoC

package My::Test;

use 5.026;
use strict;
use warnings;

use My::Test2;


sub test {

    my $test2 = My::Test2->new({});

    if ($test2 > 1) { say 'something'; } # let's call this "trigger condition"

    # uncoverable branch true
    $test2->asdf(
        {
            variable => 'asdf'
        }
    ) or say 'something else';

    return 1;
}

1;

And a second Test2

package My::Test2;

use 5.026;
use strict;
use warnings;

sub new {
    my ($class, $args) = @_;
    my $self = {};
    return bless $self, $class;
}

sub asdf {
    my ($class, $args) = @_;
    return 1;
}

1;
0

There are 0 best solutions below