Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/coverlet.console/ExitCodes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;

/// <summary>
/// Exit Codes returned from Coverlet console process.
/// </summary>
[Flags]
internal enum CommandExitCodes
{
/// <summary>
/// Indicates successful run of dotnet test without any test failure and coverage percentage above threshold if provided.
/// </summary>
Success = 0,

/// <summary>
/// Indicates test failure by dotnet test.
/// </summary>
TestFailed = 1,

/// <summary>
/// Indicates coverage percentage is below given threshold for one or more threshold type.
/// </summary>
CoverageBelowThreshold = 2,

/// <summary>
/// Indicates exception occurred during Coverlet process.
/// </summary>
Exception = 101,

/// <summary>
/// Indicates missing options or empty arguments for Coverlet process.
/// </summary>
CommandParsingException = 102
}

13 changes: 9 additions & 4 deletions src/coverlet.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static int Main(string[] args)
app.FullName = "Cross platform .NET Core code coverage tool";
app.HelpOption("-h|--help");
app.VersionOption("-v|--version", GetAssemblyVersion());
int exitCode = (int)CommandExitCodes.Success;

CommandArgument module = app.Argument("<ASSEMBLY>", "Path to the test assembly.");
CommandOption target = app.Option("-t|--target", "Path to the test runner application.", CommandOptionType.SingleValue);
Expand Down Expand Up @@ -185,10 +186,14 @@ static int Main(string[] args)
coverageTable.AddRow("Average", $"{totalLinePercent / numModules}%", $"{totalBranchPercent / numModules}%", $"{totalMethodPercent / numModules}%");

logger.LogInformation(coverageTable.ToStringAlternative());

if (process.ExitCode > 0)
{
exitCode += (int)CommandExitCodes.TestFailed;
}
thresholdTypeFlags = result.GetThresholdTypesBelowThreshold(summary, dThreshold, thresholdTypeFlags, dThresholdStat);
if (thresholdTypeFlags != ThresholdTypeFlags.None)
{
exitCode += (int)CommandExitCodes.CoverageBelowThreshold;
var exceptionMessageBuilder = new StringBuilder();
if ((thresholdTypeFlags & ThresholdTypeFlags.Line) != ThresholdTypeFlags.None)
{
Expand All @@ -208,7 +213,7 @@ static int Main(string[] args)
throw new Exception(exceptionMessageBuilder.ToString());
}

return process.ExitCode == 0 ? 0 : process.ExitCode;
return exitCode;
});

try
Expand All @@ -219,12 +224,12 @@ static int Main(string[] args)
{
logger.LogError(ex.Message);
app.ShowHelp();
return 1;
return (int)CommandExitCodes.CommandParsingException;
}
catch (Exception ex)
{
logger.LogError(ex.Message);
return 1;
return exitCode > 0 ? exitCode : (int)CommandExitCodes.Exception;
}
}

Expand Down