Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Documentation/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed
-Fix branch coverage issue for il switch [#1177](https://github.com/coverlet-coverage/coverlet/issues/1177)
-Fix branch coverage with using statement and several awaits[#1176](https://github.com/coverlet-coverage/coverlet/issues/1176)

## Release date 2021-07-19
### Packages
coverlet.msbuild 3.1.0
Expand Down
8 changes: 4 additions & 4 deletions src/coverlet.core/Symbols/CecilSymbolHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ private static bool SkipMoveNextPrologueBranches(Instruction instruction)
If method is a generated MoveNext we'll skip first branches (could be a switch or a series of branches)
that check state machine value to jump to correct state (for instance after a true async call)
Check if it's a Cond_Branch on state machine current value int num = <>1__state;
We are on branch OpCode so we need to go back by max 2 operation to reach ldloc.0 the load of "num"
Max 2 because we handle following patterns
We are on branch OpCode so we need to go back by max 3 operation to reach ldloc.0 the load of "num"
Max 3 because we handle following patterns

Swich

Expand Down Expand Up @@ -168,7 +168,7 @@ so we know that current branch are checking that field and we're not interested
*/

Instruction current = instruction.Previous;
for (int instructionBefore = 2; instructionBefore > 0 && current.Previous != null; current = current.Previous, instructionBefore--)
for (int instructionBefore = 3; instructionBefore > 0 && current.Previous != null; current = current.Previous, instructionBefore--)
{
if (
(current.OpCode == OpCodes.Ldloc && current.Operand is VariableDefinition vo && vo.Index == 0) ||
Expand Down Expand Up @@ -1446,4 +1446,4 @@ public int Compare(Instruction x, Instruction y)
}
}
}
}
}
29 changes: 29 additions & 0 deletions test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;

using Coverlet.Core.Samples.Tests;
Expand Down Expand Up @@ -125,5 +126,33 @@ public void AsyncAwait_Issue_669_2()
File.Delete(path);
}
}

[Fact]
public void AsyncAwait_Issue_1177()
{
string path = Path.GetTempFileName();
try
{
FunctionExecutor.Run(async (string[] pathSerialize) =>
{
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Issue_1177>(instance =>
{
((Task)instance.Test()).ConfigureAwait(false).GetAwaiter().GetResult();
return Task.CompletedTask;
},
persistPrepareResultToFile: pathSerialize[0]);

return 0;
}, new string[] { path });

var document = TestInstrumentationHelper.GetCoverageResult(path).Document("Instrumentation.AsyncAwait.cs");
document.AssertLinesCovered(BuildConfiguration.Debug, (133, 1), (134, 1), (135, 1), (136, 1), (137, 1));
Assert.DoesNotContain(document.Branches, x => x.Key.Line == 134);
}
finally
{
File.Delete(path);
}
}
}
}
12 changes: 12 additions & 0 deletions test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,16 @@ public interface IService
Task Process(string cat);
}
}

public class Issue_1177
{
async public Task Test()
{
await Task.CompletedTask;
using var _ = new System.IO.MemoryStream();
await Task.CompletedTask;
await Task.CompletedTask;
await Task.CompletedTask;
}
}
}