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

[BUG] DoesNotReturnAttribute is not respected by Coverlet when applied to methods marked with the async keyword #1717

Open
dvireich opened this issue Dec 12, 2024 · 0 comments
Labels
untriaged To be investigated

Comments

@dvireich
Copy link

dvireich commented Dec 12, 2024

The DoesNotReturnAttribute is not respected by Coverlet when applied to methods marked with the async keyword. This results in inaccurate code coverage reports, as lines following calls to such methods are incorrectly considered reachable and uncovered.

To Reproduce

Create a helper class with a method marked with [DoesNotReturn] that throws an exception:

public static class ThrowHelper
{
    [DoesNotReturn]
    public static void Throw(Exception e)
    {
        throw e;
    }
}

Create a class with an asynchronous method that calls the helper method:

public async Task ThrowMethodWithMessageAsync(string message)
    {
        Console.WriteLine(message);
        ThrowHelper.Throw(new Exception());
    }

Write a unit test that invokes the asynchronous method:

[TestMethod]
public void TestMethodAsync()
{
    Assert.ThrowsExceptionAsync<Exception>(async () => await ThrowMethodWithMessageAsync("Test Message"));
}

Run the unit test with Coverlet to generate a code coverage report.

Expected behavior Coverlet should recognize that the ThrowHelper.Throw method does not return and should exclude lines following its invocation from the coverage report, accurately reflecting that those lines are unreachable.

Actual behavior Coverlet does not recognize the DoesNotReturnAttribute on the ThrowHelper.Throw method when it's called from an async method. Consequently, lines following the call to ThrowHelper.Throw are incorrectly marked as uncovered in the coverage report.

Configuration

Coverlet Version: 6.0.2
.NET Version: .NET 6.0
Architecture: x64
Specificity: The issue specifically occurs with asynchronous methods (async) that call methods marked with [DoesNotReturn].

@kevin-montrose @MarcoRossignoli

@github-actions github-actions bot added the untriaged To be investigated label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged To be investigated
Projects
None yet
Development

No branches or pull requests

1 participant