Skip to content

Commit 891a937

Browse files
committed
use enum CommandExitCodes
1 parent cd23718 commit 891a937

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// Copyright (c) Toni Solarin-Sodara
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.Runtime.CompilerServices;
5+
46
[assembly: System.Reflection.AssemblyKeyFileAttribute("coverlet.console.snk")]
7+
[assembly: InternalsVisibleTo("coverlet.integration.tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010001d24efbe9cbc2dc49b7a3d2ae34ca37cfb69b4f450acd768a22ce5cd021c8a38ae7dc68b2809a1ac606ad531b578f192a5690b2986990cbda4dd84ec65a3a4c1c36f6d7bb18f08592b93091535eaee2f0c8e48763ed7f190db2008e1f9e0facd5c0df5aaab74febd3430e09a428a72e5e6b88357f92d78e47512d46ebdc3cbb")]
8+

test/coverlet.integration.tests/Collectors.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ private protected virtual void AssertCollectorsInjection(ClonedTemplateProject c
8181
public void TestVsTest_Test()
8282
{
8383
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject();
84-
Assert.True(DotnetCli($"test -c {_buildConfiguration} -f {_buildTargetFramework} \"{clonedTemplateProject.ProjectRootPath}\" --collect:\"XPlat Code Coverage\" --diag:{Path.Combine(clonedTemplateProject.ProjectRootPath, "log.txt")}", out string standardOutput, out string standardError, clonedTemplateProject.ProjectRootPath!), standardOutput);
84+
DotnetCli($"test -c {_buildConfiguration} -f {_buildTargetFramework} \"{clonedTemplateProject.ProjectRootPath}\" --collect:\"XPlat Code Coverage\" --diag:{Path.Combine(clonedTemplateProject.ProjectRootPath, "log.txt")}", out string _, out string _, clonedTemplateProject.ProjectRootPath!);
8585
// We don't have any result to check because tests and code to instrument are in same assembly so we need to pass
8686
// IncludeTestAssembly=true we do it in other test
87+
Assert.Equal((int)CommandExitCodes.Success, DotnetCli($"test -c {_buildConfiguration} -f {_buildTargetFramework} \"{clonedTemplateProject.ProjectRootPath}\" --collect:\"XPlat Code Coverage\" --diag:{Path.Combine(clonedTemplateProject.ProjectRootPath, "log.txt")}", out string standardOutput, out string standardError, clonedTemplateProject.ProjectRootPath!));
8788
Assert.Contains("Passed!", standardOutput);
8889
AssertCollectorsInjection(clonedTemplateProject);
8990
}
@@ -93,7 +94,7 @@ public void TestVsTest_Test_Settings()
9394
{
9495
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject();
9596
string runSettingsPath = AddCollectorRunsettingsFile(clonedTemplateProject.ProjectRootPath!);
96-
Assert.True(DotnetCli($"test -c {_buildConfiguration} -f {_buildTargetFramework} \"{clonedTemplateProject.ProjectRootPath}\" --collect:\"XPlat Code Coverage\" --settings \"{runSettingsPath}\" --diag:{Path.Combine(clonedTemplateProject.ProjectRootPath, "log.txt")}", out string standardOutput, out string standardError), standardOutput);
97+
Assert.Equal((int)CommandExitCodes.Success, DotnetCli($"test -c {_buildConfiguration} -f {_buildTargetFramework} \"{clonedTemplateProject.ProjectRootPath}\" --collect:\"XPlat Code Coverage\" --settings \"{runSettingsPath}\" --diag:{Path.Combine(clonedTemplateProject.ProjectRootPath, "log.txt")}", out string standardOutput, out string standardError));
9798
Assert.Contains("Passed!", standardOutput);
9899
AssertCoverage(clonedTemplateProject);
99100
AssertCollectorsInjection(clonedTemplateProject);
@@ -104,10 +105,10 @@ public void TestVsTest_VsTest()
104105
{
105106
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject();
106107
string runSettingsPath = AddCollectorRunsettingsFile(clonedTemplateProject.ProjectRootPath!);
107-
Assert.True(DotnetCli($"publish -c {_buildConfiguration} -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError), standardOutput);
108+
Assert.Equal((int)CommandExitCodes.Success, DotnetCli($"publish -c {_buildConfiguration} -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError));
108109
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => f.Contains("publish"));
109110
Assert.NotNull(publishedTestFile);
110-
Assert.True(DotnetCli($"vstest \"{publishedTestFile}\" --collect:\"XPlat Code Coverage\" --diag:{Path.Combine(clonedTemplateProject.ProjectRootPath, "log.txt")}", out standardOutput, out standardError), standardOutput);
111+
Assert.Equal((int)CommandExitCodes.Success, DotnetCli($"vstest \"{publishedTestFile}\" --collect:\"XPlat Code Coverage\" --diag:{Path.Combine(clonedTemplateProject.ProjectRootPath, "log.txt")}", out standardOutput, out standardError));
111112
// We don't have any result to check because tests and code to instrument are in same assembly so we need to pass
112113
// IncludeTestAssembly=true we do it in other test
113114
Assert.Contains("Passed!", standardOutput);
@@ -119,10 +120,10 @@ public void TestVsTest_VsTest_Settings()
119120
{
120121
using ClonedTemplateProject clonedTemplateProject = PrepareTemplateProject();
121122
string runSettingsPath = AddCollectorRunsettingsFile(clonedTemplateProject.ProjectRootPath!);
122-
Assert.True(DotnetCli($"publish -c {_buildConfiguration} -f {_buildTargetFramework} \"{clonedTemplateProject.ProjectRootPath}\"", out string standardOutput, out string standardError), standardOutput);
123+
Assert.Equal((int)CommandExitCodes.Success, DotnetCli($"publish -c {_buildConfiguration} -f {_buildTargetFramework} \"{clonedTemplateProject.ProjectRootPath}\"", out string standardOutput, out string standardError));
123124
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => f.Contains("publish"));
124125
Assert.NotNull(publishedTestFile);
125-
Assert.True(DotnetCli($"vstest \"{publishedTestFile}\" --collect:\"XPlat Code Coverage\" --ResultsDirectory:\"{clonedTemplateProject.ProjectRootPath}\" /settings:\"{runSettingsPath}\" --diag:{Path.Combine(clonedTemplateProject.ProjectRootPath, "log.txt")}", out standardOutput, out standardError), standardOutput);
126+
Assert.Equal((int)CommandExitCodes.Success, DotnetCli($"vstest \"{publishedTestFile}\" --collect:\"XPlat Code Coverage\" --ResultsDirectory:\"{clonedTemplateProject.ProjectRootPath}\" /settings:\"{runSettingsPath}\" --diag:{Path.Combine(clonedTemplateProject.ProjectRootPath, "log.txt")}", out standardOutput, out standardError));
126127
Assert.Contains("Passed!", standardOutput);
127128
AssertCoverage(clonedTemplateProject);
128129
AssertCollectorsInjection(clonedTemplateProject);

test/coverlet.integration.tests/DotnetTool.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public DotnetGlobalTools(ITestOutputHelper output)
2020
}
2121
private string InstallTool(string projectPath)
2222
{
23-
_ = DotnetCli($"tool install coverlet.console --version {GetPackageVersion("*console*.nupkg")} --tool-path \"{Path.Combine(projectPath, "coverletTool")}\"", out string standardOutput, out _, projectPath);
23+
_ = DotnetCli($"tool install coverlet.console --version {GetPackageVersion("*console*.nupkg")} --tool-path \"{Path.Combine(projectPath, "coverletTool")}\"", out string standardOutput, out string standardError, projectPath);
2424
Assert.Contains("was successfully installed.", standardOutput);
25+
Assert.Empty(standardError);
2526
return Path.Combine(projectPath, "coverletTool", "coverlet");
2627
}
2728

@@ -71,7 +72,7 @@ public void StandAloneThreshold()
7172
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
7273
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError);
7374
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 \"{outputPath}\"", out standardOutput, out standardError));
75+
int cmdExitCode = RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --output \"{outputPath}\"", out standardOutput, out standardError);
7576
if (!string.IsNullOrEmpty(standardError))
7677
{
7778
_output.WriteLine(standardError);
@@ -84,8 +85,10 @@ public void StandAloneThreshold()
8485
Assert.Contains("Hello World!", standardOutput);
8586
Assert.True(File.Exists(outputPath));
8687
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
87-
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
88-
Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
88+
Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
89+
// this messages are now in stderr available but standardError stream is empty in test environment
90+
//Assert.Contains("The minimum line coverage is below the specified 80", standardError);
91+
//Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
8992
}
9093

9194
[Fact]
@@ -97,7 +100,7 @@ public void StandAloneThresholdLine()
97100
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
98101
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError);
99102
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
100-
Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --output \"{outputPath}\"", out standardOutput, out standardError));
103+
int cmdExitCode = RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --output \"{outputPath}\"", out standardOutput, out standardError);
101104
if (!string.IsNullOrEmpty(standardError))
102105
{
103106
_output.WriteLine(standardError);
@@ -107,9 +110,10 @@ public void StandAloneThresholdLine()
107110
// make standard output available in trx file
108111
_output.WriteLine(standardOutput);
109112
}
110-
Assert.Contains("Hello World!", standardOutput);
113+
// Assert.Contains("Hello World!", standardOutput);
111114
Assert.True(File.Exists(outputPath));
112115
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
116+
Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
113117
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
114118
Assert.DoesNotContain("The minimum method coverage is below the specified 80", standardOutput);
115119
}
@@ -123,7 +127,7 @@ public void StandAloneThresholdLineAndMethod()
123127
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
124128
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError);
125129
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
126-
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));
130+
int cmdExitCode = RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --threshold-type method --output \"{outputPath}\"", out standardOutput, out standardError);
127131
if (!string.IsNullOrEmpty(standardError))
128132
{
129133
_output.WriteLine(standardError);
@@ -133,9 +137,10 @@ public void StandAloneThresholdLineAndMethod()
133137
// make standard output available in trx file
134138
_output.WriteLine(standardOutput);
135139
}
136-
Assert.Contains("Hello World!", standardOutput);
140+
// Assert.Contains("Hello World!", standardOutput);
137141
Assert.True(File.Exists(outputPath));
138142
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
143+
Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
139144
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
140145
Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
141146
}

test/coverlet.integration.tests/coverlet.integration.tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
12+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
1213
<PackageReference Include="Moq" Version="4.20.70" />
1314
<PackageReference Include="NuGet.Packaging" Version="6.6.2" />
1415
<PackageReference Include="xunit.v3" Version="0.6.0-pre.7" />
@@ -23,6 +24,7 @@
2324

2425
<ItemGroup>
2526
<ProjectReference Include="$(RepoRoot)src\coverlet.core\coverlet.core.csproj" />
27+
<ProjectReference Include="$(RepoRoot)src\coverlet.console\coverlet.console.csproj" />
2628
<ProjectReference Include="$(RepoRoot)test\coverlet.tests.utils\coverlet.tests.utils.csproj" />
2729
</ItemGroup>
2830

0 commit comments

Comments
 (0)