Skip to content

Commit afeb751

Browse files
committed
set exit code according ExitCodes.cs
1 parent 47cdd27 commit afeb751

File tree

12 files changed

+60
-55
lines changed

12 files changed

+60
-55
lines changed

Directory.Packages.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@
5454
<PackageVersion Include="Tmds.ExecFunction" Version="0.8.0" />
5555
<PackageVersion Include="xunit.v3" Version="$(XunitV3Version)" />
5656
<PackageVersion Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualstudioVersion)" />
57-
<PackageVersion Include="System.Buffers" Version="4.6.0" />
57+
<PackageVersion Include="System.Buffers" Version="4.6.1" />
5858
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
5959
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
6060
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
61-
<PackageVersion Include="System.Memory" Version="4.6.0" />
61+
<PackageVersion Include="System.Memory" Version="4.6.2" />
6262
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
6363
<PackageVersion Include="System.Reflection.Metadata" Version="8.0.1" />
64-
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.0" />
64+
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.1" />
6565
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="6.0.5" />
6666
<PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0" />
6767
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
6868
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
69-
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.0" />
69+
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.2" />
7070
</ItemGroup>
7171
</Project>

Documentation/GlobalTool.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,4 @@ Coverlet outputs specific exit codes to better support build automation systems
275275
2 - Coverage percentage is below threshold.
276276
3 - Test fails and also coverage percentage is below threshold.
277277
101 - General exception occurred during coverlet process.
278-
102 - Missing options or invalid arguments for coverlet process.
279278
```

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "8.0.113"
3+
"version": "8.0.114"
44
}
55
}

src/coverlet.collector/coverlet.collector.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<Authors>tonerdo</Authors>
2828
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2929
<PackageProjectUrl>https://github.com/coverlet-coverage/coverlet</PackageProjectUrl>
30-
<PackageIconUrl>https://raw.githubusercontent.com/tonerdo/coverlet/master/_assets/coverlet-icon.svg?sanitize=true</PackageIconUrl>
3130
<PackageIcon>coverlet-icon.png</PackageIcon>
3231
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
3332
<Description>Coverlet is a cross platform code coverage library for .NET, with support for line, branch and method coverage.</Description>

src/coverlet.console/ExitCodes.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,5 @@ internal enum CommandExitCodes
2828
/// Indicates exception occurred during Coverlet process.
2929
/// </summary>
3030
Exception = 101,
31-
32-
/// <summary>
33-
/// Indicates missing options or empty arguments for Coverlet process.
34-
/// </summary>
35-
CommandParsingException = 102
3631
}
3732

src/coverlet.console/Program.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace Coverlet.Console
2525
{
2626
public static class Program
2727
{
28+
static int s_exitCode;
2829
static int Main(string[] args)
2930
{
3031
var moduleOrAppDirectory = new Argument<string>("path", "Path to the test assembly or application directory.");
@@ -175,7 +176,7 @@ string sourceMappingFile
175176

176177
// Adjust log level based on user input.
177178
logger.Level = verbosity;
178-
int exitCode = (int)CommandExitCodes.Success;
179+
s_exitCode = (int)CommandExitCodes.Success;
179180

180181
try
181182
{
@@ -357,44 +358,44 @@ string sourceMappingFile
357358
logger.LogInformation(coverageTable.ToStringAlternative());
358359
if (process.ExitCode > 0)
359360
{
360-
exitCode += (int)CommandExitCodes.TestFailed;
361+
s_exitCode = (int)CommandExitCodes.TestFailed;
361362
}
362363

363364
ThresholdTypeFlags thresholdTypeFlags = result.GetThresholdTypesBelowThreshold(thresholdTypeFlagValues, thresholdStat);
364365
if (thresholdTypeFlags != ThresholdTypeFlags.None)
365366
{
366-
exitCode += (int)CommandExitCodes.CoverageBelowThreshold;
367-
var exceptionMessageBuilder = new StringBuilder();
367+
s_exitCode = (int)CommandExitCodes.CoverageBelowThreshold;
368+
var errorMessageBuilder = new StringBuilder();
368369
if ((thresholdTypeFlags & ThresholdTypeFlags.Line) != ThresholdTypeFlags.None)
369370
{
370-
exceptionMessageBuilder.AppendLine($"The {thresholdStat.ToString().ToLower()} line coverage is below the specified {thresholdTypeFlagValues[ThresholdTypeFlags.Line]}");
371+
errorMessageBuilder.AppendLine($"The {thresholdStat.ToString().ToLower()} line coverage is below the specified {thresholdTypeFlagValues[ThresholdTypeFlags.Line]}");
371372
}
372373

373374
if ((thresholdTypeFlags & ThresholdTypeFlags.Branch) != ThresholdTypeFlags.None)
374375
{
375-
exceptionMessageBuilder.AppendLine($"The {thresholdStat.ToString().ToLower()} branch coverage is below the specified {thresholdTypeFlagValues[ThresholdTypeFlags.Branch]}");
376+
errorMessageBuilder.AppendLine($"The {thresholdStat.ToString().ToLower()} branch coverage is below the specified {thresholdTypeFlagValues[ThresholdTypeFlags.Branch]}");
376377
}
377378

378379
if ((thresholdTypeFlags & ThresholdTypeFlags.Method) != ThresholdTypeFlags.None)
379380
{
380-
exceptionMessageBuilder.AppendLine($"The {thresholdStat.ToString().ToLower()} method coverage is below the specified {thresholdTypeFlagValues[ThresholdTypeFlags.Method]}");
381+
errorMessageBuilder.AppendLine($"The {thresholdStat.ToString().ToLower()} method coverage is below the specified {thresholdTypeFlagValues[ThresholdTypeFlags.Method]}");
381382
}
382-
throw new InvalidOperationException(exceptionMessageBuilder.ToString());
383+
logger.LogError(errorMessageBuilder.ToString());
383384
}
384385

385-
return Task.FromResult(exitCode);
386+
return Task.FromResult(s_exitCode);
386387

387388
}
388389

389390
catch (Win32Exception we) when (we.Source == "System.Diagnostics.Process")
390391
{
391392
logger.LogError($"Start process '{target}' failed with '{we.Message}'");
392-
return Task.FromResult(exitCode > 0 ? exitCode : (int)CommandExitCodes.Exception);
393+
return Task.FromResult(s_exitCode > 0 ? s_exitCode : (int)CommandExitCodes.Exception);
393394
}
394395
catch (Exception ex)
395396
{
396397
logger.LogError(ex.Message);
397-
return Task.FromResult(exitCode > 0 ? exitCode : (int)CommandExitCodes.Exception);
398+
return Task.FromResult(s_exitCode > 0 ? s_exitCode : (int)CommandExitCodes.Exception);
398399
}
399400

400401
}

src/coverlet.console/coverlet.console.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<PackageTags>coverage;testing;unit-test;lcov;opencover;quality</PackageTags>
1717
<PackageReadmeFile>GlobalTool.md</PackageReadmeFile>
1818
<PackageReleaseNotes>https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/Changelog.md</PackageReleaseNotes>
19-
<PackageIconUrl>https://raw.githubusercontent.com/tonerdo/coverlet/master/_assets/coverlet-icon.svg?sanitize=true</PackageIconUrl>
2019
<PackageIcon>coverlet-icon.png</PackageIcon>
2120
<PackageProjectUrl>https://github.com/coverlet-coverage/coverlet</PackageProjectUrl>
2221
<PackageLicenseExpression>MIT</PackageLicenseExpression>

src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<Authors>tonerdo</Authors>
2929
<PackageLicenseExpression>MIT</PackageLicenseExpression>
3030
<PackageProjectUrl>https://github.com/coverlet-coverage/coverlet</PackageProjectUrl>
31-
<PackageIconUrl>https://raw.githubusercontent.com/tonerdo/coverlet/master/_assets/coverlet-icon.svg?sanitize=true</PackageIconUrl>
3231
<PackageIcon>coverlet-icon.png</PackageIcon>
3332
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
3433
<DevelopmentDependency>true</DevelopmentDependency>
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
namespace Coverlet.Integration.Template
1+
namespace Coverlet.Integration.Template
22
{
3-
public class DeepThought
3+
public class DeepThought
4+
{
5+
public int AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()
46
{
5-
public int AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()
6-
{
7-
return 42;
8-
}
7+
return 42;
98
}
9+
10+
// This method is not covered by any test
11+
// It is here to demonstrate how Coverlet will report on untested code
12+
// required for Coverlet.Integration.Tests.DotnetGlobalTools.StandAloneThreshold
13+
// required for Coverlet.Integration.Tests.DotnetGlobalTools.DotnetToolThreshold
14+
public void TheUntestedMethod()
15+
{
16+
#pragma warning disable CS0219 // Variable is assigned but its value is never used
17+
string s = "this will never be covered by any test";
18+
#pragma warning restore CS0219 // Variable is assigned but its value is never used
19+
}
20+
}
1021
}

test/coverlet.integration.tests/DotnetTool.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ public void DotnetTool()
3535
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
3636
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string buildOutput, out string buildError);
3737
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
38-
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);
38+
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);
3939
if (!string.IsNullOrEmpty(standardError))
4040
{
4141
_output.WriteLine(standardError);
4242
}
4343
Assert.Contains("Passed!", standardOutput);
4444
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
45+
Assert.Equal((int)CommandExitCodes.Success, cmdExitCode);
4546
}
4647

4748
[Fact]
@@ -53,14 +54,15 @@ public void StandAlone()
5354
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
5455
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string buildOutput, out string buildError);
5556
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
56-
RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --output \"{outputPath}\"", out string standardOutput, out string standardError);
57+
int cmdExitCode = RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --output \"{outputPath}\"", out string standardOutput, out string standardError);
5758
if (!string.IsNullOrEmpty(standardError))
5859
{
5960
_output.WriteLine(standardError);
6061
}
6162
//Assert.Contains("Hello World!", standardOutput);
6263
Assert.True(File.Exists(outputPath));
6364
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
65+
Assert.Equal((int)CommandExitCodes.Success, cmdExitCode);
6466
}
6567

6668
[Fact]
@@ -85,10 +87,9 @@ public void StandAloneThreshold()
8587
//Assert.Contains("Hello World!", standardOutput);
8688
Assert.True(File.Exists(outputPath));
8789
AssertCoverage(clonedTemplateProject, standardOutput: 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);
90+
Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
91+
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
92+
Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
9293
}
9394

9495
[Fact]
@@ -113,9 +114,9 @@ public void StandAloneThresholdLine()
113114
// Assert.Contains("Hello World!", standardOutput);
114115
Assert.True(File.Exists(outputPath));
115116
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
116-
//Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
117-
//Assert.Contains("The minimum line coverage is below the specified 80", standardError);
118-
//Assert.DoesNotContain("The minimum method coverage is below the specified 80", standardOutput);
117+
Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
118+
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
119+
Assert.DoesNotContain("The minimum method coverage is below the specified 80", standardOutput);
119120
}
120121

121122
[Fact]
@@ -140,9 +141,9 @@ public void StandAloneThresholdLineAndMethod()
140141
// Assert.Contains("Hello World!", standardOutput);
141142
Assert.True(File.Exists(outputPath));
142143
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
143-
//Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
144-
//Assert.Contains("The minimum line coverage is below the specified 80", standardError);
145-
//Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
144+
Assert.Equal((int)CommandExitCodes.CoverageBelowThreshold, cmdExitCode);
145+
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
146+
Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
146147
}
147148
}
148149
}

0 commit comments

Comments
 (0)