-
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.
Incorrect coverage for methods returning IAsyncEnumerable in generic …
…classes (#1430)
- Loading branch information
1 parent
72d5ee2
commit 04b82c2
Showing
5 changed files
with
84 additions
and
3 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
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
42 changes: 42 additions & 0 deletions
42
test/coverlet.core.tests/Coverage/CoverageTests.GenericAsyncIterator.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,42 @@ | ||
// Copyright (c) Toni Solarin-Sodara | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Coverlet.Core.Samples.Tests; | ||
using Xunit; | ||
|
||
namespace Coverlet.Core.Tests | ||
{ | ||
public partial class CoverageTests | ||
{ | ||
[Fact] | ||
public void GenericAsyncIterator() | ||
{ | ||
string path = Path.GetTempFileName(); | ||
try | ||
{ | ||
FunctionExecutor.Run(async (string[] pathSerialize) => | ||
{ | ||
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<GenericAsyncIterator<int>>(instance => | ||
{ | ||
List<int> res = ((Task<List<int>>)instance.Issue1383()).GetAwaiter().GetResult(); | ||
return Task.CompletedTask; | ||
}, persistPrepareResultToFile: pathSerialize[0]); | ||
return 0; | ||
}, new string[] { path }); | ||
|
||
TestInstrumentationHelper.GetCoverageResult(path) | ||
.Document("Instrumentation.GenericAsyncIterator.cs") | ||
.AssertLinesCovered(BuildConfiguration.Debug, (13, 1), (14, 1), (20, 1), (21, 1), (22, 1)) | ||
.ExpectedTotalNumberOfBranches(BuildConfiguration.Debug, 0); | ||
} | ||
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
25 changes: 25 additions & 0 deletions
25
test/coverlet.core.tests/Samples/Instrumentation.GenericAsyncIterator.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,25 @@ | ||
// Remember to use full name because adding new using directives change line numbers | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Coverlet.Core.Samples.Tests | ||
{ | ||
public class GenericAsyncIterator<T> | ||
{ | ||
public async Task<List<int>> Issue1383() | ||
{ | ||
var sequence = await CreateSequenceAsync().ToListAsync(); | ||
return sequence; | ||
} | ||
|
||
|
||
public async IAsyncEnumerable<int> CreateSequenceAsync() | ||
{ | ||
await Task.CompletedTask; | ||
yield return 5; | ||
yield return 2; | ||
} | ||
} | ||
} |