Skip to content

Commit a8c31c5

Browse files
feat: Remove excluded files from json/html reports (#3281)
* Remove excluded files from json/html reports * Remove file contents but keep file names * Remove string interpolation --------- Co-authored-by: Rouke Broersma <Rouke.Broersma@infosupport.com>
1 parent 6a79711 commit a8c31c5

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/Stryker.Core/Stryker.Core/Reporters/Json/JsonReport.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Stryker.Abstractions.Options;
44
using Stryker.Abstractions.ProjectComponents;
55
using Stryker.Abstractions.Reporting;
6+
using Stryker.Core.ProjectComponents;
67
using Stryker.Core.Reporters.Json.SourceFiles;
78
using Stryker.Core.Reporters.Json.TestFiles;
89

@@ -25,39 +26,47 @@ private JsonReport(IStrykerOptions options, IReadOnlyProjectComponent mutationRe
2526

2627
ProjectRoot = mutationReport.FullPath;
2728

28-
Merge(Files, GenerateReportComponents(mutationReport));
29+
Merge(Files, GenerateReportComponents(options, mutationReport));
2930
AddTestFiles(testProjectsInfo);
3031
}
3132

3233
public static IJsonReport Build(IStrykerOptions options, IReadOnlyProjectComponent mutationReport, ITestProjectsInfo testProjectsInfo) => new JsonReport(options, mutationReport, testProjectsInfo);
3334

34-
private IDictionary<string, ISourceFile> GenerateReportComponents(IReadOnlyProjectComponent component)
35+
private Dictionary<string, ISourceFile> GenerateReportComponents(IStrykerOptions options, IReadOnlyProjectComponent component)
3536
{
3637
var files = new Dictionary<string, ISourceFile>();
38+
3739
if (component is IFolderComposite folder)
3840
{
39-
Merge(files, GenerateFolderReportComponents(folder));
41+
Merge(files, GenerateFolderReportComponents(options, folder));
4042
}
4143
else if (component is IReadOnlyFileLeaf file)
4244
{
43-
Merge(files, GenerateFileReportComponents(file));
45+
Merge(files, GenerateFileReportComponents(options, file));
4446
}
4547

4648
return files;
4749
}
4850

49-
private IDictionary<string, ISourceFile> GenerateFolderReportComponents(IFolderComposite folderComponent)
51+
private Dictionary<string, ISourceFile> GenerateFolderReportComponents(IStrykerOptions options, IFolderComposite folderComponent)
5052
{
5153
var files = new Dictionary<string, ISourceFile>();
5254
foreach (var child in folderComponent.Children)
5355
{
54-
Merge(files, GenerateReportComponents(child));
56+
Merge(files, GenerateReportComponents(options, child));
5557
}
5658

5759
return files;
5860
}
5961

60-
private static IDictionary<string, ISourceFile> GenerateFileReportComponents(IReadOnlyFileLeaf fileComponent) => new Dictionary<string, ISourceFile> { { fileComponent.FullPath, new SourceFile(fileComponent) } };
62+
private static Dictionary<string, ISourceFile> GenerateFileReportComponents(IStrykerOptions options, IReadOnlyFileLeaf fileComponent)
63+
{
64+
if (fileComponent.IsComponentExcluded(options.Mutate))
65+
{
66+
return new Dictionary<string, ISourceFile> { { fileComponent.FullPath, SourceFile.Ignored } };
67+
}
68+
return new Dictionary<string, ISourceFile> { { fileComponent.FullPath, new SourceFile(fileComponent) } };
69+
}
6170

6271
private void AddTestFiles(ITestProjectsInfo testProjectsInfo)
6372
{

src/Stryker.Core/Stryker.Core/Reporters/Json/SourceFiles/SourceFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class SourceFile : ISourceFile
1717

1818
public SourceFile() { }
1919

20+
public static SourceFile Ignored => new() { Source = "File ignored by mutate filter", Language = "none", Mutants = new HashSet<IJsonMutant>() };
21+
2022
public SourceFile(IReadOnlyFileLeaf file, ILogger logger = null)
2123
{
2224
logger ??= ApplicationLogging.LoggerFactory.CreateLogger<SourceFile>();

0 commit comments

Comments
 (0)