coverlet
coverlet copied to clipboard
Incorrect coverage for methods returning `IAsyncEnumerable` in generic classes
Hi.
Using coverlet.msbuild.3.1.2, I noticed an issue with code coverage for a method which returns IAsyncEnumerable, as soon as the method is inside a generic class.
Here's a short example which reproduces the issue:
public class A
{
public static async IAsyncEnumerable<int> Demo()
{
yield return 5;
yield return 2;
}
}
public class A<T>
{
public static async IAsyncEnumerable<int> Demo()
{
yield return 5;
yield return 2;
}
}
Given the following tests:
[Fact] public async Task Test1() => Assert.Equal(new [] { 5, 2 }, await A.Demo().ToListAsync());
[Fact] public async Task Test2() => Assert.Equal(new [] { 5, 2 }, await A<string>.Demo().ToListAsync());
the coverage report will show that the Demo method inside the class A has 100% branch coverage, whereas the method Demo inside A<T> has only partial coverage (one branch out of two) on the line {, as well as on the following two yield return lines.
The code of the two methods and the corresponding tests being identical, the coverage should instead be identical, that is, 100% in both cases.
Thanks for reporting this.
Seeing similar behavior where a Generic Class has a method that returns an IAsyncEnumerable, the method is marked with ExcludeFromCodeCoverage however coverage is reported as zero instead of being ignored.
@RobARichardson I created another issue for that (#1431). I think it is another bug and my PR will not fix this.
@MarcoRossignoli, do you know when the new version of Coverlet would be available through NuGet?