Skip to content

Partially covered throw statement (async handler) #1103

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

Closed
mjeanrichard opened this issue Mar 2, 2021 · 2 comments · Fixed by #1144
Closed

Partially covered throw statement (async handler) #1103

mjeanrichard opened this issue Mar 2, 2021 · 2 comments · Fixed by #1144
Assignees
Labels
bug Something isn't working tenet-coverage Issue related to possible incorrect coverage with repro Issue with repro

Comments

@mjeanrichard
Copy link

mjeanrichard commented Mar 2, 2021

Hi,

In the following code the throw statement is marked as partially covered (because of the async statemachine), even though I see no way to cover that hidden branch. Could this be detected and marked as covered by coverlet?

public class AsyncThrowReproduction
{
	public async Task Execute(bool throwException)
	{
		try
		{
			if (throwException)
			{
				throw new InvalidOperationException();
			}
		}
		catch (InvalidOperationException)
		{
			await Task.Delay(1);
			throw;
		}
	}
}

Unit Tests:

public class AsyncThrowReproductionFixture
    {
        [Fact]
        public async Task Execute_ShouldWork_Exception()
        {
            // Arrange
            var sut = new AsyncThrowReproduction();

            // Act
            async Task TestFunc() => await sut.Execute(true);

            // Assert
            await Assert.ThrowsAsync<InvalidOperationException>(TestFunc);
        }

        [Fact]
        public async Task Execute_ShouldWork_NoException()
        {
            // Arrange
            var sut = new AsyncThrowReproduction();

            // Act
            await sut.Execute(false);
        }
    }

Reported Coverage:
image

Coverlet Version: 3.0.3

@msallin
Copy link

msallin commented Mar 2, 2021

@daveMueller daveMueller added the untriaged To be investigated label Mar 3, 2021
@daveMueller
Copy link
Collaborator

daveMueller commented Mar 31, 2021

Thanks for reporting and providing a repro. I had a quick peek on this. It seems this issue is related to IL compiled with release configuration. At a first view when compiling with debug configuration the coverage looks as expected.

image

Really suspicious are the additional branches in the coverage result that are totally misplaced.

image

I'll take a look and do the deep dive. 😉

@daveMueller daveMueller self-assigned this Mar 31, 2021
@daveMueller daveMueller added bug Something isn't working tenet-coverage Issue related to possible incorrect coverage with repro Issue with repro and removed untriaged To be investigated labels Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tenet-coverage Issue related to possible incorrect coverage with repro Issue with repro
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants