-
Notifications
You must be signed in to change notification settings - Fork 392
Description
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].