Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect branch coverage with await using in generic methods #1490

Closed
arseni-mourzenko opened this issue Jun 7, 2023 · 2 comments · Fixed by #1647
Closed

Incorrect branch coverage with await using in generic methods #1490

arseni-mourzenko opened this issue Jun 7, 2023 · 2 comments · Fixed by #1647
Labels
duplicate This issue or pull request already exists stale

Comments

@arseni-mourzenko
Copy link

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.

@petli
Copy link
Collaborator

petli commented Jun 7, 2023

Looks like it can be the same issue as #1333, and maybe related to #1284 and #1448.

@Bertk Bertk added the duplicate This issue or pull request already exists label Aug 28, 2023
Copy link

github-actions bot commented Dec 3, 2023

This issue is stale because it has been open for 3 months with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants