Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
daveMueller committed Nov 2, 2021
1 parent 79cf6f0 commit 0af5855
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Documentation/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/coverlet.core/Symbols/CecilSymbolHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ static bool CheckIfExceptionThrown(List<Instruction> instructions, Instruction i
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)
{
Expand Down
28 changes: 28 additions & 0 deletions test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,33 @@ public void AsyncAwait_Issue_1177()
File.Delete(path);
}
}

[Fact]
public void AsyncAwait_Issue_1233()
{
string path = Path.GetTempFileName();
try
{
FunctionExecutor.RunInProcess(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);
}
}
}
}
14 changes: 14 additions & 0 deletions test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,18 @@ async public Task Test()
await Task.CompletedTask;
}
}

public class Issue_1233
{
async public Task Test()
{
try
{
}
finally
{
await Task.CompletedTask;
}
}
}
}

0 comments on commit 0af5855

Please sign in to comment.