Skip to content

Commit

Permalink
Fix #22
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérémie Bertrand committed Aug 30, 2016
1 parent d0392be commit 59b3e01
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 19 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ It is possible to process several reports at the same time: `NVika parsereport r
- `--debug`: active the debug category on logger, useful for debugging
- `--includesource`: include the report source name in messages

### exit codes:
- 0: OK
- 1: unknown error
- 2: report not found
- 3: exception during report loading
- 4: no parser found for the current report
- 5: issue(s) with error severity was found

## Analysis tools
### Supported
- [InspectCode](https://chocolatey.org/packages/resharper-clt): example of usage `inspectcode /o="inspectcodereport.xml" "Vika.sln"`
Expand Down
16 changes: 8 additions & 8 deletions src/NVika.Tests/ParseReportCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Execute_NonExistingReport_ShouldLogError_ReportNotFound()
var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

// assert
Assert.Equal(1, exitCode);
Assert.Equal(2, exitCode);
var logs = _loggerOutput.ToString();
Assert.Contains("The report \"report.xml\" was not found.", logs);
}
Expand All @@ -86,7 +86,7 @@ public void Execute_ExistingButEmptyReport_ShouldLogErrorOnLoad_DefaultBuildServ
var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

// assert
Assert.Equal(2, exitCode);
Assert.Equal(4, exitCode);
var logs = _loggerOutput.ToString();
Assert.Contains("\t- \"Local console\"", logs);
Assert.Contains("An exception happened when loading the report \"report.xml\"", logs);
Expand All @@ -109,7 +109,7 @@ public void Execute_ExistingBuEmptyReport_ShouldLogErrorOnLoad_MockBuildServerIs
var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

// assert
Assert.Equal(2, exitCode);
Assert.Equal(4, exitCode);
var logs = _loggerOutput.ToString();
Assert.Contains("\t- \"MockBuildServer\"", logs);
Assert.Contains("An exception happened when loading the report \"report.xml\"", logs);
Expand All @@ -132,7 +132,7 @@ public void Execute_NoParser_ShouldLogError()
var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

// assert
Assert.Equal(3, exitCode);
Assert.Equal(4, exitCode);
var logs = _loggerOutput.ToString();
Assert.Contains("The adequate parser for this report was not found. You are welcome to address us an issue.", logs);
}
Expand All @@ -154,7 +154,7 @@ public void Execute_ParserCantParse_ShouldLogError()
var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

// assert
Assert.Equal(3, exitCode);
Assert.Equal(4, exitCode);
var logs = _loggerOutput.ToString();
Assert.Contains("The adequate parser for this report was not found. You are welcome to address us an issue.", logs);
}
Expand All @@ -176,7 +176,7 @@ public void Execute_ParserCanParse_ShouldWriteMessageFromIssues()
var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

// assert
Assert.Equal(4, exitCode);
Assert.Equal(5, exitCode);
var logs = _loggerOutput.ToString();
Assert.Contains("Message1", logs);
Assert.Contains("Message2", logs);
Expand All @@ -200,7 +200,7 @@ public void Execute_ParserCanParse_WithDebug_ShouldWriteMessageFromIssuesAndWrit
var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

// assert
Assert.Equal(4, exitCode);
Assert.Equal(5, exitCode);
var logs = _loggerOutput.ToString();
Assert.Contains("Report path is \"report.xml\"", logs);
Assert.Contains("3 issues was found", logs);
Expand Down Expand Up @@ -278,7 +278,7 @@ public void Execute_MultipleReports_ShouldWriteMessageFromIssues()
var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

// assert
Assert.Equal(4, exitCode);
Assert.Equal(5, exitCode);
var logs = _loggerOutput.ToString();
Assert.Contains("3 issues was found", logs);
Assert.Contains("Message1", logs);
Expand Down
4 changes: 2 additions & 2 deletions src/NVika.Tests/ProgramTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Run_UnknownCommand_BuildServerIsDefaultCommand()

// assert
var consoleOutput = output.ToString();
Assert.Equal(1, exitCode);
Assert.Equal(2, exitCode);
Assert.Contains($"NVika V{Assembly.GetAssembly(typeof(Program)).GetName().Version}", consoleOutput);
Assert.Contains("Executing parsereport (Parse the report and show warnings in console or inject them to the build server):", consoleOutput);
Assert.Contains("The report unkowncommand was not found.", consoleOutput);
Expand All @@ -56,7 +56,7 @@ public void Run_BuildServer_NonExistingReport_ShouldLogErrorToConsole()

// assert
var consoleOutput = output.ToString();
Assert.Equal(1, exitCode);
Assert.Equal(2, exitCode);
Assert.Contains($"NVika V{Assembly.GetAssembly(typeof(Program)).GetName().Version}", consoleOutput);
Assert.Contains("The report nonexistingreport.abc was not found.", consoleOutput);
}
Expand Down
18 changes: 18 additions & 0 deletions src/NVika/ExitCodes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

namespace NVika
{
internal static class ExitCodes
{
internal const int OK = 0;

internal const int UnknownError = 1;

internal const int ReportNotFound = 2;

internal const int ExceptionDuringReportLoading = 3;

internal const int NoParserFoundForThisReport = 4;

internal const int IssuesWithErrorWasFound = 5;
}
}
1 change: 1 addition & 0 deletions src/NVika/NVika.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="Abstractions\HttpClientFactory.cs" />
<Compile Include="Abstractions\IEnvironment.cs" />
<Compile Include="Abstractions\IHttpClientFactory.cs" />
<Compile Include="ExitCodes.cs" />
<Compile Include="Properties\GlobalSuppressions.cs" />
<Compile Include="ParseReportCommand.cs" />
<Compile Include="BuildServers\AppVeyor.cs" />
Expand Down
11 changes: 6 additions & 5 deletions src/NVika/ParseReportCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ParseReportCommand(ILogger logger,

public override int Run(string[] reportPaths)
{
var returnCode = 0;
var returnCode = ExitCodes.OK;

if (reportPaths.Length == 0)
{
Expand Down Expand Up @@ -78,15 +78,15 @@ public override int Run(string[] reportPaths)
catch (Exception ex)
{
_logger.Error(ex, "An exception happened when loading the report {reportPath}", reportPath);
return 2;
return ExitCodes.ReportNotFound;
}

// Report type Detection
var parser = GetParser(report);
if (parser == null)
{
_logger.Error("The adequate parser for this report was not found. You are welcome to address us an issue.");
return 3;
return ExitCodes.NoParserFoundForThisReport;
}
_logger.Debug("Report type is {Name}", parser.Name);

Expand All @@ -101,9 +101,10 @@ public override int Run(string[] reportPaths)
}
}

if (returnCode == 0)
if (returnCode == ExitCodes.OK && issues.Any(i => i.Severity == IssueSeverity.Error))
{
returnCode = issues.Any(i => i.Severity == IssueSeverity.Error) ? 4 : 0;
returnCode = ExitCodes.IssuesWithErrorWasFound;
_logger.Fatal("Issues with severity error was found: the build will fail");
}
}
return returnCode;
Expand Down
6 changes: 3 additions & 3 deletions src/NVika/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ internal int Run(string[] args)
}
else
{
_logger.Error(exception, "An unexpected error occurred:");
_logger.Fatal(exception, "An unexpected error occurred:");
}
return 1;
return ExitCodes.UnknownError;
}
}

Expand Down Expand Up @@ -104,7 +104,7 @@ private void Compose()
}
catch (ReflectionTypeLoadException ex)
{
_logger.Error(ex, @"Unable to load: \r\n{0}", string.Join("\r\n", ex.LoaderExceptions.Select(e => e.Message)));
_logger.Error(@"Unable to load: \r\n{0}", string.Join("\r\n", ex.LoaderExceptions.Select(e => e.Message)));
throw;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Vika.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NVika", "NVika\NVika.csproj", "{70D378FE-426F-4854-A7E5-98EED3070EB6}"
EndProject
Expand All @@ -16,6 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\build.sh = ..\build.sh
CodeCoverage.runsettings = CodeCoverage.runsettings
..\NVikaHelper.fsx = ..\NVikaHelper.fsx
..\README.md = ..\README.md
EndProjectSection
EndProject
Global
Expand Down

0 comments on commit 59b3e01

Please sign in to comment.