Skip to content

False Positive in Branch Coverage Due to Short-Circuiting Logical Operators #1751

Open
@rayventoso7079125

Description

@rayventoso7079125

I'm encountering a branch coverage false positive when using short-circuiting logical operators (|| or &&).

Example
selectedCustomer.IsNewCustomer = myDate == null || myDate > DateTime.UtcNow;

In this expression, if myDate == null evaluates to true, the second condition myDate > DateTime.UtcNow is not evaluated due to short-circuiting behavior in C#.​

However, Coverlet reports this line as having 75% branch coverage (3 out of 4 branches), indicating that one branch is not covered. This seems to be a false positive since the short-circuiting nature of the logical operator prevents the second condition from being evaluated when the first is true.​

Expected Behavior:

Coverlet should recognize the short-circuiting behavior of logical operators and not count branches that are not evaluated due to this behavior as uncovered.​

Actual Behavior:

Coverlet reports partial branch coverage for expressions with short-circuiting logical operators, even when all logically possible paths are covered in tests.

Request:

Is there a way to configure Coverlet to account for short-circuiting behavior in logical operators to avoid these false positives? If not, could this feature be considered for a future release?

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedTo be investigated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions