public void OnMutantsCreated(IReadOnlyInputComponent inputComponent) { foreach (var reporter in Reporters) { reporter.OnMutantsCreated(inputComponent); } }
public void OnAllMutantsTested(IReadOnlyInputComponent inputComponent) { foreach (var reporter in _reporters) { reporter.OnAllMutantsTested(inputComponent); } }
private void DisplayComponent(IReadOnlyInputComponent inputComponent) { var score = inputComponent.GetMutationScore(); // Convert the threshold integer values to decimal values _chalk.Default($"[{ inputComponent.DetectedMutants.Count()}/{ inputComponent.TotalMutants.Count()} "); if (inputComponent.IsExcluded) { _chalk.DarkGray($"(Excluded)"); } else if (!score.HasValue) { _chalk.DarkGray($"(- %)"); } else { // print the score as a percentage string scoreText = $"({ (score.Value / 100).ToString("p", CultureInfo.InvariantCulture)})"; if (inputComponent.CheckHealth(_options.Thresholds) is Health.Good) { _chalk.Green(scoreText); } else if (inputComponent.CheckHealth(_options.Thresholds) is Health.Warning) { _chalk.Yellow(scoreText); } else if (inputComponent.CheckHealth(_options.Thresholds) is Health.Danger) { _chalk.Red(scoreText); } } _chalk.Default($"]{Environment.NewLine}"); }
private void DisplayComponent(IReadOnlyInputComponent inputComponent) { var score = inputComponent.GetMutationScore(); _chalk.Default($"[{ inputComponent.DetectedMutants.Count()}/{ inputComponent.TotalMutants.Count()} "); if (!score.HasValue) { _chalk.DarkGray($"(- %)"); } else { // print the score as a percentage string scoreText = $"({ score.Value.ToString("P", CultureInfo.InvariantCulture)})"; if (score > 0.8M) { _chalk.Green(scoreText); } else if (score > 0.6M) { _chalk.Yellow(scoreText); } else { _chalk.Red(scoreText); } } _chalk.Default($"]{Environment.NewLine}"); }
private static List <bool> ParentContinuationLines(IReadOnlyInputComponent current) { var continuationLines = new List <bool>(); var node = (ProjectComponent)current; if (node.Parent != null) { var isRootFile = node.RelativePath == node.RelativePathToProjectFile; if (isRootFile) { continuationLines.Add(true); } else { while (node.Parent != null) { continuationLines.Add(node.Parent.Children.Last() != node); node = node.Parent; } continuationLines.Reverse(); } } return(continuationLines); }
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); }
private void DisplayComponent(IReadOnlyInputComponent inputComponent) { var score = inputComponent.GetMutationScore(); // Convert the threshold integer values to decimal values decimal thresholdHigh = _options.ThresholdOptions.ThresholdHigh; decimal thresholdLow = _options.ThresholdOptions.ThresholdLow; decimal thresholdBreak = _options.ThresholdOptions.ThresholdBreak; _chalk.Default($"[{ inputComponent.DetectedMutants.Count()}/{ inputComponent.TotalMutants.Count()} "); if (!score.HasValue) { _chalk.DarkGray($"(- %)"); } else { // print the score as a percentage string scoreText = $"({ (score.Value / 100).ToString("p", CultureInfo.InvariantCulture)})"; if (score > thresholdHigh) { _chalk.Green(scoreText); } else if (score > thresholdLow) { _chalk.Yellow(scoreText); } else if (score <= thresholdLow) { _chalk.Red(scoreText); } } _chalk.Default($"]{Environment.NewLine}"); }
public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent) { var mutationReport = JsonReport.Build(_options, reportComponent); var projectVersion = _gitInfoProvider.GetCurrentBranchName(); var baselineVersion = $"dashboard-compare/{projectVersion}"; _baselineProvider.Save(mutationReport, baselineVersion).Wait(); }
private JsonReport(StrykerOptions options, IReadOnlyInputComponent mutationReport) { _options = options; Thresholds.Add("high", _options.Thresholds.High); Thresholds.Add("low", _options.Thresholds.Low); Merge(Files, GenerateReportComponents(mutationReport)); }
public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent) { var jsonReport = JsonReportComponent.FromProjectComponent(reportComponent, _options); jsonReport.ThresholdHigh = _options.ThresholdOptions.ThresholdHigh; jsonReport.ThresholdLow = _options.ThresholdOptions.ThresholdLow; jsonReport.ThresholdBreak = _options.ThresholdOptions.ThresholdBreak; WriteReportToJsonFile(jsonReport, Path.Combine(_options.BasePath, "StrykerOutput", "reports", "mutation-report.json")); }
public void OnMutantsCreated(IReadOnlyInputComponent inputComponent) { // print empty line for readability Console.WriteLine(""); _chalk.Default($"{inputComponent.TotalMutants.Count()} mutants have been created. Each mutant will now be tested, this could take a while. {Environment.NewLine}"); // print empty line for readability Console.WriteLine(""); }
private void DisplayComponent(IReadOnlyInputComponent inputComponent) { var mutationScore = inputComponent.GetMutationScore(); // Convert the threshold integer values to decimal values _chalk.Default($" [{ inputComponent.DetectedMutants.Count()}/{ inputComponent.TotalMutants.Count()} "); if (inputComponent is ProjectComponent projectComponent && projectComponent.FullPath != null && projectComponent.IsComponentExcluded(_options.FilePatterns)) { _chalk.DarkGray($"(Excluded)"); }
private void DisplayComponent(IReadOnlyInputComponent inputComponent) { var mutationScore = inputComponent.GetMutationScore(); // Convert the threshold integer values to decimal values _consoleWriter.Write($" [{ inputComponent.DetectedMutants.Count()}/{ inputComponent.TotalMutants.Count()} "); if (inputComponent is ProjectComponent projectComponent && projectComponent.FullPath != null && projectComponent.IsComponentExcluded(_options.FilePatterns)) { _consoleWriter.Write(Output.BrightBlack("(Excluded)")); }
public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent) { var jsonReport = JsonReportComponent.FromProjectComponent(reportComponent, _options.ThresholdOptions); jsonReport.Name = _options.ProjectUnderTestNameFilter; using (var file = File.CreateText(_options.BasePath + "/StrykerLogs/mutation-report.json")) { file.WriteLine(SerializeJsonReport(jsonReport)); } }
public void OnAllMutantsTested(IReadOnlyInputComponent mutationTree) { var mutationReport = JsonReport.Build(_options, mutationTree); var reportPath = Path.Combine(_options.OutputPath, "reports", "mutation-report.json"); WriteReportToJsonFile(reportPath, mutationReport.ToJson()); _chalk.Green($"\nYour json report has been generated at: \n " + $"{reportPath} \n"); }
public static JsonReport Build(StrykerOptions options, IReadOnlyInputComponent mutationReport) { // This should really only happen in unit tests. // We need this construct because in a unit test // we want to be able to generate different reports with different settings _report = _options == options ? _report : null; // If the report was already generated, return the existing report _report = _report ?? new JsonReport(options, mutationReport); return(_report); }
public void OnAllMutantsTested(IReadOnlyInputComponent mutationTree) { var mutationReport = JsonReport.Build(_options, mutationTree); var reportPath = Path.Combine(_options.OutputPath, "reports", "mutation-report.html"); WriteHtmlReport(reportPath, mutationReport.ToJson()); _chalk.Green($"\nYour html report has been generated at: \n " + $"{reportPath} \n" + $"You can open it in your browser of choice. \n"); }
public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent) { var mutationReport = JsonReport.Build(_options, reportComponent); if (_options.CompareToDashboard) { Task.WaitAll(UploadHumanReadableReport(mutationReport), UploadBaseline(mutationReport)); } else { Task.WaitAll(UploadHumanReadableReport(mutationReport)); } }
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 OnAllMutantsTested(IReadOnlyInputComponent reportComponent) { var mutationReport = JsonReport.Build(_options, reportComponent); var reportUrl = _dashboardClient.PublishReport(mutationReport.ToJson(), _options.ProjectVersion).Result; if (reportUrl != null) { _logger.LogDebug("Your stryker report has been uploaded to: \n {0} \nYou can open it in your browser of choice.", reportUrl); _chalk.Green($"Your stryker report has been uploaded to: \n {reportUrl} \nYou can open it in your browser of choice."); } else { _logger.LogError("Uploading to stryker dashboard failed..."); } Console.WriteLine(Environment.NewLine); }
private void ValidateJsonReportComponent(JsonReportComponent jsonComponent, IReadOnlyInputComponent inputComponent, string health, int mutants = 0) { jsonComponent.Name.ShouldBe(inputComponent.Name); jsonComponent.Health.ShouldBe(health); jsonComponent.PossibleMutants.ShouldBe(inputComponent.ReadOnlyMutants.Where(m => m.ResultStatus != MutantStatus.BuildError).Count()); jsonComponent.MutationScore.ShouldBe(inputComponent.GetMutationScore()); jsonComponent.CompileErrors.ShouldBe(inputComponent.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.BuildError).Count()); jsonComponent.SurvivedMutants.ShouldBe(inputComponent.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Survived).Count()); jsonComponent.SkippedMutants.ShouldBe(inputComponent.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Skipped).Count()); jsonComponent.TimeoutMutants.ShouldBe(inputComponent.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Timeout).Count()); jsonComponent.KilledMutants.ShouldBe(inputComponent.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Killed).Count()); jsonComponent.TotalMutants.ShouldBe(inputComponent.TotalMutants.Count()); jsonComponent.ThresholdHigh.ShouldBe(80); jsonComponent.ThresholdLow.ShouldBe(60); jsonComponent.ThresholdBreak.ShouldBe(0); if (inputComponent is FolderComposite folderComponent) { jsonComponent.Source.ShouldBe(null); jsonComponent.Mutants.ShouldBeEmpty(); jsonComponent.ChildResults.Count.ShouldBe(folderComponent.Children.Count()); } if (inputComponent is FileLeaf fileComponent) { jsonComponent.Source.ShouldBe(fileComponent.SourceCode); jsonComponent.Mutants.Count.ShouldBe(mutants); for (int i = 0; i < mutants; i++) { jsonComponent.Mutants[i].Id.ShouldBe(fileComponent.Mutants.ToArray()[i].Id); jsonComponent.Mutants[i].MutatorName.ShouldBe(fileComponent.Mutants.ToArray()[i].Mutation.DisplayName); jsonComponent.Mutants[i].Replacement.ShouldBe(fileComponent.Mutants.ToArray()[i].Mutation.ReplacementNode.ToString()); jsonComponent.Mutants[i].Span.ShouldBe( new[] { fileComponent.Mutants.ToArray()[i].Mutation.OriginalNode.SpanStart, fileComponent.Mutants.ToArray()[i].Mutation.OriginalNode.Span.End }); jsonComponent.Mutants[i].Status.ShouldBe(fileComponent.Mutants.ToArray()[i].ResultStatus.ToString()); } } }
public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent) { var files = new List <FileLeaf>(); FolderComposite rootFolder = null; reportComponent.DisplayFolder = (int _, IReadOnlyInputComponent current) => { rootFolder ??= (FolderComposite)current; }; reportComponent.DisplayFile = (int _, IReadOnlyInputComponent current) => { var fileLeaf = (FileLeaf)current; files.Add((FileLeaf)current); }; // print empty line for readability _consoleWriter.WriteLine(); _consoleWriter.WriteLine(); _consoleWriter.WriteLine("All mutants have been tested, and your mutation score has been calculated"); // start recursive invocation of handlers reportComponent.Display(0); var filePathLength = Math.Max(9, files.Max(f => f.RelativePathToProjectFile?.Length ?? 0) + 1); _consoleWriter.WriteLine($"┌─{new string('─', filePathLength)}┬──────────┬──────────┬───────────┬────────────┬──────────┬─────────┐"); _consoleWriter.WriteLine($"│ File{new string(' ', filePathLength - 4)}│ % score │ # killed │ # timeout │ # survived │ # no cov │ # error │"); _consoleWriter.WriteLine($"├─{new string('─', filePathLength)}┼──────────┼──────────┼───────────┼────────────┼──────────┼─────────┤"); DisplayComponent(rootFolder, filePathLength); foreach (var file in files) { DisplayComponent(file, filePathLength); } _consoleWriter.WriteLine($"└─{new string('─', filePathLength)}┴──────────┴──────────┴───────────┴────────────┴──────────┴─────────┘"); }
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); }
public static JsonReportComponent FromProjectComponent(IReadOnlyInputComponent component, StrykerOptions options) { int Where(MutantStatus MutantStatus) => component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus).Count(); var report = new JsonReportComponent { DetectedMutations = component.DetectedMutants.Count(), TotalMutants = component.TotalMutants.Count(), KilledMutants = Where(MutantStatus.Killed), SurvivedMutants = Where(MutantStatus.Survived), SkippedMutants = Where(MutantStatus.Skipped), TimeoutMutants = Where(MutantStatus.Timeout), CompileErrors = Where(MutantStatus.CompileError), MutationScore = component.GetMutationScore() ?? 0, }; report.ValidMutations = report.TotalMutants + report.SkippedMutants; if (report.MutationScore >= options.ThresholdOptions.ThresholdHigh) { report.Health = "Good"; } else if (report.MutationScore <= options.ThresholdOptions.ThresholdBreak) { report.Health = "Danger"; } else { report.Health = "Warning"; } if (component is FolderComposite folderComponent) { report.Name = component.Name is null ? options.ProjectUnderTestNameFilter : folderComponent.RelativePath; report.ChildResults = new List <JsonReportComponent>(); foreach (var child in folderComponent.Children) { report.ChildResults.Add(FromProjectComponent(child, options)); } } else if (component is FileLeaf fileComponent) { report.Name = fileComponent.Name; report.Source = fileComponent.SourceCode; report.Language = "cs"; report.Mutants = new List <JsonMutant>(); foreach (var mutant in fileComponent.Mutants) { var jsonMutant = new JsonMutant { Id = mutant.Id, MutatorName = mutant.Mutation.DisplayName, Replacement = mutant.Mutation.ReplacementNode.ToFullString(), Location = new JsonMutant.JsonMutantLocation(mutant.Mutation.OriginalNode.SyntaxTree.GetLineSpan(mutant.Mutation.OriginalNode.FullSpan)), Status = mutant.ResultStatus.ToString() }; report.Mutants.Add(jsonMutant); } } else { throw new System.Exception("Unknown IReadOnlyInputComponent implementation"); } return(report); }
public void OnMutantsCreated(IReadOnlyInputComponent reportComponent) { // Method to implement the interface }
public void OnMutantsCreated(IReadOnlyInputComponent reportComponent) { }
public void OnAllMutantsTested(IReadOnlyInputComponent reportComponent) { }
private IDictionary <string, JsonReportFileComponent> GenerateReportComponents(IReadOnlyInputComponent component) { Dictionary <string, JsonReportFileComponent> files = new Dictionary <string, JsonReportFileComponent>(); if (component is FolderComposite folder) { Merge(files, GenerateFolderReportComponents(folder)); } else if (component is FileLeaf file) { Merge(files, GenerateFileReportComponents(file)); } return(files); }
public void OnMutantsCreated(IReadOnlyInputComponent reportComponent) { // This reporter does not report during the testrun }
public void OnMutantsCreated(IReadOnlyInputComponent reportComponent) { // For implementing interface }