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

[BUG] ExcludeFromCodeCoverage does not exclude F# task workflow inside of function #1547

Closed
JohnDoeKyrgyz opened this issue Nov 1, 2023 · 2 comments · Fixed by #1542
Closed
Labels
bug Something isn't working with repro Issue with repro

Comments

@JohnDoeKyrgyz
Copy link

JohnDoeKyrgyz commented Nov 1, 2023

Describe the bug
The ExcludeFromCodeCoverage attribute does not exclude code inside a task workflow in an F# function

To Reproduce
Project Code

namespace src

open System.Diagnostics.CodeAnalysis
open System.Threading.Tasks

module Say =
    
    [<ExcludeFromCodeCoverage>]
    let hello name =
        
        [|for i in 0 .. 10 do
             task {
                 printfn $"Task {i} Hello %s{name}"
             } :> Task|]
        |> Task.WaitAll
        
        printfn $"Hello %s{name}"

    let formatHello name =
        $"Hello %s{name}!"

Unit Test

module test

open NUnit.Framework

[<Test>]
let formatMessage () =
    let helloWorld = src.Say.formatHello "World"
    Assert.That(helloWorld, Is.EqualTo("Hello World!"))

Generate Code Coverage via command line

dotnet test --collect:"XPlat Code Coverage"

Expected behavior
Expect the coverage file to not include any code in the hello function.

Actual behavior
Coverage file picks up the body of the task in the hello function. It's listed as method MoveNext() line 13.

coverage.cobertura.xml

<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="0.3333" branch-rate="0" version="1.9" timestamp="1698873645" lines-covered="1" lines-valid="3" branches-covered="0" branches-valid="4">
  <sources>
    <source>/CodeCoverageTest/src/Library.fs/</source>
  </sources>
  <packages>
    <package name="Source" line-rate="0.5" branch-rate="0" complexity="5">
      <classes>
        <class name="src.Say" filename="/CodeCoverageTest/src/Library.fs" line-rate="1" branch-rate="1" complexity="1">
          <methods>
            <method name="formatHello" signature="(System.String)" line-rate="1" branch-rate="1" complexity="1">
              <lines>
                <line number="20" hits="1" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="20" hits="1" branch="False" />
          </lines>
        </class>
        <class name="src.Say/Pipe #1 input at line 11@12" filename="/CodeCoverageTest/src/Library.fs" line-rate="0" branch-rate="0" complexity="4">
          <methods>
            <method name="MoveNext" signature="()" line-rate="0" branch-rate="0" complexity="4">
              <lines>
                <line number="13" hits="0" branch="True" condition-coverage="0% (0/4)">
                  <conditions>
                    <condition number="71" type="jump" coverage="0%" />
                    <condition number="119" type="jump" coverage="0%" />
                  </conditions>
                </line>
              </lines>
            </method>
          </methods>
          <lines>
            <line number="13" hits="0" branch="True" condition-coverage="0% (0/4)">
              <conditions>
                <condition number="71" type="jump" coverage="0%" />
                <condition number="119" type="jump" coverage="0%" />
              </conditions>
            </line>
          </lines>
        </class>
      </classes>
    </package>
    <package name="src" line-rate="0" branch-rate="1" complexity="1">
      <classes>
        <class name="src.Say" filename="/CodeCoverageTest/src/Library.fs" line-rate="0" branch-rate="1" complexity="1">
          <methods>
            <method name="formatHello" signature="(System.String)" line-rate="0" branch-rate="1" complexity="1">
              <lines>
                <line number="12" hits="0" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="12" hits="0" branch="False" />
          </lines>
        </class>
      </classes>
    </package>
  </packages>
</coverage>

Configuration (please complete the following information):
Please provide more information on your .NET configuration:
* Which coverlet package and version was used? - 6.0.0
* Which version of .NET is the code running on? - 7.0.403
* What OS and version, and what distro if applicable? - macOS
* What is the architecture (x64, x86, ARM, ARM64)? - arm64
* Do you know whether it is specific to that configuration? - no

@github-actions github-actions bot added the untriaged To be investigated label Nov 1, 2023
@daveMueller
Copy link
Collaborator

Thanks for reporting 🙏 . I can reproduce it.

grafik

@daveMueller daveMueller added bug Something isn't working with repro Issue with repro and removed untriaged To be investigated labels Nov 4, 2023
@daveMueller
Copy link
Collaborator

I just checked it again. PR #1542 will close this issue.

grafik

<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="1" branch-rate="0" version="1.9" timestamp="1699169476" lines-covered="1" lines-valid="1" branches-covered="0" branches-valid="4">
  <sources>
    <source>D:\</source>
  </sources>
  <packages>
    <package name="Issue1547" line-rate="1" branch-rate="0" complexity="5">
      <classes>
        <class name="Issue1547.Say" filename="Repos\Repros\Issue1547\Issue1547\Library.fs" line-rate="1" branch-rate="1" complexity="1">
          <methods>
            <method name="formatHello" signature="(System.String)" line-rate="1" branch-rate="1" complexity="1">
              <lines>
                <line number="20" hits="1" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="20" hits="1" branch="False" />
          </lines>
        </class>
        <class name="Issue1547.Say/Pipe #1 input at line 11@12" filename="Repos\Repros\Issue1547\Issue1547\Library.fs" line-rate="1" branch-rate="0" complexity="4">
          <methods />
          <lines />
        </class>
      </classes>
    </package>
  </packages>
</coverage>

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