Example #1
0
        /// <summary>
        /// Analyzes the arguments and displays an interface to the user. Kicks off the program.
        /// </summary>
        /// <param name="args">User input</param>
        public int Run(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name              = "Stryker",
                FullName          = "Stryker: Stryker mutator for .Net",
                Description       = "Stryker mutator for .Net",
                ExtendedHelpText  = "Welcome to Stryker for .Net! Run dotnet stryker to kick off a mutation test run",
                HelpTextGenerator = new GroupedHelpTextGenerator()
            };

            app.HelpOption();

            var inputs           = new StrykerInputs();
            var cmdConfigHandler = new CommandLineConfigHandler();

            cmdConfigHandler.RegisterCommandLineOptions(app, inputs);

            app.OnExecute(() =>
            {
                // app started
                PrintStrykerASCIIName();

                _configReader.Build(inputs, args, app, cmdConfigHandler);
                _loggingInitializer.SetupLogOptions(inputs);

                PrintStrykerVersionInformationAsync();
                RunStryker(inputs);
                return(ExitCode);
            });

            try
            {
                return(app.Execute(args));
            }
            catch (CommandParsingException ex)
            {
                Console.Error.WriteLine(ex.Message);

                if (ex is UnrecognizedCommandParsingException uex && uex.NearestMatches.Any())
                {
                    Console.Error.WriteLine();
                    Console.Error.WriteLine("Did you mean this?");
                    Console.Error.WriteLine("    " + uex.NearestMatches.First());
                }

                return(ExitCodes.OtherError);
            }
        }
        public void ShouldAddGitIgnore()
        {
            var fileSystemMock = new MockFileSystem();
            var basePath       = Directory.GetCurrentDirectory();
            var target         = new LoggingInitializer();

            var inputs = new StrykerInputs();

            inputs.BasePathInput.SuppliedInput = basePath;
            target.SetupLogOptions(inputs, fileSystemMock);

            var gitIgnoreFile = fileSystemMock.AllFiles.FirstOrDefault(x => x.EndsWith(Path.Combine("StrykerOutput", ".gitignore")));

            gitIgnoreFile.ShouldNotBeNull();
            var fileContents = fileSystemMock.GetFile(gitIgnoreFile).Contents;

            Encoding.Default.GetString(fileContents).ShouldBe("*");
        }