public JsonReportFileComponent(FileLeaf file, ILogger logger = null) { var log = logger ?? ApplicationLogging.LoggerFactory.CreateLogger <JsonReportFileComponent>(); Source = file.SourceCode; Language = "cs"; Mutants = new HashSet <JsonMutant>(new UniqueJsonMutantComparer()); foreach (var mutant in file.Mutants) { var jsonMutant = new JsonMutant { Id = mutant.Id.ToString(), MutatorName = mutant.Mutation.DisplayName, Replacement = mutant.Mutation.ReplacementNode.ToFullString(), Location = new JsonMutantLocation(mutant.Mutation.OriginalNode.GetLocation().GetMappedLineSpan()), Status = mutant.ResultStatus.ToString() }; if (!Mutants.Add(jsonMutant)) { logger.LogWarning( $"Mutant {mutant.Id} was generated twice in file {file.RelativePath}. \n" + $"This should not have happened. Please create an issue at https://github.com/stryker-mutator/stryker-net/issues"); } } }
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); }