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

Branch coverage Issue - async delegate + await using #1284

Closed
g0dm0d3 opened this issue Jan 31, 2022 · 3 comments
Closed

Branch coverage Issue - async delegate + await using #1284

g0dm0d3 opened this issue Jan 31, 2022 · 3 comments
Labels
stale tenet-coverage Issue related to possible incorrect coverage untriaged To be investigated

Comments

@g0dm0d3
Copy link

g0dm0d3 commented Jan 31, 2022

Hi guys!
Found one more interesting case.

Code:

namespace CoverletAsyncAwait;

public class SomeClass
{
    public async Task SomeMethod()
    {
        await SomeInternalMethod(async () =>
        {
            await using var stream = new MemoryStream();
            await Task.CompletedTask;
        });
    }

    private static async Task SomeInternalMethod(Func<Task> work)
    {
        await work();
    }
}

Test:

using System.Threading.Tasks;
using NUnit.Framework;

namespace CoverletAsyncAwait.Tests;

[TestFixture]
public class TestSomeClass
{
    [Test]
    public async Task SomeTest()
    {
        var someClass = new SomeClass();
        await someClass.SomeMethod();
    }
}

Expected:
Full branch coverage

Actual:
Partially covered (1 visits, 4 of 6 branches are covered)

Output:
image

Report:

<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="1" branch-rate="0.6666" version="1.9" timestamp="1643610246" lines-covered="10" lines-valid="10" branches-covered="4" branches-valid="6">
  <sources>
    <source>F:\</source>
  </sources>
  <packages>
    <package name="CoverletAsyncAwait" line-rate="1" branch-rate="0.6666" complexity="8">
      <classes>
        <class name="CoverletAsyncAwait.SomeClass/&lt;&gt;c/&lt;&lt;SomeMethod&gt;b__0_0&gt;d" filename="Work\experiments\CoverletAsyncAwait\CoverletAsyncAwait\SomeClass.cs" line-rate="1" branch-rate="0.6666" complexity="6">
          <methods>
            <method name="MoveNext" signature="()" line-rate="1" branch-rate="0.6666" complexity="6">
              <lines>
                <line number="8" hits="1" branch="False" />
                <line number="9" hits="1" branch="False" />
                <line number="10" hits="1" branch="True" condition-coverage="66.66% (4/6)">
                  <conditions>
                    <condition number="181" type="jump" coverage="100%" />
                    <condition number="299" type="jump" coverage="50%" />
                    <condition number="339" type="jump" coverage="50%" />
                  </conditions>
                </line>
                <line number="11" hits="2" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="8" hits="1" branch="False" />
            <line number="9" hits="1" branch="False" />
            <line number="10" hits="1" branch="True" condition-coverage="66.66% (4/6)">
              <conditions>
                <condition number="181" type="jump" coverage="100%" />
                <condition number="299" type="jump" coverage="50%" />
                <condition number="339" type="jump" coverage="50%" />
              </conditions>
            </line>
            <line number="11" hits="2" branch="False" />
          </lines>
        </class>
        <class name="CoverletAsyncAwait.SomeClass/&lt;SomeInternalMethod&gt;d__1" filename="Work\experiments\CoverletAsyncAwait\CoverletAsyncAwait\SomeClass.cs" line-rate="1" branch-rate="1" complexity="1">
          <methods>
            <method name="MoveNext" signature="()" line-rate="1" branch-rate="1" complexity="1">
              <lines>
                <line number="15" hits="1" branch="False" />
                <line number="16" hits="1" branch="False" />
                <line number="17" hits="1" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="15" hits="1" branch="False" />
            <line number="16" hits="1" branch="False" />
            <line number="17" hits="1" branch="False" />
          </lines>
        </class>
        <class name="CoverletAsyncAwait.SomeClass/&lt;SomeMethod&gt;d__0" filename="Work\experiments\CoverletAsyncAwait\CoverletAsyncAwait\SomeClass.cs" line-rate="1" branch-rate="1" complexity="1">
          <methods>
            <method name="MoveNext" signature="()" line-rate="1" branch-rate="1" complexity="1">
              <lines>
                <line number="6" hits="1" branch="False" />
                <line number="7" hits="1" branch="False" />
                <line number="12" hits="1" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="6" hits="1" branch="False" />
            <line number="7" hits="1" branch="False" />
            <line number="12" hits="1" branch="False" />
          </lines>
        </class>
      </classes>
    </package>
  </packages>
</coverage>

Reproduced in .NET 6, Coverlet 3.1.1

@MarcoRossignoli MarcoRossignoli added tenet-coverage Issue related to possible incorrect coverage untriaged To be investigated labels Jan 31, 2022
@MarcoRossignoli
Copy link
Collaborator

Thanks for reporting it.

@github-actions
Copy link

github-actions bot commented Sep 4, 2023

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

@github-actions github-actions bot added the stale label Sep 4, 2023
Copy link

This issue was closed because it has been inactive for 9 months since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale tenet-coverage Issue related to possible incorrect coverage untriaged To be investigated
Projects
None yet
Development

No branches or pull requests

2 participants