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

Multi-line lambda false negatives in 3.0.1 #1056

Closed
ulrichb opened this issue Jan 16, 2021 · 17 comments · Fixed by #1060
Closed

Multi-line lambda false negatives in 3.0.1 #1056

ulrichb opened this issue Jan 16, 2021 · 17 comments · Fixed by #1060
Labels
bug Something isn't working tenet-coverage Issue related to possible incorrect coverage

Comments

@ulrichb
Copy link

ulrichb commented Jan 16, 2021

Okay, it got way better with 3.0.1 (after 3.0.0's #1037 has been fixed), but there are still false negatives (compared to coverlet.collector 1.3.0).

Example 1:
image

Example 2:
image

Originally posted by @ulrichb in #1037 (comment)

... I'm trying to create a repro sample.

@MarcoRossignoli MarcoRossignoli added tenet-coverage Issue related to possible incorrect coverage untriaged To be investigated labels Jan 16, 2021
@ulrichb
Copy link
Author

ulrichb commented Jan 16, 2021

Okay, it's simply a multi-line lamba:

    public class SampleTest
    {
        [Fact]
        public void T1()
        {
            Do(x => Console.WriteLine(x.GetType().Name));

            Do(x => Console.WriteLine(x
                .GetType()
                .Name));

            Do2(x => x.GetType().Name.Length);

            Do2(x => x.GetType()
                .Name
                .Length);
        }

        private static void Do(Action<object> action)
        {
            action(new object());
        }

        private static object Do2(Func<object, object> func)
        {
            return func(new object());
        }
    }

image

(Using latest ReportGenerator 4.8.4.)

@MarcoRossignoli
Copy link
Collaborator

Thanks

@ulrichb ulrichb changed the title False negatives in 3.0.1 (compared to coverlet.collector 1.3.0) Multi-line lambda false negatives in 3.0.1 (compared to coverlet.collector 1.3.0) Jan 16, 2021
@ulrichb ulrichb changed the title Multi-line lambda false negatives in 3.0.1 (compared to coverlet.collector 1.3.0) Multi-line lambda false negatives in 3.0.1 Jan 16, 2021
@MarcoRossignoli
Copy link
Collaborator

ok I was able to repro

image

@MarcoRossignoli MarcoRossignoli added bug Something isn't working and removed untriaged To be investigated labels Jan 16, 2021
@ulrichb
Copy link
Author

ulrichb commented Jan 16, 2021

Nice. And btw. thanks for this great, great tool!

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Jan 16, 2021

We changed a bit the accounting alg because it was a mess, now we need to adjust a bit. Np we'll fix it.

@MarcoRossignoli
Copy link
Collaborator

@ulrichb can you try the fix?

coverlet.console.3.0.2-preview.2.g6741924090.zip

@ulrichb
Copy link
Author

ulrichb commented Jan 16, 2021

Hmm, do you also have a prerelease .collector nuget package?

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Jan 16, 2021

It's a zip with all three packages inside.
Didn't renamed sorry.

@ulrichb
Copy link
Author

ulrichb commented Jan 16, 2021

Yipee, just tested your build and my repro and my real code is 100% covered again. Thank you very much!

@MarcoRossignoli
Copy link
Collaborator

@martincostello @JSkimming @Malivil @Dave-EMIS someone of you can try the package on your project and let us know if it's all ok? #1056 (comment)

@Malivil
Copy link

Malivil commented Jan 17, 2021

Looks good on my solution. The only unexpected change I saw was marking a line as covered that ended a multi-line ternary statement with multi-line lambdas inside. I think it's completely understandable to show that as covered, though, so I don't think it's a problem. For example:

return DoThing ? 
    HandleThingTrue(() => // Entire lambda covered
    {
        DoOtherThing();
    })
    : HandleThingFalse(() => // Entire lambda uncovered
    {
        DoThirdThing();
    }); // Covered

In terms of the coverage numbers:

MSBuild 2.9.0: 2 9 0 Coverage
MSBuild 3.0.1: 3 0 1 Coverage
MSBuild 3.0.2: 3 0 2 Coverage

The only number that went down was branch coverage and it looks, to me, like that branch is not really covered so that's a positive too

Overall, looks good to me =)

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Jan 17, 2021

I think it's completely understandable to show that as covered, though, so I don't think it's a problem.

It's ok...lambda accounting it's a bit complex, coverlet uses sequence points(strong choice sometimes uncomfortable) and sometimes are "nested" i.e.

sequence A hitted
line 1 { hit
line 2 ... hit
line 3 ... hit
line 4 } hit

sequence B (lambda closure object) not hitted
line 2 ... no hit
line 3 ... no hit

When we have an hit for A and not for B we account for covered line 1 and 4 from A but we use sequence B for 2 and 3.

Thx @Malivil

@MarcoRossignoli MarcoRossignoli pinned this issue Jan 17, 2021
@JSkimming
Copy link

@MarcoRossignoli Results comparing different version of coverlet and OpenCover.

Summary

All looks good.

Results

coverlet.msbuild 2.9.0 coverlet.msbuild 3.0.1 coverlet.msbuild 3.0.2-preview.2.g6741924090 OpenCover 4.7.922
Castle.Core.AsyncInterceptor (Debug) 100% (328 of 328) 100% (328 of 328) 100% (328 of 328) 100% (333 of 333)
Castle.Core.AsyncInterceptor (Release) 100% (220 of 220) 100% (220 of 220) 100% (220 of 220) 100% (227 of 227)
abioc (Debug) 99.8% (2215 of 2219) 99.8% (2216 of 2219) 99.8% (2216 of 2219) 99.8% (2219 of 2222)
abioc (Release) 99.8% (1743 of 1745) 99.9% (1744 of 1745) 99.9% (1744 of 1745) no longer works 🤷
Tesla.NET (Debug) 100% (683 of 683) 100% (683 of 683) 100% (683 of 683) 100% (683 of 683)
Tesla.NET (Release) 100% (589 of 589) 100% (589 of 589) 100% (589 of 589) 100% (589 of 589)

It looks like I incorrectly compared debug and release version when I stated coverlet was now giving comparable results as OpenCover, though the good news is, it already was 😃

@JSkimming
Copy link

I'm, not a big user of lambdas, I tend to use local functions or private methods for anything more complex than x => x.Property, which may be why my libraries are unaffected.

@MarcoRossignoli
Copy link
Collaborator

Thx for the test @JSkimming

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Jan 17, 2021

After midnight will be on nightly https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/ConsumeNightlyBuild.md
I'd like need to check another issue before release, if I won't find a solution I'll release in a week.

@MarcoRossignoli MarcoRossignoli unpinned this issue Jan 17, 2021
@MarcoRossignoli
Copy link
Collaborator

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
Development

Successfully merging a pull request may close this issue.

4 participants