Fix multi-line lambda coverage regression (#1060)
Fix multi-line lambda coverage regression
This commit is contained in:
@@ -405,8 +405,8 @@ namespace Coverlet.Core
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -102,5 +102,40 @@ namespace Coverlet.Core.Tests
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Issue_1056()
|
||||
{
|
||||
string path = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
FunctionExecutor.Run(async (string[] pathSerialize) =>
|
||||
{
|
||||
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Issue_1056>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,6 +246,11 @@ namespace Coverlet.Core.Tests
|
||||
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)
|
||||
|
||||
@@ -103,4 +103,31 @@ namespace Coverlet.Core.Samples.Tests
|
||||
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<object> action)
|
||||
{
|
||||
action(new object());
|
||||
}
|
||||
|
||||
private static object Do2(System.Func<object, object> func)
|
||||
{
|
||||
return func(new object());
|
||||
}
|
||||
|
||||
public void WriteLine(string str) { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user