Skip to content

Commit 06a5e59

Browse files
use remove branch strategy
1 parent 303a3b4 commit 06a5e59

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/coverlet.core/Coverage.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,6 @@ private void CalculateCoverage()
183183
int ordinal = int.Parse(info[3]);
184184
var branch = document.Branches[(start, ordinal)];
185185
branch.Hits += hits;
186-
187-
// for MoveNext() compiler autogenerated method we need to patch false positive (IAsyncStateMachine for instance)
188-
// the idea is force same hits on other branch
189-
if (CecilSymbolHelper.IsMoveNext(branch.Method))
190-
{
191-
foreach (var moveNextBranch in document.Branches)
192-
{
193-
if (moveNextBranch.Value.Method == branch.Method && moveNextBranch.Value != branch)
194-
{
195-
moveNextBranch.Value.Hits += hits;
196-
}
197-
}
198-
}
199186
}
200187
else
201188
{
@@ -209,6 +196,31 @@ private void CalculateCoverage()
209196
}
210197
}
211198

199+
// for MoveNext() compiler autogenerated method we need to patch false positive (IAsyncStateMachine for instance)
200+
// we'll remove all MoveNext() not covered branch
201+
foreach (var document in result.Documents)
202+
{
203+
List<KeyValuePair<(int, int), Branch>> branchesToRemove = new List<KeyValuePair<(int, int), Branch>>();
204+
foreach (var branch in document.Value.Branches)
205+
{
206+
//if one branch is covered we search the other one only if it's not covered
207+
if (CecilSymbolHelper.IsMoveNext(branch.Value.Method) && branch.Value.Hits > 0)
208+
{
209+
foreach (var moveNextBranch in document.Value.Branches)
210+
{
211+
if (moveNextBranch.Value.Method == branch.Value.Method && moveNextBranch.Value != branch.Value && moveNextBranch.Value.Hits == 0)
212+
{
213+
branchesToRemove.Add(moveNextBranch);
214+
}
215+
}
216+
}
217+
}
218+
foreach (var branchToRemove in branchesToRemove)
219+
{
220+
document.Value.Branches.Remove(branchToRemove.Key);
221+
}
222+
}
223+
212224
InstrumentationHelper.DeleteHitsFile(result.HitsFilePath);
213225
}
214226
}

0 commit comments

Comments
 (0)