You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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].
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:
Create a class with an asynchronous method that calls the helper method:
Write a unit test that invokes the asynchronous method:
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
The text was updated successfully, but these errors were encountered: