Fix coverage issue for finally block with await (#1245)

Fix coverage issue for finally block with await
This commit is contained in:
David Müller
2021-11-06 10:40:00 +01:00
committed by GitHub
parent cf59c4f6f6
commit 924d3bbe89
4 changed files with 46 additions and 3 deletions
+2 -1
View File
@@ -7,9 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Fixed
-Fix branch coverage issue for finally block with await [#1233](https://github.com/coverlet-coverage/coverlet/issues/1233)
-Fix threshold doesn't work when coverage empty [#1205](https://github.com/coverlet-coverage/coverlet/issues/1205)
-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)
-Fix branch coverage with using statement and several awaits[#1176](https://github.com/coverlet-coverage/coverlet/issues/1176)
### Improvements
-Improve logging in case of exception inside static ctor of NetstandardAwareAssemblyResolver [#1230](https://github.com/coverlet-coverage/coverlet/pull/1230)
@@ -543,9 +543,9 @@ namespace Coverlet.Core.Symbols
instructions[i].Operand is FieldDefinition field &&
IsCompilerGenerated(field) && field.FieldType.FullName == "System.Object")
{
// We expect the call to GetResult() to be no more than three
// We expect the call to GetResult() to be no more than four
// instructions before the loading of the field's value.
int minCallIndex = Math.Max(0, i - 3);
int minCallIndex = Math.Max(0, i - 4);
for (int j = i - 1; j >= minCallIndex; --j)
{
@@ -154,5 +154,33 @@ namespace Coverlet.Core.Tests
File.Delete(path);
}
}
[Fact]
public void AsyncAwait_Issue_1233()
{
string path = Path.GetTempFileName();
try
{
FunctionExecutor.Run(async (string[] pathSerialize) =>
{
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Issue_1233>(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, (150, 1));
Assert.DoesNotContain(document.Branches, x => x.Key.Line == 150);
}
finally
{
File.Delete(path);
}
}
}
}
@@ -137,4 +137,18 @@ namespace Coverlet.Core.Samples.Tests
await Task.CompletedTask;
}
}
public class Issue_1233
{
async public Task Test()
{
try
{
}
finally
{
await Task.CompletedTask;
}
}
}
}