From 440c0c0b5afe0518a9a97a382a61410a73b48169 Mon Sep 17 00:00:00 2001 From: Vishnu Kumar Date: Wed, 15 May 2019 23:59:22 +0530 Subject: [PATCH 1/4] Different exit codes for coverlet process to indicate particular error if any. --- src/coverlet.console/Program.cs | 49 ++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/coverlet.console/Program.cs b/src/coverlet.console/Program.cs index 6fb305488..c24676b0a 100644 --- a/src/coverlet.console/Program.cs +++ b/src/coverlet.console/Program.cs @@ -15,6 +15,42 @@ namespace Coverlet.Console { class Program { + /// + /// Exit Codes returned from Coverlet console process. + /// + enum CommandExitCodes + { + /// + /// Indicates successful run of dotnet test without any test failure and coverage percentage above threshold if provided. + /// + Success = 0, + + /// + /// Indicates test failure by dotnet test. + /// + TestFailed = 1, + + /// + /// Indicates coverage percentage is below given threshold for one or more threshold type. + /// + CoverageBelowThreshold = 2, + + /// + /// Indicates test failure by dotnet test and coverage percentage is below given threshold for one or more threshold type. + /// + TestFailedAndCoverageBelowThreshold = TestFailed + CoverageBelowThreshold, + + /// + /// Indicates exception occurred during Coverlet process. + /// + Exception = 101, + + /// + /// Indicates missing options or empty arguments for Coverlet process. + /// + CommandParsingException = 102 + } + static int Main(string[] args) { var logger = new ConsoleLogger(); @@ -23,6 +59,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 = 0; CommandArgument module = app.Argument("", "Path to the test assembly."); CommandOption target = app.Option("-t|--target", "Path to the test runner application.", CommandOptionType.SingleValue); @@ -185,10 +222,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) { @@ -208,7 +249,7 @@ static int Main(string[] args) throw new Exception(exceptionMessageBuilder.ToString()); } - return process.ExitCode == 0 ? 0 : process.ExitCode; + return exitCode; }); try @@ -219,12 +260,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; } } From f0e612760c0e4e26083aa334cc265daf1b6137f3 Mon Sep 17 00:00:00 2001 From: Vishnu Kumar Date: Tue, 28 May 2019 22:25:15 +0530 Subject: [PATCH 2/4] ExitCodes in a separate file and using [Flags] attribute on Enum. --- src/coverlet.console/ExitCodes.cs | 34 ++++++++++++++++++++++++++ src/coverlet.console/Program.cs | 40 ++----------------------------- 2 files changed, 36 insertions(+), 38 deletions(-) create mode 100644 src/coverlet.console/ExitCodes.cs diff --git a/src/coverlet.console/ExitCodes.cs b/src/coverlet.console/ExitCodes.cs new file mode 100644 index 000000000..2677b3f19 --- /dev/null +++ b/src/coverlet.console/ExitCodes.cs @@ -0,0 +1,34 @@ +using System; + +/// +/// Exit Codes returned from Coverlet console process. +/// +[Flags] +internal enum CommandExitCodes +{ + /// + /// Indicates successful run of dotnet test without any test failure and coverage percentage above threshold if provided. + /// + Success = 0, + + /// + /// Indicates test failure by dotnet test. + /// + TestFailed = 1, + + /// + /// Indicates coverage percentage is below given threshold for one or more threshold type. + /// + CoverageBelowThreshold = 2, + + /// + /// Indicates exception occurred during Coverlet process. + /// + Exception = 101, + + /// + /// Indicates missing options or empty arguments for Coverlet process. + /// + CommandParsingException = 102 +} + diff --git a/src/coverlet.console/Program.cs b/src/coverlet.console/Program.cs index c24676b0a..94be64519 100644 --- a/src/coverlet.console/Program.cs +++ b/src/coverlet.console/Program.cs @@ -14,43 +14,7 @@ namespace Coverlet.Console { class Program - { - /// - /// Exit Codes returned from Coverlet console process. - /// - enum CommandExitCodes - { - /// - /// Indicates successful run of dotnet test without any test failure and coverage percentage above threshold if provided. - /// - Success = 0, - - /// - /// Indicates test failure by dotnet test. - /// - TestFailed = 1, - - /// - /// Indicates coverage percentage is below given threshold for one or more threshold type. - /// - CoverageBelowThreshold = 2, - - /// - /// Indicates test failure by dotnet test and coverage percentage is below given threshold for one or more threshold type. - /// - TestFailedAndCoverageBelowThreshold = TestFailed + CoverageBelowThreshold, - - /// - /// Indicates exception occurred during Coverlet process. - /// - Exception = 101, - - /// - /// Indicates missing options or empty arguments for Coverlet process. - /// - CommandParsingException = 102 - } - + { static int Main(string[] args) { var logger = new ConsoleLogger(); @@ -59,7 +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 = 0; + int exitCode = (int)CommandExitCodes.Success; CommandArgument module = app.Argument("", "Path to the test assembly."); CommandOption target = app.Option("-t|--target", "Path to the test runner application.", CommandOptionType.SingleValue); From 4c01ec2eed9d70ddc093443f472c0206eafc865b Mon Sep 17 00:00:00 2001 From: Vishnu Kumar Date: Wed, 29 May 2019 20:11:14 +0530 Subject: [PATCH 3/4] Adding up the enum flag values for exit code aggregation always after initial assignment. Co-Authored-By: Marco Rossignoli --- src/coverlet.console/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coverlet.console/Program.cs b/src/coverlet.console/Program.cs index 94be64519..814485aa2 100644 --- a/src/coverlet.console/Program.cs +++ b/src/coverlet.console/Program.cs @@ -188,7 +188,7 @@ static int Main(string[] args) logger.LogInformation(coverageTable.ToStringAlternative()); if (process.ExitCode > 0) { - exitCode = (int)CommandExitCodes.TestFailed; + exitCode += (int)CommandExitCodes.TestFailed; } thresholdTypeFlags = result.GetThresholdTypesBelowThreshold(summary, dThreshold, thresholdTypeFlags, dThresholdStat); if (thresholdTypeFlags != ThresholdTypeFlags.None) From a6ddede4b8bab29009199796f4a124f08716abe5 Mon Sep 17 00:00:00 2001 From: Vishnu Kumar Date: Thu, 27 Jun 2019 22:05:07 +0530 Subject: [PATCH 4/4] Fix formating - empty space --- src/coverlet.console/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coverlet.console/Program.cs b/src/coverlet.console/Program.cs index 814485aa2..e0635a43c 100644 --- a/src/coverlet.console/Program.cs +++ b/src/coverlet.console/Program.cs @@ -14,7 +14,7 @@ namespace Coverlet.Console { class Program - { + { static int Main(string[] args) { var logger = new ConsoleLogger();