Repository navigation
Expand file tree
/
Copy pathCoverageTests.PatternMatchingOr.cs
More file actions
55 lines (48 loc) · 1.94 KB
/
Copy pathCoverageTests.PatternMatchingOr.cs
File metadata and controls
55 lines (48 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) Toni Solarin-Sodara
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Coverlet.Core;
using Coverlet.Core.CoverageSamples.Tests;
using Coverlet.Core.Tests;
using Xunit;
namespace Coverlet.CoreCoverage.Tests
{
public partial class CoverageTests : ExternalProcessExecutionTest
{
[Fact]
public void PatternMatchingOr_Should_Report_100_Percent_Branch_Coverage()
{
string path = Path.GetTempFileName();
try
{
FunctionExecutor.Run(async (string[] pathSerialize) =>
{
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<PatternMatchingOr>(instance =>
{
instance.PatternMatching("hello");
instance.PatternMatching("world");
instance.PatternMatching("other");
return Task.CompletedTask;
}, persistPrepareResultToFile: pathSerialize[0]);
return 0;
}, [path]);
CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path);
var methodDocument = result.Document("Instrumentation.PatternMatchingOr.cs")
.Method("System.Boolean Coverlet.Core.CoverageSamples.Tests.PatternMatchingOr::PatternMatching(System.String)");
var branches = methodDocument.Branches.Values.OrderBy(x => x.Ordinal).ToArray();
Assert.Equal(2, branches.Length);
Assert.Equal(new uint[] { 0, 1 }, branches.Select(x => x.Ordinal).ToArray());
Assert.Equal(new[] { 0, 1 }, branches.Select(x => x.Path).ToArray());
Assert.All(branches, branch => Assert.Equal(9, branch.Number));
Assert.Equal(branches[0].Offset, branches[1].Offset);
Assert.All(branches, branch => Assert.True(branch.Hits > 0));
}
finally
{
File.Delete(path);
}
}
}
}