-
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
Open
shivambagadia23
wants to merge
2
commits into
stryker-mutator:master
Choose a base branch
from
shivambagadia23:feat/add-since-on-line-level
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Stryker.Core.DiffProviders; | ||
|
||
public class DiffResult | ||
namespace Stryker.Core.DiffProviders | ||
{ | ||
public ICollection<string> ChangedTestFiles { get; set; } | ||
public ICollection<string> ChangedSourceFiles { get; set; } | ||
public class DiffResult | ||
{ | ||
public IDictionary<string, List<int>> ChangedTestFiles { get; set; } | ||
public IDictionary<string, List<int>> ChangedSourceFiles { get; set; } | ||
} | ||
} |
137 changes: 86 additions & 51 deletions
137
src/Stryker.Core/Stryker.Core/DiffProviders/GitDiffProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,116 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.IO; | ||
using System.Linq; | ||
using LibGit2Sharp; | ||
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions; | ||
using Spectre.Console; | ||
using Stryker.Abstractions.Exceptions; | ||
using Stryker.Abstractions.Options; | ||
using Stryker.Core.Baseline.Providers; | ||
using Stryker.Core.Mutants; | ||
using Stryker.Utilities; | ||
|
||
namespace Stryker.Core.DiffProviders; | ||
|
||
public class GitDiffProvider : IDiffProvider | ||
namespace Stryker.Core.DiffProviders | ||
{ | ||
public TestSet Tests { get; } | ||
private readonly IStrykerOptions _options; | ||
private readonly IGitInfoProvider _gitInfoProvider; | ||
|
||
public GitDiffProvider(IStrykerOptions options, TestSet tests, IGitInfoProvider gitInfoProvider = null) | ||
public class GitDiffProvider : IDiffProvider | ||
{ | ||
Tests = tests; | ||
_options = options; | ||
_gitInfoProvider = gitInfoProvider ?? new GitInfoProvider(options); | ||
} | ||
|
||
public DiffResult ScanDiff() | ||
{ | ||
var diffResult = new DiffResult() | ||
{ | ||
ChangedSourceFiles = new Collection<string>(), | ||
ChangedTestFiles = new Collection<string>() | ||
}; | ||
|
||
// A git repository has been detected, calculate the diff to filter | ||
var repository = _gitInfoProvider.Repository; | ||
var commit = _gitInfoProvider.DetermineCommit(); | ||
public TestSet Tests { get; } | ||
private readonly IStrykerOptions _options; | ||
private readonly IGitInfoProvider _gitInfoProvider; | ||
|
||
if (commit == null) | ||
public GitDiffProvider(IStrykerOptions options, TestSet tests, IGitInfoProvider gitInfoProvider = null) | ||
{ | ||
throw new InputException("Could not find a commit to diff. Please check you have provided the correct committish for 'since'."); | ||
Tests = tests; | ||
_options = options; | ||
_gitInfoProvider = gitInfoProvider ?? new GitInfoProvider(options); | ||
} | ||
|
||
var testProjects = _options.TestProjects.ToList(); | ||
if (!testProjects.Any()) | ||
public DiffResult ScanDiff() | ||
{ | ||
testProjects.Add(_options.ProjectPath); | ||
} | ||
var diffResult = new DiffResult() | ||
{ | ||
ChangedSourceFiles = new Dictionary<string, List<int>>(), | ||
ChangedTestFiles = new Dictionary<string, List<int>>(), | ||
}; | ||
|
||
var testPaths = testProjects | ||
.Select(testProject => testProject.EndsWith(Path.DirectorySeparatorChar) | ||
? testProject | ||
: testProject + Path.DirectorySeparatorChar) | ||
.ToArray(); | ||
// A git repository has been detected, calculate the diff to filter | ||
var repository = _gitInfoProvider.Repository; | ||
var commit = _gitInfoProvider.DetermineCommit(); | ||
|
||
foreach (var patchChanges in repository.Diff.Compare<Patch>(commit.Tree, DiffTargets.WorkingDirectory)) | ||
{ | ||
var diffPath = FilePathUtils.NormalizePathSeparators(Path.Combine(_gitInfoProvider.RepositoryPath, patchChanges.Path)); | ||
if (commit == null) | ||
{ | ||
throw new InputException("Could not find a commit to diff. Please check you have provided the correct committish for 'since'."); | ||
} | ||
|
||
if (testPaths.Any(testPath => diffPath.StartsWith(testPath))) | ||
var testProjects = _options.TestProjects.ToList(); | ||
if (!testProjects.Any()) | ||
{ | ||
diffResult.ChangedTestFiles.Add(diffPath); | ||
testProjects.Add(_options.ProjectPath); | ||
} | ||
else | ||
|
||
var testPaths = testProjects | ||
.Select(testProject => testProject.EndsWith(Path.DirectorySeparatorChar) | ||
? testProject | ||
: testProject + Path.DirectorySeparatorChar) | ||
.ToArray(); | ||
|
||
foreach (var patchChanges in repository.Diff.Compare<Patch>(commit.Tree, DiffTargets.WorkingDirectory)) | ||
{ | ||
diffResult.ChangedSourceFiles.Add(diffPath); | ||
var diffPath = FilePathUtils.NormalizePathSeparators(Path.Combine(_gitInfoProvider.RepositoryPath, patchChanges.Path)); | ||
|
||
if (testPaths.Any(testPath => diffPath.StartsWith(testPath))) | ||
{ | ||
for (var i = 0; i < patchChanges.AddedLines.Count; i++) | ||
{ | ||
if (!diffResult.ChangedTestFiles.ContainsKey(diffPath)) | ||
{ | ||
diffResult.ChangedTestFiles.Add(diffPath, [patchChanges.AddedLines[i].LineNumber]); | ||
|
||
} | ||
else | ||
|
||
{ | ||
var entry = diffResult.ChangedTestFiles[diffPath]; | ||
entry.Add(patchChanges.AddedLines[i].LineNumber); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if (patchChanges.AddedLines.Count > 0) | ||
{ | ||
for (var i = 0; i < patchChanges.AddedLines.Count; i++) | ||
{ | ||
if (!diffResult.ChangedSourceFiles.ContainsKey(diffPath)) | ||
{ | ||
diffResult.ChangedSourceFiles.Add(diffPath, [patchChanges.AddedLines[i].LineNumber]); | ||
|
||
} | ||
else | ||
|
||
{ | ||
var entry = diffResult.ChangedSourceFiles[diffPath]; | ||
entry.Add(patchChanges.AddedLines[i].LineNumber); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
RemoveFilteredOutFiles(diffResult); | ||
|
||
return diffResult; | ||
} | ||
RemoveFilteredOutFiles(diffResult); | ||
|
||
private void RemoveFilteredOutFiles(DiffResult diffResult) | ||
{ | ||
foreach (var glob in _options.DiffIgnoreChanges.Select(d => d.Glob)) | ||
return diffResult; | ||
} | ||
|
||
private void RemoveFilteredOutFiles(DiffResult diffResult) | ||
{ | ||
diffResult.ChangedSourceFiles = diffResult.ChangedSourceFiles.Where(diffResultFile => !glob.IsMatch(diffResultFile)).ToList(); | ||
diffResult.ChangedTestFiles = diffResult.ChangedTestFiles.Where(diffResultFile => !glob.IsMatch(diffResultFile)).ToList(); | ||
foreach (var glob in _options.DiffIgnoreChanges.Select(d => d.Glob)) | ||
{ | ||
diffResult.ChangedSourceFiles = diffResult.ChangedSourceFiles.Where(diffResultFile => !glob.IsMatch(diffResultFile.Key)).ToDictionary(); | ||
diffResult.ChangedTestFiles = diffResult.ChangedTestFiles.Where(diffResultFile => !glob.IsMatch(diffResultFile.Key)).ToDictionary(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 did we move these inside class?
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.
@inishantmishra We did not change anything there it was like that only