Exemple #1
0
        public void OnAllMutantsTested(IReadOnlyInputComponent inputComponent)
        {
            // setup display handlers
            inputComponent.DisplayFolder = (int depth, IReadOnlyInputComponent current) =>
            {
                // show depth
                _chalk.Default($"{new string('-', depth)} {Path.DirectorySeparatorChar}{Path.GetFileName(current.Name)} ");
                DisplayComponent(current);
            };

            inputComponent.DisplayFile = (int depth, IReadOnlyInputComponent current) =>
            {
                // show depth
                _chalk.Default($"{new string('-', depth)} {current.Name} ");
                DisplayComponent(current);
                foreach (var mutant in current.TotalMutants)
                {
                    if (mutant.ResultStatus == MutantStatus.Killed ||
                        mutant.ResultStatus == MutantStatus.Timeout)
                    {
                        _chalk.Green($"[{mutant.ResultStatus}] ");
                    }
                    else
                    {
                        _chalk.Red($"[{mutant.ResultStatus}] ");
                    }
                    _chalk.Default($"{mutant.Mutation.DisplayName} on line {mutant.Mutation.OriginalNode.GetLocation().GetLineSpan().StartLinePosition.Line + 1}: '{mutant.Mutation.OriginalNode}' ==> '{mutant.Mutation.ReplacementNode}'{Environment.NewLine}");
                }
            };

            // print empty line for readability
            _chalk.Default($"{Environment.NewLine}{Environment.NewLine}All mutants have been tested, and your mutation score has been calculated{Environment.NewLine}");
            // start recursive invocation of handlers
            inputComponent.Display(1);
        }
Exemple #2
0
        private void MutantAnalyzerOnMutantExecuted(object sender, CppMutantEventArgs e)
        {
            lock (Sync)
            {
                var mutant     = e.Mutant;
                var lineNumber = mutant.Mutation.LineNumber;
                var status     = $"{Environment.NewLine}Line: {lineNumber} - {mutant.ResultStatus.ToString()} - {mutant.Mutation.DisplayName}".PrintWithDateTimeSimple();

                if (mutant.ResultStatus == MutantStatus.Survived)
                {
                    _chalk.Yellow($"{status}{Environment.NewLine}");
                }
                else if (mutant.ResultStatus == MutantStatus.BuildError)
                {
                    _chalk.Red($"{status}{Environment.NewLine}");
                }
                else if (mutant.ResultStatus == MutantStatus.Timeout)
                {
                    _chalk.Cyan($"{status}{Environment.NewLine}");
                }
                else
                {
                    _chalk.Green($"{status}{Environment.NewLine}");
                }

                if (_options.EnableDiagnostics)
                {
                    _chalk.Red($"{e.BuildLog.ConvertToPlainText()}{Environment.NewLine}");
                    _chalk.Red($"{e.TestLog.ConvertToPlainText()}{Environment.NewLine}");
                }

                _mutantProgress++;
                UpdateProgress();
            }
        }
Exemple #3
0
        private static int Main(string[] args)
        {
            try
            {
                _chalk = new Chalk();
                Trace.Listeners.Add(new EventLogTraceListener("MuTest_CPP_CLI"));

                _muTest = new MuTestRunner(_chalk, new CppDirectoryFactory());
                var app = new MuTestCli(_muTest);

                CancelKeyPress += CancelMutationHandler;
                AppDomain.CurrentDomain.ProcessExit += CancelMutationHandler;

                return(app.Run(args));
            }
            catch (MuTestInputException ex)
            {
                ShowMessage(ex);
                CancelMutation();
                return(1);
            }
            catch (CommandParsingException ex)
            {
                _chalk.Red(ex.Message);
                CancelMutation();
                return(1);
            }
            catch (Exception ex)
            {
                CancelMutation();
                var innerException = ex.InnerException;
                if (innerException != null && (innerException.GetType() == typeof(MuTestInputException) ||
                                               innerException.GetType().BaseType == typeof(MuTestInputException)))
                {
                    ShowMessage((MuTestInputException)innerException);

                    var statusCode = MuTestExceptions[innerException.GetType()];
                    _chalk.Red($"\nStatus Code: {statusCode}\n");
                    return(statusCode);
                }

                if (ex.Message.StartsWith("Unrecognized option"))
                {
                    _chalk.Default($"{ex.Message}{Environment.NewLine}");
                    return(1);
                }

                Trace.TraceError("{0}", ex);
                _chalk.Red($"\n{ex.Message} - review trace for more details\n");
                return(1);
            }
        }
        public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent)
        {
            var mutationReport = JsonReport.Build(_options, reportComponent);

            var reportUrl = PublishReport(mutationReport.ToJson()).Result;

            if (reportUrl != null)
            {
                _chalk.Green($"\nYour stryker report has been uploaded to: \n {reportUrl} \nYou can open it in your browser of choice.");
            }
            else
            {
                _chalk.Red("Uploading to stryker dashboard failed...");
            }
            Console.WriteLine(Environment.NewLine);
        }
        public void OnMutantTested(IReadOnlyMutant result)
        {
            switch (result.ResultStatus)
            {
            case MutantStatus.Killed:
                _chalk.Default(".");
                break;

            case MutantStatus.Survived:
                _chalk.Red("S");
                break;

            case MutantStatus.Timeout:
                _chalk.Default("T");
                break;
            }
            ;
        }
Exemple #6
0
        private void DisplayComponent(ProjectComponent inputComponent, int filePathLength)
        {
            _chalk.Default($"│ {(inputComponent.RelativePathToProjectFile ?? "All files").PadRight(filePathLength)}│ ");

            var mutationScore = inputComponent.GetMutationScore();

            if (inputComponent is FileLeaf && inputComponent.IsComponentExcluded(_options.FilePatterns))
            {
                _chalk.DarkGray("Excluded");
            }
            else if (double.IsNaN(mutationScore))
            {
                _chalk.DarkGray("     N/A");
            }
            else
            {
                var scoreText = $"{mutationScore * 100:N2}".PadLeft(8);

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

            _chalk.Default($" │ {inputComponent.ReadOnlyMutants.Count(m => m.ResultStatus == MutantStatus.Killed),8}");
            _chalk.Default($" │ {inputComponent.ReadOnlyMutants.Count(m => m.ResultStatus == MutantStatus.Timeout),9}");
            _chalk.Default($" │ {inputComponent.TotalMutants.Count() - inputComponent.DetectedMutants.Count(),10}");
            _chalk.Default($" │ {inputComponent.ReadOnlyMutants.Count(m => m.ResultStatus == MutantStatus.NoCoverage),8}");
            _chalk.Default($" │ {inputComponent.ReadOnlyMutants.Count(m => m.ResultStatus == MutantStatus.CompileError),7}");
            _chalk.Default($" │{Environment.NewLine}");
        }
        public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent)
        {
            // setup display handlers
            reportComponent.DisplayFolder = (int depth, IReadOnlyInputComponent current) =>
            {
                // show depth
                _chalk.Default($"{new string('-', depth)} {Path.DirectorySeparatorChar}{Path.GetFileName(current.Name)} ");
                DisplayComponent(current);
            };

            reportComponent.DisplayFile = (int depth, IReadOnlyInputComponent current) =>
            {
                // show depth
                _chalk.Default($"{new string('-', depth)} {current.Name} ");
                DisplayComponent(current);
                foreach (var mutant in current.TotalMutants)
                {
                    if (mutant.ResultStatus == MutantStatus.Killed ||
                        mutant.ResultStatus == MutantStatus.Timeout)
                    {
                        _chalk.Green($"[{mutant.ResultStatus}] ");
                    }
                    else if (mutant.ResultStatus == MutantStatus.NoCoverage)
                    {
                        _chalk.Yellow($"[{mutant.ResultStatus}] ");
                    }
                    else
                    {
                        _chalk.Red($"[{mutant.ResultStatus}] ");
                    }
                    _chalk.Default(mutant.LongName + Environment.NewLine);
                }
            };

            // print empty line for readability
            _chalk.Default($"{Environment.NewLine}{Environment.NewLine}All mutants have been tested, and your mutation score has been calculated{Environment.NewLine}");
            // start recursive invocation of handlers
            reportComponent.Display(1);
        }
Exemple #8
0
 private static void ShowMessage(MuTestInputException strEx)
 {
     _chalk.Yellow("\nMuTest C++ failed to mutate your project. For more information see the logs below:\n");
     _chalk.Red($"\n{strEx.Message} - {strEx.Details.ConvertToPlainText()}\n");
 }
        private async Task FindTestExecutionTime(SourceClassDetail source)
        {
            _chalk.Default("\nFinding Tests Execution Time...");
            var log = new StringBuilder();

            void OutputData(object sender, string args) => log.AppendLine(args);

            var testExecutor = new TestExecutor(_settings, source.TestClaz.ClassLibrary)
            {
                X64TargetPlatform  = X64TargetPlatform,
                FullyQualifiedName = source.TestClaz.MethodDetails.Count > _useClassFilterTestsThreshold ||
                                     UseClassFilter || source.TestClaz.BaseClass != null
                    ? source.TestClaz.Claz.Syntax.FullName()
                    : string.Empty,
                EnableLogging       = true,
                EnableCustomOptions = false
            };

            testExecutor.OutputDataReceived += OutputData;

            await testExecutor.ExecuteTests(source.TestClaz.MethodDetails.ToList());

            testExecutor.OutputDataReceived -= OutputData;

            if (testExecutor.LastTestExecutionStatus != Constants.TestExecutionStatus.Success)
            {
                throw new MuTestFailingTestException(log.ToString());
            }

            if (testExecutor.TestResult?.Results?.UnitTestResult != null)
            {
                var tests = testExecutor.TestResult?.Results?.UnitTestResult;
                foreach (var test in tests)
                {
                    var executionTime = 0d;
                    if (test.Duration != null)
                    {
                        executionTime = TimeSpan.Parse(test.Duration).TotalMilliseconds;
                    }

                    if (executionTime <= TestExecutionTime)
                    {
                        source.TestExecutionTimes.Add(new TestExecutionTime(test.TestName, executionTime));
                    }
                    else
                    {
                        source.TestExecutionTimesAboveThreshold.Add(new TestExecutionTime(test.TestName, executionTime));
                    }
                }

                source.TestExecutionTimes.Sort((x1, x2) => x2.ExecutionTime.CompareTo(x1.ExecutionTime));
                source.TestExecutionTimesAboveThreshold.Sort((x1, x2) => x2.ExecutionTime.CompareTo(x1.ExecutionTime));

                foreach (var test in source.TestExecutionTimesAboveThreshold)
                {
                    _chalk.Red($"\n  {test.TestName} ({test.ExecutionTime}ms)");
                }

                foreach (var test in source.TestExecutionTimes)
                {
                    _chalk.Green($"\n  {test.TestName} ({test.ExecutionTime}ms)");
                }
            }
        }
