Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
62 changes: 61 additions & 1 deletion test/coverlet.core.tests/Coverage/CoverageTest.Yield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Yield_Single()
}

[Fact]
public void Yield_Multiple()
public void Yield_Two()
{
string path = Path.GetTempFileName();
try
Expand Down Expand Up @@ -100,5 +100,65 @@ public void Yield_SingleWithSwitch()
File.Delete(path);
}
}

[Fact]
public void Yield_Three()
{
string path = Path.GetTempFileName();
try
{
FunctionExecutor.Run(async (string[] pathSerialize) =>
{
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Yield>(instance =>
{
foreach (var _ in instance.Three()) ;

return Task.CompletedTask;
}, persistPrepareResultToFile: pathSerialize[0]);
return 0;
}, new string[] { path });

CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path);

result.Document("Instrumentation.Yield.cs")
.Method("System.Boolean Coverlet.Core.Samples.Tests.Yield/<Three>d__3::MoveNext()")
.AssertLinesCovered((42, 1), (43, 1), (44, 1))
.ExpectedTotalNumberOfBranches(0);
}
finally
{
File.Delete(path);
}
}

[Fact]
public void Yield_Enumerable()
{
string path = Path.GetTempFileName();
try
{
FunctionExecutor.Run(async (string[] pathSerialize) =>
{
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Yield>(instance =>
{
foreach (var _ in instance.Enumerable(new[] { "one", "two", "three", "four" })) ;

return Task.CompletedTask;
}, persistPrepareResultToFile: pathSerialize[0]);
return 0;
}, new string[] { path });

CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path);

result.Document("Instrumentation.Yield.cs")
.Method("System.Boolean Coverlet.Core.Samples.Tests.Yield/<Enumerable>d__4::MoveNext()")
.AssertLinesCovered((51, 4))
.ExpectedTotalNumberOfBranches(1);
}
finally
{
File.Delete(path);
}
}
}
}
15 changes: 15 additions & 0 deletions test/coverlet.core.tests/Samples/Instrumentation.Yield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,20 @@ public System.Collections.Generic.IEnumerable<int> OneWithSwitch(int n)

yield return result;
}

public System.Collections.Generic.IEnumerable<int> Three()
{
yield return 1;
yield return 2;
yield return 3;
}

public System.Collections.Generic.IEnumerable<string> Enumerable(System.Collections.Generic.IList<string> ls)
{
foreach (var item in ls)
{
yield return item;
}
}
}
}