Skip to content

ExcludeFromCodeCoverage attribute is ignored on local function #1302

Closed
@meggima

Description

@meggima

Having the following code:

public class ExcludedLocalFunctionReproduction
{
    public void SomethingThatIsUsingALocalFunction()
    {
        MethodThatTakesALambda(NewMethod());

        [ExcludeFromCodeCoverage(Justification = "Not testable")]
        static Func<string, bool> NewMethod()
        {
            return myString => myString.Length == 10;
        }
    }

    private void MethodThatTakesALambda(Func<string, bool> function)
    {
        // Do something - the actual function is not invoked to show the issue
        bool _ = function != null;
    }
}

Coverlet reports the line return myString => myString.Length == 10; as uncovered even though the local method is excluded from code coverage:

image

I would expect the local function to be shown as excluded.

The full code (along with other reproductions for already reported issues) is here: https://github.com/meggima/coverlet-reproductions

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtenet-coverageIssue related to possible incorrect coveragewith reproIssue with repro

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions