Ejemplo n.º 1
0
        private void DisplayComponent(IReadOnlyProjectComponent inputComponent)
        {
            var mutationScore = inputComponent.GetMutationScore();

            // Convert the threshold integer values to decimal values
            _consoleWriter.Write($" [{ inputComponent.DetectedMutants().Count()}/{ inputComponent.TotalMutants().Count()} ");

            if (inputComponent.IsComponentExcluded(_options.Mutate))
            {
                _consoleWriter.Write(Output.Bright.Black("(Excluded)"));
            }
            else if (double.IsNaN(mutationScore))
            {
                _consoleWriter.Write(Output.Bright.Black("(N/A)"));
            }
            else
            {
                // print the score as a percentage
                string scoreText = string.Format("({0:P2})", mutationScore);
                if (inputComponent.CheckHealth(_options.Thresholds) is Health.Good)
                {
                    _consoleWriter.Write(Output.Green(scoreText));
                }
                else if (inputComponent.CheckHealth(_options.Thresholds) is Health.Warning)
                {
                    _consoleWriter.Write(Output.Yellow(scoreText));
                }
                else if (inputComponent.CheckHealth(_options.Thresholds) is Health.Danger)
                {
                    _consoleWriter.Write(Output.Red(scoreText));
                }
            }
            _consoleWriter.WriteLine("]");
        }
        private void DisplayComponent(IReadOnlyProjectComponent inputComponent, Table table)
        {
            var columns = new List <IRenderable>
            {
                new Text(inputComponent.RelativePath ?? "All files")
            };

            var mutationScore = inputComponent.GetMutationScore();

            if (inputComponent.IsComponentExcluded(_options.Mutate))
            {
                columns.Add(new Markup("[Gray]Excluded[/]"));
            }
            else if (double.IsNaN(mutationScore))
            {
                columns.Add(new Markup("[Gray]N/A[/]"));
            }
            else
            {
                var scoreText = $"{mutationScore * 100:N2}";

                var checkHealth = inputComponent.CheckHealth(_options.Thresholds);
                if (checkHealth is Health.Good)
                {
                    columns.Add(new Markup($"[Green]{scoreText}[/]"));
                }
                else if (checkHealth is Health.Warning)
                {
                    columns.Add(new Markup($"[Yellow]{scoreText}[/]"));
                }
                else if (checkHealth is Health.Danger)
                {
                    columns.Add(new Markup($"[Red]{scoreText}[/]"));
                }
            }

            var mutants = inputComponent.Mutants.ToList();

            columns.Add(new Text(mutants.Count(m => m.ResultStatus == MutantStatus.Killed).ToString()));
            columns.Add(new Text(mutants.Count(m => m.ResultStatus == MutantStatus.Timeout).ToString()));
            columns.Add(new Text((inputComponent.TotalMutants().Count() - inputComponent.DetectedMutants().Count()).ToString()));
            columns.Add(new Text(mutants.Count(m => m.ResultStatus == MutantStatus.NoCoverage).ToString()));
            columns.Add(new Text(mutants.Count(m => m.ResultStatus == MutantStatus.CompileError).ToString()));

            table.AddRow(columns);
        }
