Skip to content

Commit 3edf519

Browse files
fix false positive
1 parent d4890a6 commit 3edf519

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/coverlet.core/Coverage.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
using Coverlet.Core.Helpers;
2+
using Coverlet.Core.Instrumentation;
3+
using Coverlet.Core.Symbols;
14
using System;
25
using System.Collections.Generic;
36
using System.IO;
4-
using System.IO.Compression;
57
using System.Linq;
6-
7-
using Coverlet.Core.Helpers;
8-
using Coverlet.Core.Instrumentation;
9-
8+
109
namespace Coverlet.Core
1110
{
1211
public class Coverage
@@ -183,6 +182,18 @@ private void CalculateCoverage()
183182
{
184183
int ordinal = int.Parse(info[3]);
185184
var branch = document.Branches[(start, ordinal)];
185+
// for MoveNext() compiler autogenerated method we need to patch false positive (IAsyncStateMachine for instance)
186+
// the idea is force same hits on other branch
187+
if (CecilSymbolHelper.IsMoveNext(branch.Method))
188+
{
189+
foreach (var moveNextBranch in document.Branches)
190+
{
191+
if (moveNextBranch.Value.Method == branch.Method && moveNextBranch.Value != branch)
192+
{
193+
moveNextBranch.Value.Hits += hits;
194+
}
195+
}
196+
}
186197
branch.Hits += hits;
187198
}
188199
else

src/coverlet.core/Symbols/CecilSymbolHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public static class CecilSymbolHelper
2020
private const int StepOverLineCode = 0xFEEFEE;
2121
private static readonly Regex IsMovenext = new Regex(@"\<[^\s>]+\>\w__\w(\w)?::MoveNext\(\)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
2222

23+
public static bool IsMoveNext(string fullName)
24+
{
25+
return IsMovenext.IsMatch(fullName);
26+
}
27+
2328
public static List<BranchPoint> GetBranchPoints(MethodDefinition methodDefinition)
2429
{
2530
var list = new List<BranchPoint>();

0 commit comments

Comments
 (0)