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] lets through lambdas, yield return and await #129

Closed
SteveGilham opened this issue Jun 22, 2018 · 2 comments · Fixed by #671
Closed

[ExcludeFromCodeCoverage] lets through lambdas, yield return and await #129

SteveGilham opened this issue Jun 22, 2018 · 2 comments · Fixed by #671
Labels
bug Something isn't working tenet-coverage Issue related to possible incorrect coverage

Comments

@SteveGilham
Copy link

This code

    public class Class1
    {
        [ExcludeFromCodeCoverage]
        public int F1(string input)
        {
            Func<char, int> f = (c => { return (int)c; });

            return input.Select(x =>
            {
                var l = new List<char> { x };
                return l.Select(f).Last();
            }).Sum();
        }

        [ExcludeFromCodeCoverage]
        public IEnumerable<int> F2(string input)
        {
            foreach (char c in input)
            {
                yield return c;
            }
        }

        [ExcludeFromCodeCoverage]
        public async Task<string> F3(string input)
        {
            var f = new StreamReader(File.OpenRead(input));
            var r = await f.ReadToEndAsync();
            return r;
        }

        public static string F4(string input)
        {
            return input.ToUpperInvariant();
        }

        [ExcludeFromCodeCoverage]
        public string F5(string input)
        {
            return input.ToUpperInvariant();
        }
    }

with a test to exercise method F4.

Expect just method F4 in the coverage file, with 100% coverage
Get 15.8% line coverage, with the lambda expressions in F1 and generated MoveNext methods in the implementations of F2 and F3 showing uncovered.

@SteveGilham
Copy link
Author

The async/await case is the equivalent of OpenCover's issue #779.

@MarcoRossignoli MarcoRossignoli added tenet-coverage Issue related to possible incorrect coverage bug Something isn't working labels Sep 28, 2019
@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Sep 28, 2019

Possible related to #343
Unrelated...the issue is due to state machine generated for a method...that new type doesn't have exclude attrib applied.

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
Projects
None yet
2 participants