Exemple #10
0
        public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent)
        {
            var rootFolderProcessed = false;

            // setup display handlers
            reportComponent.DisplayFolder = (int _, IReadOnlyInputComponent current) =>
            {
                // show depth
                var continuationLines = ParentContinuationLines(current);

                var stringBuilder = new StringBuilder();
                foreach (var item in continuationLines.SkipLast(1))
                {
                    stringBuilder.Append(item ? ContinueLine : NoLine);
                }

                var folderLines = string.Empty;
                if (continuationLines.Count > 0)
                {
                    folderLines = continuationLines.Last() ? BranchLine : FinalBranchLine;
                }

                var name = current.Name;
                if (name == null && !rootFolderProcessed)
                {
                    name = "All files";
                    rootFolderProcessed = true;
                }

                if (!string.IsNullOrWhiteSpace(name))
                {
                    _chalk.Default($"{stringBuilder}{folderLines}{name}");
                    DisplayComponent(current);
                }
            };

            reportComponent.DisplayFile = (int _, IReadOnlyInputComponent current) =>
            {
                // show depth
                var continuationLines = ParentContinuationLines(current);

                var stringBuilder = new StringBuilder();
                foreach (var item in continuationLines.SkipLast(1))
                {
                    stringBuilder.Append(item ? ContinueLine : NoLine);
                }

                _chalk.Default($"{stringBuilder}{(continuationLines.Last() ? BranchLine : FinalBranchLine)}{current.Name}");
                DisplayComponent(current);

                stringBuilder.Append(continuationLines.Last() ? ContinueLine : NoLine);

                var prefix = stringBuilder.ToString();

                foreach (var mutant in current.TotalMutants)
                {
                    var isLastMutant = current.TotalMutants.Last() == mutant;

                    _chalk.Default($"{prefix}{(isLastMutant ? FinalBranchLine : BranchLine)}");

                    switch (mutant.ResultStatus)
                    {
                    case MutantStatus.Killed:
                    case MutantStatus.Timeout:
                        _chalk.Green($"[{mutant.ResultStatus}]");
                        break;

                    case MutantStatus.NoCoverage:
                        _chalk.Yellow($"[{mutant.ResultStatus}]");
                        break;

                    default:
                        _chalk.Red($"[{mutant.ResultStatus}]");
                        break;
                    }

                    _chalk.Default($" {mutant.Mutation.DisplayName} on line {mutant.Line}{Environment.NewLine}");
                    _chalk.Default($"{prefix}{(isLastMutant ? NoLine : ContinueLine)}{BranchLine}[-] {mutant.Mutation.OriginalNode}{Environment.NewLine}");
                    _chalk.Default($"{prefix}{(isLastMutant ? NoLine : ContinueLine)}{FinalBranchLine}[+] {mutant.Mutation.ReplacementNode}{Environment.NewLine}");
                }
            };

            // print empty line for readability
            _chalk.Default($"{Environment.NewLine}{Environment.NewLine}All mutants have been tested, and your mutation score has been calculated{Environment.NewLine}");

            // start recursive invocation of handlers
            reportComponent.Display(1);
        }
Exemple #11
0
        private static int Main(string[] args)
        {
            try
            {
                _chalk = new Chalk();
                Trace.Listeners.Add(new EventLogTraceListener("MuTest_CPP_CLI"));
                var services = new ServiceCollection();

                services
                .AddHttpClient <IFirebaseApiClient, FirebaseApiClient>()
                .AddPolicyHandler(GetRetryPolicy())
                .AddPolicyHandler(GetCircuitBreakerPatternPolicy());
                services.AddSingleton(_chalk);
                var provider = services.BuildServiceProvider();
                var factory  = provider.GetService <IHttpClientFactory>();

                _muTest = new MuTestRunner(
                    _chalk,
                    new CppDirectoryFactory(),
                    new FirebaseApiClient(
                        factory.CreateClient(),
                        MuTestSettings.FireBaseDatabaseApiUrl,
                        MuTestSettings.FireBaseStorageApiUrl));
                var app = new MuTestCli(_muTest);

                CancelKeyPress += CancelMutationHandler;
                AppDomain.CurrentDomain.ProcessExit += CancelMutationHandler;

                return(app.Run(args));
            }
            catch (MuTestInputException ex)
            {
                ShowMessage(ex);
                CancelMutation();
                return(1);
            }
            catch (CommandParsingException ex)
            {
                _chalk.Red(ex.Message);
                CancelMutation();
                return(1);
            }
            catch (Exception ex)
            {
                CancelMutation();
                var innerException = ex.InnerException;
                if (innerException != null && (innerException.GetType() == typeof(MuTestInputException) ||
                                               innerException.GetType().BaseType == typeof(MuTestInputException)))
                {
                    ShowMessage((MuTestInputException)innerException);

                    var statusCode = MuTestExceptions[innerException.GetType()];
                    _chalk.Red($"\nStatus Code: {statusCode}\n");
                    return(statusCode);
                }

                if (ex.Message.StartsWith("Unrecognized option"))
                {
                    _chalk.Default($"{ex.Message}{Environment.NewLine}");
                    return(1);
                }

                Trace.TraceError("{0}", ex);
                _chalk.Red($"\n{ex.Message} - review trace for more details\n");
                return(1);
            }
        }