-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added since on line level changes #3086
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
|
@@ -55,17 +54,37 @@ public IEnumerable<IMutant> FilterMutants(IEnumerable<IMutant> mutants, IReadOnl | |
IEnumerable<IMutant> filteredMutants; | ||
|
||
// A non-csharp file is flagged by the diff result as modified. We cannot determine which mutants will be affected by this, thus all mutants have to be tested. | ||
if (_diffResult.ChangedTestFiles is { } && _diffResult.ChangedTestFiles.Any(x => !x.EndsWith(".cs"))) | ||
if (_diffResult.ChangedTestFiles is { } && _diffResult.ChangedTestFiles.Keys.Any(x => !x.EndsWith(".cs"))) | ||
{ | ||
_logger.LogDebug("Returning all mutants in {RelativePath} because a non-source file is modified", file.RelativePath); | ||
return SetMutantStatusForNonCSharpFileChanged(mutants); | ||
} | ||
|
||
// If the diff result flags this file as modified, we want to run all mutants again | ||
if (_diffResult.ChangedSourceFiles != null && _diffResult.ChangedSourceFiles.Contains(file.FullPath)) | ||
if (_diffResult.ChangedSourceFiles != null && _diffResult.ChangedSourceFiles.Keys.Contains(file.FullPath)) | ||
{ | ||
foreach (var mutant in mutants) | ||
{ | ||
foreach (var line in _diffResult.ChangedSourceFiles[file.FullPath]) | ||
{ | ||
|
||
var actualLineSpan = mutant.Mutation.OriginalNode.GetLocation().GetMappedLineSpan(); | ||
|
||
_logger.LogDebug("Original line span is found to be {actualLineSpan}", actualLineSpan); | ||
var start = actualLineSpan.Span.Start.Line; | ||
var end = actualLineSpan.Span.Start.Line; | ||
if (start <= line && line <= end) | ||
{ | ||
if (mutant.ResultStatus != MutantStatus.NoCoverage) | ||
{ | ||
mutant.ResultStatus = MutantStatus.Pending; | ||
mutant.ResultStatusReason = "Mutant changed compared to target commit"; | ||
} | ||
} | ||
} | ||
} | ||
_logger.LogDebug("Returning all mutants in {RelativePath} because the file is modified", file.RelativePath); | ||
return SetMutantStatusForFileChanged(mutants); | ||
return mutants; | ||
} | ||
else | ||
{ | ||
|
@@ -74,12 +93,30 @@ public IEnumerable<IMutant> FilterMutants(IEnumerable<IMutant> mutants, IReadOnl | |
|
||
// If any of the tests have been changed, we want to return all mutants covered by these testfiles. | ||
// Only check for changed c# files. Other files have already been handled. | ||
if (_diffResult.ChangedTestFiles != null && _diffResult.ChangedTestFiles.Any(file => file.EndsWith(".cs"))) | ||
if (_diffResult.ChangedTestFiles != null && _diffResult.ChangedTestFiles.Keys.Any(file => file.EndsWith(".cs"))) | ||
{ | ||
filteredMutants = ResetMutantStatusForChangedTests(mutants); | ||
foreach (var mutant in mutants) | ||
{ | ||
foreach (var line in _diffResult.ChangedTestFiles[file.FullPath]) | ||
{ | ||
var actualLineSpan = mutant.Mutation.OriginalNode.GetLocation().GetMappedLineSpan(); | ||
|
||
_logger.LogDebug("Original line span is found to be {actualLineSpan}", actualLineSpan); | ||
var start = actualLineSpan.Span.Start.Line; | ||
var end = actualLineSpan.Span.Start.Line; | ||
if (start <= line && line <= end) | ||
{ | ||
if (mutant.ResultStatus != MutantStatus.NoCoverage) | ||
{ | ||
mutant.ResultStatus = MutantStatus.Pending; | ||
mutant.ResultStatusReason = "Mutant changed compared to target commit"; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The status reason is not correct, the mutant has not been changed but a covering test has been changed
Comment on lines
+109
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you not use ResetMutantStatusForChangedTests? |
||
} | ||
} | ||
} | ||
} | ||
|
||
return filteredMutants; | ||
return mutants; | ||
} | ||
|
||
private static IEnumerable<IMutant> SetNotRunMutantsToIgnored(IEnumerable<IMutant> mutants) | ||
|
@@ -128,7 +165,7 @@ private IEnumerable<IMutant> ResetMutantStatusForChangedTests(IEnumerable<IMutan | |
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.Keys.Any(changedTestFile => coveringTest.TestFilePath == changedTestFile | ||
|| string.IsNullOrEmpty(coveringTest.TestFilePath)))) | ||
{ | ||
mutant.ResultStatus = MutantStatus.Pending; | ||
|
@@ -141,3 +178,4 @@ private IEnumerable<IMutant> ResetMutantStatusForChangedTests(IEnumerable<IMutan | |
return filteredMutants; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you not use SetMutantStatusForFileChanged?