From c68c46cb96c4c7ee98f1ad7b9c0f92425a572e74 Mon Sep 17 00:00:00 2001 From: Mischa Vreeburg Date: Fri, 7 Jun 2024 16:59:23 +0200 Subject: [PATCH] fix(since): Retest all mutants covered by tests for which we cannot determine the filepath (#2753) * All covering unit tests that don't have a TestFilePath are marked as pending. Added shortcircuit for mutants having no covering tests * Update src/Stryker.Core/Stryker.Core/MutantFilters/SinceMutantFilter.cs --------- Co-authored-by: Mischa Vreeburg Co-authored-by: Rouke Broersma Co-authored-by: Rouke Broersma --- .../Stryker.Core/MutantFilters/SinceMutantFilter.cs | 11 ++++++++--- src/Stryker.Core/Stryker.Core/Mutants/TestSet.cs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Stryker.Core/Stryker.Core/MutantFilters/SinceMutantFilter.cs b/src/Stryker.Core/Stryker.Core/MutantFilters/SinceMutantFilter.cs index b7bef21508..b85a73ff85 100644 --- a/src/Stryker.Core/Stryker.Core/MutantFilters/SinceMutantFilter.cs +++ b/src/Stryker.Core/Stryker.Core/MutantFilters/SinceMutantFilter.cs @@ -1,4 +1,6 @@ +using System.Collections.Generic; +using System.Linq; using Microsoft.CodeAnalysis; using Microsoft.Extensions.Logging; using Stryker.Core.DiffProviders; @@ -6,8 +8,6 @@ using Stryker.Core.Mutants; using Stryker.Core.Options; using Stryker.Core.ProjectComponents; -using System.Collections.Generic; -using System.Linq; namespace Stryker.Core.MutantFilters { @@ -120,10 +120,15 @@ private IEnumerable ResetMutantStatusForChangedTests(IEnumerable foreach (var mutant in mutants) { + if (mutant.CoveringTests.IsEmpty || mutant.CoveringTests.Count == 0) + { + continue; + } var coveringTests = _tests.Extract(mutant.CoveringTests.GetGuids()); if (coveringTests != null - && coveringTests.Any(coveringTest => _diffResult.ChangedTestFiles.Any(changedTestFile => coveringTest.TestFilePath == changedTestFile))) + && coveringTests.Any(coveringTest => _diffResult.ChangedTestFiles.Any(changedTestFile => coveringTest.TestFilePath == changedTestFile + || string.IsNullOrEmpty(coveringTest.TestFilePath)))) { mutant.ResultStatus = MutantStatus.Pending; mutant.ResultStatusReason = "One or more covering tests changed"; diff --git a/src/Stryker.Core/Stryker.Core/Mutants/TestSet.cs b/src/Stryker.Core/Stryker.Core/Mutants/TestSet.cs index 2118c3ae4c..12f7f2af1d 100644 --- a/src/Stryker.Core/Stryker.Core/Mutants/TestSet.cs +++ b/src/Stryker.Core/Stryker.Core/Mutants/TestSet.cs @@ -20,6 +20,6 @@ public void RegisterTests(IEnumerable tests) public void RegisterTest(TestDescription test) => _tests[test.Id] = test; - public IEnumerable Extract(IEnumerable ids) => ids.Select(i => _tests[i]); + public IEnumerable Extract(IEnumerable ids) => ids?.Select(i => _tests[i]) ?? Enumerable.Empty(); } }