- Notifications
You must be signed in to change notification settings - Fork 392
Closed
Labels
Description
Hi.
Using coverlet.msbuild.6.0.0, I noticed an issue with code coverage in generic methods that contain await using
.
Here's a short example which reproduces the issue:
public static class A { public static async Task<int> Demo() { await using var example = new DisposableExample<int>(); var result = await Task.FromResult(42); return result; } public static async Task<T> Demo<T>() { await using var example = new DisposableExample<T>(); var result = await Task.FromResult(default(T)); return result; } } public class DisposableExample<T> : IAsyncDisposable { public ValueTask DisposeAsync() { GC.SuppressFinalize(this); return ValueTask.CompletedTask; } }
Given the following tests:
[Fact] public async Task One() => Assert.Equal(42, await A.Demo()); [Fact] public async Task Two() => Assert.Null(await A.Demo<string>());
the first, non-generic method Demo()
will have a 100% branch coverage. The branch coverage of generic method, Demo<T>()
, will show a missing branch on line return result;
(1 visits, 3 of 4 branches are covered).
Unless I missed something, I would expect the branch coverage to be 100% in both cases.