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 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}"); }
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 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)")); }
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()); } } }
private void ValidateJsonReportComponent(JsonReporter.JsonReportComponent jsonComponent, IReadOnlyInputComponent inputComponent, string health, int mutants = 0) { jsonComponent.Health.ShouldBe(health); jsonComponent.ValidMutations.ShouldBe(inputComponent.ReadOnlyMutants.Where(m => m.ResultStatus != MutantStatus.CompileError).Count()); jsonComponent.MutationScore.ShouldBe(inputComponent.GetMutationScore() ?? 0); jsonComponent.CompileErrors.ShouldBe(inputComponent.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.CompileError).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()); if (inputComponent is FolderComposite folderComponent) { var componentNameToTest = folderComponent.Name is null ? null : folderComponent.RelativePath; jsonComponent.Name.ShouldBe(componentNameToTest); jsonComponent.Source.ShouldBe(null); jsonComponent.Mutants.ShouldBe(null); jsonComponent.ChildResults.Count.ShouldBe(folderComponent.Children.Count()); } if (inputComponent is FileLeaf fileComponent) { jsonComponent.Name.ShouldBe(fileComponent.Name); 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()); var location = fileComponent.Mutants.ToArray()[i].Mutation.OriginalNode.SyntaxTree.GetLineSpan(fileComponent.Mutants.ToArray()[i].Mutation.OriginalNode.FullSpan); jsonComponent.Mutants[i].Location.Start.Line.ShouldBe(location.StartLinePosition.Line + 1); jsonComponent.Mutants[i].Location.Start.Column.ShouldBe(location.StartLinePosition.Character + 1); jsonComponent.Mutants[i].Location.End.Line.ShouldBe(location.EndLinePosition.Line + 1); jsonComponent.Mutants[i].Location.End.Column.ShouldBe(location.EndLinePosition.Character + 1); jsonComponent.Mutants[i].Status.ShouldBe(fileComponent.Mutants.ToArray()[i].ResultStatus.ToString()); } } }
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 static JsonReportComponent FromProjectComponent(IReadOnlyInputComponent component, ThresholdOptions thresholdOptions) { var report = new JsonReportComponent { Name = component.Name, DetectedMutants = component.DetectedMutants.Count(), TotalMutants = component.TotalMutants.Count(), KilledMutants = component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Killed).Count(), SurvivedMutants = component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Survived).Count(), SkippedMutants = component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Skipped).Count(), TimeoutMutants = component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.Timeout).Count(), CompileErrors = component.ReadOnlyMutants.Where(m => m.ResultStatus == MutantStatus.BuildError).Count(), MutationScore = component.GetMutationScore(), ThresholdHigh = thresholdOptions.ThresholdHigh, ThresholdLow = thresholdOptions.ThresholdLow, ThresholdBreak = thresholdOptions.ThresholdBreak, }; report.PossibleMutants = report.TotalMutants + report.SkippedMutants; if (report.MutationScore >= report.ThresholdHigh) { report.Health = "ok"; } else if (report.MutationScore <= report.ThresholdBreak) { report.Health = "danger"; } else { report.Health = "warning"; } if (component is FolderComposite folderComponent) { foreach (var child in folderComponent.Children) { report.ChildResults.Add(FromProjectComponent(child, thresholdOptions)); } } else if (component is FileLeaf fileComponent) { report.Source = fileComponent.SourceCode; foreach (var mutant in fileComponent.Mutants) { var jsonMutant = new JsonMutant { Id = mutant.Id, MutatorName = mutant.Mutation.DisplayName, Replacement = mutant.Mutation.ReplacementNode.ToFullString(), Span = new[] { mutant.Mutation.OriginalNode.SpanStart, mutant.Mutation.OriginalNode.Span.End }, Status = StrykerStatusToMutationStatus(mutant.ResultStatus) }; report.Mutants.Add(jsonMutant); } } else { throw new System.Exception("Unknown IReadOnlyInputComponent implementation"); } return(report); }