|
4 | 4 | using System.IO; |
5 | 5 | using System.Linq; |
6 | 6 | using Coverlet.Tests.Utils; |
7 | | -using Coverlet.Tests.Xunit.Extensions; |
8 | 7 | using Xunit; |
9 | 8 | using Xunit.Abstractions; |
10 | 9 |
|
@@ -61,64 +60,79 @@ public void StandAlone() |
61 | 60 | AssertCoverage(clonedTemplateProject, standardOutput: standardOutput); |
62 | 61 | } |
63 | 62 |
|
64 | | - [ConditionalFact] |
65 | | - [SkipOnOS(OS.Linux)] |
66 | | - [SkipOnOS(OS.MacOS)] |
| 63 | + [Fact] |
67 | 64 | public void StandAloneThreshold() |
68 | 65 | { |
69 | 66 | using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject(); |
70 | 67 | UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!); |
71 | 68 | string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!); |
| 69 | + string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json"; |
72 | 70 | DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError); |
73 | 71 | string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref")); |
74 | | - Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --output \"{clonedTemplateProject.ProjectRootPath}\"\\", out standardOutput, out standardError)); |
| 72 | + Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --output \"{outputPath}\"", out standardOutput, out standardError)); |
75 | 73 | if (!string.IsNullOrEmpty(standardError)) |
76 | 74 | { |
77 | 75 | _output.WriteLine(standardError); |
78 | 76 | } |
| 77 | + else |
| 78 | + { |
| 79 | + // make standard output available in trx file |
| 80 | + _output.WriteLine(standardOutput); |
| 81 | + } |
79 | 82 | Assert.Contains("Hello World!", standardOutput); |
| 83 | + Assert.True(File.Exists($"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json")); |
80 | 84 | AssertCoverage(clonedTemplateProject, standardOutput: standardOutput); |
81 | 85 | Assert.Contains("The minimum line coverage is below the specified 80", standardOutput); |
82 | 86 | Assert.Contains("The minimum method coverage is below the specified 80", standardOutput); |
83 | 87 | } |
84 | 88 |
|
85 | | - [ConditionalFact] |
86 | | - [SkipOnOS(OS.Linux)] |
87 | | - [SkipOnOS(OS.MacOS)] |
| 89 | + [Fact] |
88 | 90 | public void StandAloneThresholdLine() |
89 | 91 | { |
90 | 92 | using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject(); |
91 | 93 | UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!); |
92 | 94 | string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!); |
| 95 | + string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json"; |
93 | 96 | DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError); |
94 | 97 | string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref")); |
95 | | - Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --output \"{clonedTemplateProject.ProjectRootPath}\"\\", out standardOutput, out standardError)); |
| 98 | + Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --output \"{outputPath}\"", out standardOutput, out standardError)); |
96 | 99 | if (!string.IsNullOrEmpty(standardError)) |
97 | 100 | { |
98 | 101 | _output.WriteLine(standardError); |
99 | 102 | } |
| 103 | + else |
| 104 | + { |
| 105 | + // make standard output available in trx file |
| 106 | + _output.WriteLine(standardOutput); |
| 107 | + } |
100 | 108 | Assert.Contains("Hello World!", standardOutput); |
| 109 | + Assert.True(File.Exists($"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json")); |
101 | 110 | AssertCoverage(clonedTemplateProject, standardOutput: standardOutput); |
102 | 111 | Assert.Contains("The minimum line coverage is below the specified 80", standardOutput); |
103 | 112 | Assert.DoesNotContain("The minimum method coverage is below the specified 80", standardOutput); |
104 | 113 | } |
105 | 114 |
|
106 | | - [ConditionalFact] |
107 | | - [SkipOnOS(OS.Linux)] |
108 | | - [SkipOnOS(OS.MacOS)] |
| 115 | + [Fact] |
109 | 116 | public void StandAloneThresholdLineAndMethod() |
110 | 117 | { |
111 | 118 | using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject(); |
112 | 119 | UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!); |
113 | 120 | string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!); |
| 121 | + string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json"; |
114 | 122 | DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError); |
115 | 123 | string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref")); |
116 | | - Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --threshold-type method --output \"{clonedTemplateProject.ProjectRootPath}\"\\", out standardOutput, out standardError)); |
| 124 | + Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --threshold-type method --output \"{outputPath}\"", out standardOutput, out standardError)); |
117 | 125 | if (!string.IsNullOrEmpty(standardError)) |
118 | 126 | { |
119 | 127 | _output.WriteLine(standardError); |
120 | 128 | } |
| 129 | + else |
| 130 | + { |
| 131 | + // make standard output available in trx file |
| 132 | + _output.WriteLine(standardOutput); |
| 133 | + } |
121 | 134 | Assert.Contains("Hello World!", standardOutput); |
| 135 | + Assert.True(File.Exists($"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json")); |
122 | 136 | AssertCoverage(clonedTemplateProject, standardOutput: standardOutput); |
123 | 137 | Assert.Contains("The minimum line coverage is below the specified 80", standardOutput); |
124 | 138 | Assert.Contains("The minimum method coverage is below the specified 80", standardOutput); |
|
0 commit comments