Skip to content

Commit b8e6911

Browse files
committed
bugfix #1233
1 parent 79cf6f0 commit b8e6911

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

Documentation/Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## Unreleased
88

99
### Fixed
10+
-Fix branch coverage issue for finally block with await [#1233](https://github.com/coverlet-coverage/coverlet/issues/1233)
1011
-Fix threshold doesn't work when coverage empty [#1205](https://github.com/coverlet-coverage/coverlet/issues/1205)
1112
-Fix branch coverage issue for il switch [#1177](https://github.com/coverlet-coverage/coverlet/issues/1177)
12-
-Fix branch coverage with using statement and several awaits[#1176](https://github.com/coverlet-coverage/coverlet/issues/1176)
13+
-Fix branch coverage with using statement and several awaits[#1176](https://github.com/coverlet-coverage/coverlet/issues/1176)
1314

1415
### Improvements
1516
-Improve logging in case of exception inside static ctor of NetstandardAwareAssemblyResolver [#1230](https://github.com/coverlet-coverage/coverlet/pull/1230)

src/coverlet.core/Symbols/CecilSymbolHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,9 @@ static bool CheckIfExceptionThrown(List<Instruction> instructions, Instruction i
543543
instructions[i].Operand is FieldDefinition field &&
544544
IsCompilerGenerated(field) && field.FieldType.FullName == "System.Object")
545545
{
546-
// We expect the call to GetResult() to be no more than three
546+
// We expect the call to GetResult() to be no more than four
547547
// instructions before the loading of the field's value.
548-
int minCallIndex = Math.Max(0, i - 3);
548+
int minCallIndex = Math.Max(0, i - 4);
549549

550550
for (int j = i - 1; j >= minCallIndex; --j)
551551
{

test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,33 @@ public void AsyncAwait_Issue_1177()
154154
File.Delete(path);
155155
}
156156
}
157+
158+
[Fact]
159+
public void AsyncAwait_Issue_1233()
160+
{
161+
string path = Path.GetTempFileName();
162+
try
163+
{
164+
FunctionExecutor.Run(async (string[] pathSerialize) =>
165+
{
166+
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Issue_1233>(instance =>
167+
{
168+
((Task)instance.Test()).ConfigureAwait(false).GetAwaiter().GetResult();
169+
return Task.CompletedTask;
170+
},
171+
persistPrepareResultToFile: pathSerialize[0]);
172+
173+
return 0;
174+
}, new string[] { path });
175+
176+
var document = TestInstrumentationHelper.GetCoverageResult(path).Document("Instrumentation.AsyncAwait.cs");
177+
document.AssertLinesCovered(BuildConfiguration.Debug, (150, 1));
178+
Assert.DoesNotContain(document.Branches, x => x.Key.Line == 150);
179+
}
180+
finally
181+
{
182+
File.Delete(path);
183+
}
184+
}
157185
}
158186
}

test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,18 @@ async public Task Test()
137137
await Task.CompletedTask;
138138
}
139139
}
140+
141+
public class Issue_1233
142+
{
143+
async public Task Test()
144+
{
145+
try
146+
{
147+
}
148+
finally
149+
{
150+
await Task.CompletedTask;
151+
}
152+
}
153+
}
140154
}

0 commit comments

Comments
 (0)