-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip branches in generated
MoveNext()
for singleton iterators (#813)
Skip branches in generated `MoveNext()` for singleton iterators
- Loading branch information
Showing
6 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
test/coverlet.core.tests/Coverage/CoverageTest.Yield.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
using Coverlet.Core.Samples.Tests; | ||
using Tmds.Utils; | ||
using Xunit; | ||
|
||
namespace Coverlet.Core.Tests | ||
{ | ||
public partial class CoverageTests : ExternalProcessExecutionTest | ||
{ | ||
[Fact] | ||
public void Yield_Single() | ||
{ | ||
string path = Path.GetTempFileName(); | ||
try | ||
{ | ||
FunctionExecutor.Run(async (string[] pathSerialize) => | ||
{ | ||
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Yield>(instance => | ||
{ | ||
foreach (var _ in instance.One()) ; | ||
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/<One>d__0::MoveNext()") | ||
.AssertLinesCovered((9, 1)) | ||
.ExpectedTotalNumberOfBranches(0); | ||
} | ||
finally | ||
{ | ||
File.Delete(path); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Yield_Two() | ||
{ | ||
string path = Path.GetTempFileName(); | ||
try | ||
{ | ||
FunctionExecutor.Run(async (string[] pathSerialize) => | ||
{ | ||
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Yield>(instance => | ||
{ | ||
foreach (var _ in instance.Two()) ; | ||
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/<Two>d__1::MoveNext()") | ||
.AssertLinesCovered((14, 1), (15, 1)) | ||
.ExpectedTotalNumberOfBranches(0); | ||
} | ||
finally | ||
{ | ||
File.Delete(path); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Yield_SingleWithSwitch() | ||
{ | ||
string path = Path.GetTempFileName(); | ||
try | ||
{ | ||
FunctionExecutor.Run(async (string[] pathSerialize) => | ||
{ | ||
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Yield>(instance => | ||
{ | ||
foreach (var _ in instance.OneWithSwitch(2)) ; | ||
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/<OneWithSwitch>d__2::MoveNext()") | ||
.AssertLinesCovered(BuildConfiguration.Debug, (21, 1), (30, 1), (31, 1), (37, 1)) | ||
.ExpectedTotalNumberOfBranches(1); | ||
} | ||
finally | ||
{ | ||
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(BuildConfiguration.Debug, (48, 1), (49, 1), (50, 4), (51, 5), (52, 1), (54, 4), (55, 4), (56, 4), (57, 1)) | ||
.ExpectedTotalNumberOfBranches(1); | ||
} | ||
finally | ||
{ | ||
File.Delete(path); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Remember to use full name because adding new using directives change line numbers | ||
|
||
namespace Coverlet.Core.Samples.Tests | ||
{ | ||
public class Yield | ||
{ | ||
public System.Collections.Generic.IEnumerable<int> One() | ||
{ | ||
yield return 1; | ||
} | ||
|
||
public System.Collections.Generic.IEnumerable<int> Two() | ||
{ | ||
yield return 1; | ||
yield return 2; | ||
} | ||
|
||
public System.Collections.Generic.IEnumerable<int> OneWithSwitch(int n) | ||
{ | ||
int result; | ||
switch (n) | ||
{ | ||
case 0: | ||
result = 10; | ||
break; | ||
case 1: | ||
result = 11; | ||
break; | ||
case 2: | ||
result = 12; | ||
break; | ||
default: | ||
result = -1; | ||
break; | ||
} | ||
|
||
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters