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

ExcludeFromCodeCoverage attribute is ignored on local function #1302

Closed
meggima opened this issue Feb 15, 2022 · 3 comments · Fixed by #1306
Closed

ExcludeFromCodeCoverage attribute is ignored on local function #1302

meggima opened this issue Feb 15, 2022 · 3 comments · Fixed by #1306
Assignees
Labels
bug Something isn't working tenet-coverage Issue related to possible incorrect coverage with repro Issue with repro

Comments

@meggima
Copy link

meggima commented Feb 15, 2022

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

@meggima
Copy link
Author

meggima commented Feb 15, 2022

A similar issue is already mentioned here:

It should also come as no surprise that C#7.0 local functions are similarly not excluded even if the enclosing method is.

Originally posted by @SteveGilham in #82 (comment)

@MarcoRossignoli MarcoRossignoli added bug Something isn't working tenet-coverage Issue related to possible incorrect coverage labels Feb 20, 2022
@MarcoRossignoli
Copy link
Collaborator

Thanks for reporting this.

@MarcoRossignoli MarcoRossignoli added the with repro Issue with repro label Feb 20, 2022
@daveMueller
Copy link
Collaborator

I start to work on this.

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