Skip to content

ExcludeFromCodeCoverage attribute on local functions ignores lambda expression #1306

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

Conversation

daveMueller
Copy link
Collaborator

closes #1302

@daveMueller daveMueller force-pushed the 1302_ExcludeFromCoverageLambdaInsideLocalFunction branch from f7476a2 to e96a5c8 Compare February 27, 2022 01:36
@daveMueller
Copy link
Collaborator Author

The issue is only for lambda methods inside local functions. The algorithm that checks if the function name is synthesized by the compiler doesn't work here because the base for the lambda method name is the 'parent' function and not the local function.

For example when we have the following code:

public void ParentFunction()
{
    [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
    static Func<string, bool> LocalFunction()
    {
        return myString => myString.Length == 10;
     }
}

The name of the local function is sth like <ParentFunction>g__LocalFunction|0_0 and the name of the lambda method sth like <ParentFunction>b__0_1. The current algorithem compares only the name of the 'parent' function which is ParentFunction and looks up if it is already excluded.
Unfortunately ParentFunction isn't the one with the ExcludeFromCodeCoverage attribute and thus the lambda method isn't excluded.

I couldn't think of any other solution besides this PR because from a name like <ParentFunction>b__0_1 it seems impossible to figure out if the lambda method is inside a local function or not.

Copy link
Collaborator

@MarcoRossignoli MarcoRossignoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's resolve the conflict and we can merge thanks

…ideLocalFunction

# Conflicts:
#	Documentation/Changelog.md
@daveMueller
Copy link
Collaborator Author

Ok I resolved the merge conflicts.

@MarcoRossignoli MarcoRossignoli merged commit ebbf042 into coverlet-coverage:master Mar 15, 2022
@daveMueller daveMueller deleted the 1302_ExcludeFromCoverageLambdaInsideLocalFunction branch March 16, 2022 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ExcludeFromCodeCoverage attribute is ignored on local function
2 participants