We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi again) Code:
namespace CoverletAsync { public class MyService { public async Task<byte[]> GetBytes(Func<Task<bool>> process, Func<Task<MemoryStream>> getStream, Func<ISession> getSession, Func<Stream, ISession, Task<byte[]>> doWithStream) { if (!await process()) { return Array.Empty<byte>(); } using var session = getSession(); await using var stream = await getStream(); return await doWithStream(stream, session); } public interface ISession : IDisposable { } } }
Test:
namespace CoverletAsync.Tests { public class Tests { [Test] public async Task SomeMethodEmpty() { await using var memoryStream = new MemoryStream(); var actual = await new MyService().GetBytes(() => Task.FromResult(false), () => Task.FromResult(memoryStream), () => new TestSession(), (stream, session) => Task.FromResult(new byte[] { 0x01, 0x02 })); CollectionAssert.IsEmpty(actual); } [Test] public async Task SomeMethodNonEmpty() { await using var memoryStream = new MemoryStream(); var actual = await new MyService().GetBytes(() => Task.FromResult(true), () => Task.FromResult(memoryStream), () => new TestSession(), (stream, session) => Task.FromResult(new byte[] { 0x01, 0x02 })); Assert.That(actual, Is.EqualTo(new byte[] { 0x01, 0x02 })); } private class TestSession : MyService.ISession { public void Dispose() { } } } }
Expected: Full branch coverage
Actual: Partially covered (1 visits, 2 of 4 branches are covered)
Output:
Report:
<?xml version="1.0" encoding="utf-8"?> <coverage line-rate="1" branch-rate="0.75" version="1.9" timestamp="1623166089" lines-covered="8" lines-valid="8" branches-covered="6" branches-valid="8"> <sources> <source>F:\</source> </sources> <packages> <package name="CoverletAsync" line-rate="1" branch-rate="0.75" complexity="8"> <classes> <class name="CoverletAsync.MyService/<GetBytes>d__0" filename="Work\experiments\CoverletAsync\CoverletAsync\MyService.cs" line-rate="1" branch-rate="0.75" complexity="8"> <methods> <method name="MoveNext" signature="()" line-rate="1" branch-rate="0.75" complexity="8"> <lines> <line number="10" hits="2" branch="True" condition-coverage="100% (2/2)"> <conditions> <condition number="16" type="jump" coverage="100%" /> </conditions> </line> <line number="11" hits="2" branch="True" condition-coverage="100% (2/2)"> <conditions> <condition number="146" type="jump" coverage="100%" /> </conditions> </line> <line number="12" hits="1" branch="False" /> <line number="13" hits="1" branch="False" /> <line number="16" hits="1" branch="True" condition-coverage="50% (2/4)"> <conditions> <condition number="181" type="switch" coverage="50%" /> </conditions> </line> <line number="17" hits="1" branch="False" /> <line number="18" hits="1" branch="False" /> <line number="19" hits="2" branch="False" /> </lines> </method> </methods> <lines> <line number="10" hits="2" branch="True" condition-coverage="100% (2/2)"> <conditions> <condition number="16" type="jump" coverage="100%" /> </conditions> </line> <line number="11" hits="2" branch="True" condition-coverage="100% (2/2)"> <conditions> <condition number="146" type="jump" coverage="100%" /> </conditions> </line> <line number="12" hits="1" branch="False" /> <line number="13" hits="1" branch="False" /> <line number="16" hits="1" branch="True" condition-coverage="50% (2/4)"> <conditions> <condition number="181" type="switch" coverage="50%" /> </conditions> </line> <line number="17" hits="1" branch="False" /> <line number="18" hits="1" branch="False" /> <line number="19" hits="2" branch="False" /> </lines> </class> </classes> </package> </packages> </coverage>
Run: dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
Reproduced in .NET Core 3.1, Coverlet 3.0.3 / Coverlet 3.0.4-preview.31.g4902c245c8
The text was updated successfully, but these errors were encountered:
Maybe a duplicate #1176.
Sorry, something went wrong.
The IL switch isn't ignored when there is a code like this
switch
await xxx await await await
I just took a quick peek and couldn't properly detect the pattern yet but I'm working on it. And I now can confirm that it is a duplicate to #1176.
daveMueller
Successfully merging a pull request may close this issue.
Hi again)
Code:
Test:
Expected:
Full branch coverage
Actual:
Partially covered (1 visits, 2 of 4 branches are covered)
Output:
Report:
Run: dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
Reproduced in .NET Core 3.1, Coverlet 3.0.3 / Coverlet 3.0.4-preview.31.g4902c245c8
The text was updated successfully, but these errors were encountered: