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

.NET 7 Method Group branch coverage issue #1447

Closed
g0dm0d3 opened this issue Feb 10, 2023 · 4 comments · Fixed by #1564
Closed

.NET 7 Method Group branch coverage issue #1447

g0dm0d3 opened this issue Feb 10, 2023 · 4 comments · Fixed by #1564
Assignees
Labels
bug Something isn't working with repro Issue with repro

Comments

@g0dm0d3
Copy link

g0dm0d3 commented Feb 10, 2023

Hi guys!
After updating to .NET 7 new coverage issue was found.
It can be reproduced easily, you just need to reuse the same method group delegate.

Code:

namespace ClassLibrary1;

public class Class1
{
    public int[] Query1()
    {
        return new[] { 1, 2, 3 }.Select(Map).ToArray();
    }

    public int[] Query2()
    {
        return new[] { 1, 2, 3 }.Select(Map).ToArray();
    }

    private static int Map(int row) => row + 1;
}

Test:

using ClassLibrary1;
using NUnit.Framework;

namespace TestProject1;

public class Tests
{
    [Test]
    public void Test1()
    {
        new Class1().Query1();
        Assert.Pass();
    }

    [Test]
    public void Test2()
    {
        new Class1().Query2();
        Assert.Pass();
    }
}

Expected:
Full branch coverage (no branches at all)

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

Output:
image

Report:

<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="1" branch-rate="0.75" version="1.9" timestamp="1676057701" lines-covered="7" lines-valid="7" branches-covered="3" branches-valid="4">
  <sources>
    <source>F:\</source>
  </sources>
  <packages>
    <package name="ClassLibrary1" line-rate="1" branch-rate="0.75" complexity="5">
      <classes>
        <class name="ClassLibrary1.Class1" filename="ClassLibrary1\Class1.cs" line-rate="1" branch-rate="0.75" complexity="5">
          <methods>
            <method name="Query1" signature="()" line-rate="1" branch-rate="1" complexity="2">
              <lines>
                <line number="6" hits="1" branch="False" />
                <line number="7" hits="1" branch="True" condition-coverage="100% (2/2)">
                  <conditions>
                    <condition number="24" type="jump" coverage="100%" />
                  </conditions>
                </line>
                <line number="8" hits="1" branch="False" />
              </lines>
            </method>
            <method name="Query2" signature="()" line-rate="1" branch-rate="0.5" complexity="2">
              <lines>
                <line number="11" hits="1" branch="False" />
                <line number="12" hits="1" branch="True" condition-coverage="50% (1/2)">
                  <conditions>
                    <condition number="24" type="jump" coverage="50%" />
                  </conditions>
                </line>
                <line number="13" hits="1" branch="False" />
              </lines>
            </method>
            <method name="Map" signature="(System.Int32)" line-rate="1" branch-rate="1" complexity="1">
              <lines>
                <line number="15" hits="6" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="6" hits="1" branch="False" />
            <line number="7" hits="1" branch="True" condition-coverage="100% (2/2)">
              <conditions>
                <condition number="24" type="jump" coverage="100%" />
              </conditions>
            </line>
            <line number="8" hits="1" branch="False" />
            <line number="11" hits="1" branch="False" />
            <line number="12" hits="1" branch="True" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="24" type="jump" coverage="50%" />
              </conditions>
            </line>
            <line number="13" hits="1" branch="False" />
            <line number="15" hits="6" branch="False" />
          </lines>
        </class>
      </classes>
    </package>
  </packages>
</coverage>

Reproduced in .NET 7, Coverlet 3.2.0

@daveMueller
Copy link
Collaborator

Thanks for reporting this and providing a repro 🙏.

@daveMueller daveMueller added untriaged To be investigated with repro Issue with repro labels Feb 10, 2023
@github-actions
Copy link

github-actions bot commented Sep 3, 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 3, 2023
@daveMueller daveMueller added bug Something isn't working and removed untriaged To be investigated stale labels Nov 9, 2023
@daveMueller
Copy link
Collaborator

I can reproduce this and will start working on it.

@g0dm0d3
Copy link
Author

g0dm0d3 commented Jan 10, 2024

Thanks for fixing this @daveMueller !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working with repro Issue with repro
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants