Beispiel #1
0
        public void OutofMemory()
        {
            var exception        = new OutOfMemoryException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.OutofMemory, observedExitCode);
        }
Beispiel #2
0
        public void InvalidData()
        {
            var exception        = new InvalidDataException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.InvalidData, observedExitCode);
        }
Beispiel #3
0
        public void CallNotImplemented()
        {
            var exception        = new NotImplementedException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.CallNotImplemented, observedExitCode);
        }
Beispiel #4
0
        public void FileNotFound()
        {
            var exception        = new FileNotFoundException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.FileNotFound, observedExitCode);
        }
Beispiel #5
0
        public void BadArguments()
        {
            var exception        = new ArgumentNullException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.BadArguments, observedExitCode);
        }
Beispiel #6
0
        public void BadFormat()
        {
            var exception        = new FormatException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.BadFormat, observedExitCode);
        }
Beispiel #7
0
        public void UserError()
        {
            var exception        = new UserErrorException("user error");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.UserError, observedExitCode);
        }
Beispiel #8
0
        public void SharingViolation()
        {
            var exception        = new ProcessLockedFileException("locked file");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.SharingViolation, observedExitCode);
        }
Beispiel #9
0
        public void AccessDenied()
        {
            var exception        = new UnauthorizedAccessException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.AccessDenied, observedExitCode);
        }
Beispiel #10
0
        public void InvalidFileFormat()
        {
            var exception        = new InvalidFileFormatException("invalid format");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.InvalidFileFormat, observedExitCode);
        }
Beispiel #11
0
        public void FileNotSorted()
        {
            var exception        = new FileNotSortedException("not sorted");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.FileNotSorted, observedExitCode);
        }
Beispiel #12
0
        public void MissingCompressionLibrary()
        {
            var exception        = new MissingCompressionLibraryException("compression file");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.MissingCompressionLibrary, observedExitCode);
        }
Beispiel #13
0
        public void ShowException_UnknownException_ExitCode_ShouldBeOne()
        {
            var unknownException = new AbandonedMutexException();
            var exitCode         = ExitCodeUtilities.ShowException(unknownException);

            Assert.Equal(ExitCodes.InvalidFunction, exitCode);
        }
Beispiel #14
0
        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);
 }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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));
            }
        }