Ejemplo n.º 3
0
        private void DisplayComponent(IReadOnlyProjectComponent inputComponent, int filePathLength)
        {
            _consoleWriter.Write($"│ {(inputComponent.RelativePath ?? "All files").PadRight(filePathLength)}│ ");

            var mutationScore = inputComponent.GetMutationScore();

            if (inputComponent.IsComponentExcluded(_options.Mutate))
            {
                _consoleWriter.Write(Output.Bright.Black("Excluded"));
            }
            else if (double.IsNaN(mutationScore))
            {
                _consoleWriter.Write(Output.Bright.Black("     N/A"));
            }
            else
            {
                var scoreText = $"{mutationScore * 100:N2}".PadLeft(8);

                var checkHealth = inputComponent.CheckHealth(_options.Thresholds);
                if (checkHealth is Health.Good)
                {
                    _consoleWriter.Write(Output.Green(scoreText));
                }
                else if (checkHealth is Health.Warning)
                {
                    _consoleWriter.Write(Output.Yellow(scoreText));
                }
                else if (checkHealth is Health.Danger)
                {
                    _consoleWriter.Write(Output.Red(scoreText));
                }
            }

            var mutants = inputComponent.Mutants.ToList();

            _consoleWriter.Write($" │ {mutants.Count(m => m.ResultStatus == MutantStatus.Killed),8}");
            _consoleWriter.Write($" │ {mutants.Count(m => m.ResultStatus == MutantStatus.Timeout),9}");
            _consoleWriter.Write($" │ {inputComponent.TotalMutants().Count() - inputComponent.DetectedMutants().Count(),10}");
            _consoleWriter.Write($" │ {mutants.Count(m => m.ResultStatus == MutantStatus.NoCoverage),8}");
            _consoleWriter.Write($" │ {mutants.Count(m => m.ResultStatus == MutantStatus.CompileError),7}");
            _consoleWriter.WriteLine($" │");
        }
        private string DisplayComponent(IReadOnlyProjectComponent inputComponent)
        {
            var mutationScore = inputComponent.GetMutationScore();

            var stringBuilder = new StringBuilder();

            // Convert the threshold integer values to decimal values
            stringBuilder.Append($" [[{ inputComponent.DetectedMutants().Count()}/{ inputComponent.TotalMutants().Count()} ");

            if (inputComponent.IsComponentExcluded(_options.Mutate))
            {
                stringBuilder.Append("[Gray](Excluded)[/]");
            }
            else if (double.IsNaN(mutationScore))
            {
                stringBuilder.Append("[Gray](N/A)[/]");
            }
            else
            {
                // print the score as a percentage
                var scoreText = string.Format("({0:P2})", mutationScore);
                if (inputComponent.CheckHealth(_options.Thresholds) is Health.Good)
                {
                    stringBuilder.Append($"[Green]{scoreText}[/]");
                }
                else if (inputComponent.CheckHealth(_options.Thresholds) is Health.Warning)
                {
                    stringBuilder.Append($"[Yellow]{scoreText}[/]");
                }
                else if (inputComponent.CheckHealth(_options.Thresholds) is Health.Danger)
                {
                    stringBuilder.Append($"[Red]{scoreText}[/]");
                }
            }

            stringBuilder.Append("]]");

            return(stringBuilder.ToString());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Starts a mutation test run
        /// </summary>
        /// <param name="options">The user options</param>
        /// <param name="loggerFactory">This loggerfactory will be used to create loggers during the stryker run</param>
        /// <exception cref="InputException">For managed exceptions</exception>
        public StrykerRunResult RunMutationTest(IStrykerInputs inputs, ILoggerFactory loggerFactory, IProjectOrchestrator projectOrchestrator = null)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            SetupLogging(loggerFactory);

            // Setup project orchestrator can't be done sooner since it needs logging
            projectOrchestrator ??= new ProjectOrchestrator();

            var options = inputs.ValidateAll();

            _logger.LogDebug("Stryker started with options: {@Options}", options);

            var reporters = _reporterFactory.Create(options);

            try
            {
                // Mutate
                _mutationTestProcesses = projectOrchestrator.MutateProjects(options, reporters).ToList();

                IReadOnlyProjectComponent rootComponent = AddRootFolderIfMultiProject(_mutationTestProcesses.Select(x => x.Input.ProjectInfo.ProjectContents).ToList(), options);

                _logger.LogInformation("{0} mutants created", rootComponent.Mutants.Count());

                AnalyseCoverage(options);

                // Filter
                foreach (var project in _mutationTestProcesses)
                {
                    project.FilterMutants();
                }

                // Report
                reporters.OnMutantsCreated(rootComponent);

                var allMutants    = rootComponent.Mutants;
                var mutantsNotRun = rootComponent.NotRunMutants().ToList();

                if (!mutantsNotRun.Any())
                {
                    if (allMutants.Any(x => x.ResultStatus == MutantStatus.Ignored))
                    {
                        _logger.LogWarning("It looks like all mutants with tests were ignored. Try a re-run with less ignoring!");
                    }
                    if (allMutants.Any(x => x.ResultStatus == MutantStatus.NoCoverage))
                    {
                        _logger.LogWarning("It looks like all non-ignored mutants are not covered by a test. Go add some tests!");
                    }
                    if (allMutants.Any(x => x.ResultStatus == MutantStatus.CompileError))
                    {
                        _logger.LogWarning("It looks like all mutants resulted in compile errors. Mutants sure are strange!");
                    }
                    if (!allMutants.Any())
                    {
                        _logger.LogWarning("It\'s a mutant-free world, nothing to test.");
                    }

                    reporters.OnAllMutantsTested(rootComponent);
                    return(new StrykerRunResult(options, rootComponent.GetMutationScore()));
                }

                // Report
                reporters.OnStartMutantTestRun(mutantsNotRun);

                // Test
                foreach (var project in _mutationTestProcesses)
                {
                    project.Test(project.Input.ProjectInfo.ProjectContents.Mutants.Where(x => x.ResultStatus == MutantStatus.NotRun).ToList());
                    project.Restore();
                }

                reporters.OnAllMutantsTested(rootComponent);

                return(new StrykerRunResult(options, rootComponent.GetMutationScore()));
            }
#if !DEBUG
            catch (Exception ex) when(!(ex is InputException))
            // let the exception be caught by the debugger when in debug
            {
                _logger.LogError(ex, "An error occurred during the mutation test run ");
                throw;
            }
#endif
            finally
            {
                // log duration
                stopwatch.Stop();
                _logger.LogInformation("Time Elapsed {0}", stopwatch.Elapsed);
            }
        }