coverlet icon indicating copy to clipboard operation
coverlet copied to clipboard

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

Open rayventoso7079125 opened this issue 7 months ago • 0 comments

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?

rayventoso7079125 avatar Apr 20 '25 20:04 rayventoso7079125