diff --git a/src/coverlet.core/Coverage.cs b/src/coverlet.core/Coverage.cs index e2a74a18a..cdee8156a 100644 --- a/src/coverlet.core/Coverage.cs +++ b/src/coverlet.core/Coverage.cs @@ -405,8 +405,8 @@ private void CalculateCoverage() { if (hitCandidate != hitCandidateToCompare && !hitCandidateToCompare.isBranch) { - if (hitCandidateToCompare.start >= hitCandidate.start && - hitCandidateToCompare.end <= hitCandidate.end) + if (hitCandidateToCompare.start > hitCandidate.start && + hitCandidateToCompare.end < hitCandidate.end) { for (int i = hitCandidateToCompare.start; i <= (hitCandidateToCompare.end == 0 ? hitCandidateToCompare.start : hitCandidateToCompare.end); diff --git a/test/coverlet.core.tests/Coverage/CoverageTests.Lambda.cs b/test/coverlet.core.tests/Coverage/CoverageTests.Lambda.cs index 6ef519102..37b3e76aa 100644 --- a/test/coverlet.core.tests/Coverage/CoverageTests.Lambda.cs +++ b/test/coverlet.core.tests/Coverage/CoverageTests.Lambda.cs @@ -102,5 +102,40 @@ public void Lambda_Issue760() File.Delete(path); } } + + [Fact] + public void Issue_1056() + { + string path = Path.GetTempFileName(); + try + { + FunctionExecutor.Run(async (string[] pathSerialize) => + { + CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => + { + instance.T1(); + return Task.CompletedTask; + }, + persistPrepareResultToFile: pathSerialize[0]); + + return 0; + }, new string[] { path }); + + TestInstrumentationHelper.GetCoverageResult(path) + .Document("Instrumentation.Lambda.cs") + .AssertLinesCoveredFromTo(BuildConfiguration.Debug, 110, 119) + .AssertLinesCoveredFromTo(BuildConfiguration.Debug, 122, 124) + .AssertLinesCoveredFromTo(BuildConfiguration.Debug, 127, 129) + .AssertLinesCoveredFromTo(BuildConfiguration.Debug, 131, 131) + .AssertLinesCovered(BuildConfiguration.Debug, (110, 1), (111, 2), (112, 2), (113, 2), (114, 2), (115, 2), (116, 2), (117, 2), (118, 2), (119, 1), + (122, 2), (123, 2), (124, 2), + (127, 2), (128, 2), (129, 2), + (131, 4)); + } + finally + { + File.Delete(path); + } + } } } \ No newline at end of file diff --git a/test/coverlet.core.tests/Coverage/InstrumenterHelper.Assertions.cs b/test/coverlet.core.tests/Coverage/InstrumenterHelper.Assertions.cs index 92da3b47e..07f3e2bad 100644 --- a/test/coverlet.core.tests/Coverage/InstrumenterHelper.Assertions.cs +++ b/test/coverlet.core.tests/Coverage/InstrumenterHelper.Assertions.cs @@ -246,6 +246,11 @@ public static Document AssertLinesCoveredAllBut(this Document document, BuildCon return document; } + public static Document AssertLinesCoveredFromTo(this Document document, int from, int to) + { + return AssertLinesCoveredFromTo(document, BuildConfiguration.Debug | BuildConfiguration.Release, from, to); + } + public static Document AssertLinesCoveredFromTo(this Document document, BuildConfiguration configuration, int from, int to) { if (document is null) diff --git a/test/coverlet.core.tests/Samples/Instrumentation.Lambda.cs b/test/coverlet.core.tests/Samples/Instrumentation.Lambda.cs index b179b7ebf..dcf4ffee1 100644 --- a/test/coverlet.core.tests/Samples/Instrumentation.Lambda.cs +++ b/test/coverlet.core.tests/Samples/Instrumentation.Lambda.cs @@ -103,4 +103,31 @@ public async Task Foreach() return sum; } } + + public class Issue_1056 + { + public void T1() + { + Do(x => WriteLine(x.GetType().Name)); + Do(x => WriteLine(x + .GetType() + .Name)); + Do2(x => x.GetType().Name.Length); + Do2(x => x.GetType() + .Name + .Length); + } + + private static void Do(System.Action action) + { + action(new object()); + } + + private static object Do2(System.Func func) + { + return func(new object()); + } + + public void WriteLine(string str) { } + } }