public void OutofMemory() { var exception = new OutOfMemoryException(); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.OutofMemory, observedExitCode); }
public void InvalidData() { var exception = new InvalidDataException(); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.InvalidData, observedExitCode); }
public void CallNotImplemented() { var exception = new NotImplementedException(); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.CallNotImplemented, observedExitCode); }
public void FileNotFound() { var exception = new FileNotFoundException(); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.FileNotFound, observedExitCode); }
public void BadArguments() { var exception = new ArgumentNullException(); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.BadArguments, observedExitCode); }
public void BadFormat() { var exception = new FormatException(); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.BadFormat, observedExitCode); }
public void UserError() { var exception = new UserErrorException("user error"); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.UserError, observedExitCode); }
public void SharingViolation() { var exception = new ProcessLockedFileException("locked file"); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.SharingViolation, observedExitCode); }
public void AccessDenied() { var exception = new UnauthorizedAccessException(); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.AccessDenied, observedExitCode); }
public void InvalidFileFormat() { var exception = new InvalidFileFormatException("invalid format"); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.InvalidFileFormat, observedExitCode); }
public void FileNotSorted() { var exception = new FileNotSortedException("not sorted"); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.FileNotSorted, observedExitCode); }
public void MissingCompressionLibrary() { var exception = new MissingCompressionLibraryException("compression file"); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.MissingCompressionLibrary, observedExitCode); }
public void ShowException_UnknownException_ExitCode_ShouldBeOne() { var unknownException = new AbandonedMutexException(); var exitCode = ExitCodeUtilities.ShowException(unknownException); Assert.Equal(ExitCodes.InvalidFunction, exitCode); }
protected void ParseCommandLine(string[] args) { try { _commandLineOps["version"] = new TopLevelOption("displays the version", null); string command = null; Func <string, string[], int> commandMethod = null; string unsupportedOp = null; if (args == null || args.Length == 0) { SetExitCode(ExitCodes.MissingCommandLineOption); _showHelpMenu = true; } else { command = args[0].ToLower(); if (command == "version") { _showVersion = true; } commandMethod = GetCommandMethod(command); if (commandMethod == null) { unsupportedOp = command; } } if (_showVersion) { Console.WriteLine("{0} {1}", _versionProvider.GetProgramVersion(), _versionProvider.GetDataVersion()); SetExitCode(ExitCodes.Success); } else { if (_showHelpMenu) { CommandLineUtilities.DisplayBanner(_programAuthors); ShowHelpMenu(unsupportedOp); } else { if (FoundParsingErrors()) { return; } if (commandMethod != null) { ExitCode = commandMethod(command, args.Skip(1).ToArray()); } } } } catch (Exception e) { ExitCode = ExitCodeUtilities.ShowException(e); } }
public void ShowException_CompressionException_CheckExitCode() { var compressionException = new CompressionException("test"); compressionException.Data[ExitCodeUtilities.VcfLine] = "chr1\t100\tA\tC"; var exitCode = ExitCodeUtilities.ShowException(compressionException); Assert.Equal(ExitCodes.Compression, exitCode); }
public void ShowException_AggregateException_ExitCode_ShouldBeOne() { // TODO: It would be great to verify which exception was shown var refNullException = new NullReferenceException(); var aggregateException = new AggregateException(refNullException); var exitCode = ExitCodeUtilities.ShowException(aggregateException); Assert.Equal(ExitCodes.InvalidFunction, exitCode); }
public void InvalidFunction() { var exception = new GeneralException(""); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.InvalidFunction, observedExitCode); var exception2 = new Exception(); observedExitCode = ExitCodeUtilities.ShowException(exception2); Assert.Equal((int)ExitCodes.InvalidFunction, observedExitCode); var exception3 = new InvalidOperationException(); observedExitCode = ExitCodeUtilities.ShowException(exception3); Assert.Equal((int)ExitCodes.InvalidFunction, observedExitCode); }
/// <summary> /// executes the command-line workflow /// </summary> public void Execute(string[] args) { var bench = new Benchmark(); try { List <string> unsupportedOps = null; if (args == null || args.Length == 0) { SetExitCode(ExitCodes.MissingCommandLineOption); _showHelpMenu = true; } else { try { unsupportedOps = _commandLineOps.Parse(args); if (unsupportedOps.Count > 0) { SetExitCode(ExitCodes.UnknownCommandLineOption); _showHelpMenu = true; } } catch (OptionException oe) { _errorBuilder.AppendFormat("{0}ERROR: {1}\n", _errorSpacer, oe.Message); SetExitCode(ExitCodes.UnknownCommandLineOption); _showHelpMenu = true; } } if (_showVersion) { Console.WriteLine("{0} {1}", _versionProvider.GetProgramVersion(), _versionProvider.GetDataVersion()); SetExitCode(ExitCodes.Success); } else { if (!Console.IsOutputRedirected) { CommandLineUtilities.DisplayBanner(_programAuthors); } if (_showHelpMenu) { Help.Show(_commandLineOps, _commandLineExample, _programDescription); CommandLineUtilities.ShowUnsupportedOptions(unsupportedOps); Console.WriteLine(); Console.WriteLine(_versionProvider.GetDataVersion()); Console.WriteLine(); // print the errors if any were found if (FoundParsingErrors()) { return; } } else { ValidateCommandLine(); // print the errors if any were found if (FoundParsingErrors()) { return; } ProgramExecution(); } } } catch (Exception e) { ExitCode = ExitCodeUtilities.ShowException(e); } _peakMemoryUsageBytes = MemoryUtilities.GetPeakMemoryUsage(); _wallTimeSpan = bench.GetElapsedTime(); if (!_showVersion && !_showHelpMenu && !Console.IsOutputRedirected) { Console.WriteLine(); if (_peakMemoryUsageBytes > 0) { Console.WriteLine("Peak memory usage: {0}", MemoryUtilities.ToHumanReadable(_peakMemoryUsageBytes)); } Console.WriteLine("Time: {0}", Benchmark.ToHumanReadable(_wallTimeSpan)); } }