Skip to content

Commit

Permalink
fix(since): Retest all mutants covered by tests for which we cannot d…
Browse files Browse the repository at this point in the history
…etermine 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 <[email protected]>
Co-authored-by: Rouke Broersma <[email protected]>
Co-authored-by: Rouke Broersma <[email protected]>
  • Loading branch information
4 people authored Jun 7, 2024
1 parent 9c06c53 commit c68c46c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/Stryker.Core/Stryker.Core/MutantFilters/SinceMutantFilter.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using Stryker.Core.DiffProviders;
using Stryker.Core.Logging;
using Stryker.Core.Mutants;
using Stryker.Core.Options;
using Stryker.Core.ProjectComponents;
using System.Collections.Generic;
using System.Linq;

namespace Stryker.Core.MutantFilters
{
Expand Down Expand Up @@ -120,10 +120,15 @@ private IEnumerable<Mutant> ResetMutantStatusForChangedTests(IEnumerable<Mutant>

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";
Expand Down
2 changes: 1 addition & 1 deletion src/Stryker.Core/Stryker.Core/Mutants/TestSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public void RegisterTests(IEnumerable<TestDescription> tests)

public void RegisterTest(TestDescription test) => _tests[test.Id] = test;

public IEnumerable<TestDescription> Extract(IEnumerable<Guid> ids) => ids.Select(i => _tests[i]);
public IEnumerable<TestDescription> Extract(IEnumerable<Guid> ids) => ids?.Select(i => _tests[i]) ?? Enumerable.Empty<TestDescription>();
}
}

0 comments on commit c68c46c

Please sign in to comment.