-
Notifications
You must be signed in to change notification settings - Fork 388
/
Copy pathDotnetTool.cs
145 lines (137 loc) · 8.47 KB
/
DotnetTool.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// 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 Coverlet.Tests.Utils;
using Xunit;
namespace Coverlet.Integration.Tests
{
public class DotnetGlobalTools : BaseTest
{
private readonly ITestOutputHelper _output;
private readonly string _buildTargetFramework;
public DotnetGlobalTools(ITestOutputHelper output)
{
_output = output;
_buildTargetFramework = TestUtils.GetAssemblyTargetFramework();
}
private string InstallTool(string projectPath)
{
_ = DotnetCli($"tool install coverlet.console --version {GetPackageVersion("*console*.nupkg")} --tool-path \"{Path.Combine(projectPath, "coverletTool")}\"", out string standardOutput, out string standardError, projectPath);
Assert.Contains("was successfully installed.", standardOutput);
Assert.Empty(standardError);
return Path.Combine(projectPath, "coverletTool", "coverlet");
}
[Fact]
public void DotnetTool()
{
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string buildOutput, out string buildError);
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
int cmdExitCode = RunCommand(coverletToolCommandPath, $"\"{publishedTestFile}\" --target \"dotnet\" --targetargs \"test {Path.Combine(clonedTemplateProject.ProjectRootPath, ClonedTemplateProject.ProjectFileName)} --no-build\" --include-test-assembly --output \"{outputPath}\"", out string standardOutput, out string standardError);
if (!string.IsNullOrEmpty(standardError))
{
_output.WriteLine(standardError);
}
Assert.Contains("Passed!", standardOutput);
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
Assert.Equal((int)CommandExitCodes.Success, cmdExitCode);
}
[Fact]
public void StandAlone()
{
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string buildOutput, out string buildError);
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
int cmdExitCode = RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --output \"{outputPath}\"", out string standardOutput, out string standardError);
if (!string.IsNullOrEmpty(standardError))
{
_output.WriteLine(standardError);
}
Assert.True(File.Exists(outputPath));
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
Assert.Equal((int)CommandExitCodes.Success, cmdExitCode);
}
[Fact]
public void StandAloneThreshold()
{
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string buildOutput, out string buildError);
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
int cmdExitCode = RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --output \"{outputPath}\"", out string standardOutput, out string standardError);
if (!string.IsNullOrEmpty(standardError))
{
_output.WriteLine(standardError);
}
else
{
// make standard output available in trx file
_output.WriteLine(standardOutput);
}
Assert.True(File.Exists(outputPath));
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
}
[Fact]
public void StandAloneThresholdLine()
{
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string buildOutput, out string buildError);
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
int cmdExitCode = RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --output \"{outputPath}\"", out string standardOutput, out string standardError);
if (!string.IsNullOrEmpty(standardError))
{
_output.WriteLine(standardError);
}
else
{
// make standard output available in trx file
_output.WriteLine(standardOutput);
}
Assert.True(File.Exists(outputPath));
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
Assert.DoesNotContain("The minimum method coverage is below the specified 80", standardOutput);
}
[Fact]
public void StandAloneThresholdLineAndMethod()
{
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string buildOutput, out string buildError);
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
int cmdExitCode = RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --threshold-type method --output \"{outputPath}\"", out string standardOutput, out string standardError);
if (!string.IsNullOrEmpty(standardError))
{
_output.WriteLine(standardError);
}
else
{
// make standard output available in trx file
_output.WriteLine(standardOutput);
}
Assert.True(File.Exists(outputPath));
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
}
}
}