Skip to content
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

feat(MutateArgument): Allow the user to specify which files to mutate. #662

Merged
merged 55 commits into from
Sep 5, 2019
Merged

feat(MutateArgument): Allow the user to specify which files to mutate. #662

merged 55 commits into from
Sep 5, 2019

Conversation

anhaehne
Copy link

@anhaehne anhaehne commented Aug 13, 2019

I created a new IMutantFilter that allow to specify which files should be in- or excluded as described in #322.

The files-to-excluded parameter is now marked as deprecated but the changes should be fully backwards compatible. If files-to-excluded is specified their paths will be converted to exclude file patterns in the StrykerOptions.

New configuration section:

Mutate

To specify which files should be mutated you can use file pattern to in- or excluded files or even only parts of a files. By default all files are included.

dotnet stryker --mutate "['C:/Repos/MyProject/MyFile.cs']"
dotnet stryker -m "['C:/Repos/MyProject/MyFile.cs']"

The patterns support globbing syntax to allow wildcards.

dotnet stryker --mutate "['**/*Services.cs']"
dotnet stryker -m "['**/*Services.cs']"

You can add an ! in front of the pattern to exclude all files that match the pattern.

dotnet stryker --mutate "['!**/*Factory.cs']"
dotnet stryker -m "['!**/*Factory.cs']"

When only exclude patterns are provided, all files will be included that do not match any exclude pattern. If both, include and exclude patterns, are provided, only the files that match an include pattern but not also an exclude pattern will be included. The order of the patterns is irrelevant.

Example:

Patterns File Will be mutated
[] MyFolder/MyFactory.cs Yes
[] MyFolder/MyService.cs Yes
['**/*.*'] MyFolder/MyFactory.cs Yes
['**/*.*'] MyFolder/MyService.cs Yes
['!**/MyFactory.cs'] MyFolder/MyFactory.cs No
['!**/MyFactory.cs'] MyFolder/MyService.cs Yes
['!**/MyFactory.cs', '**/My*.cs'] MyFolder/MyFactory.cs No
['!**/MyFactory.cs', '**/My*.cs'] MyFolder/MyService.cs Yes

To allow more fine grained filtering you can also specify the span of text that should be in- or excluded. A span is defined by the indices of the first character and the last character.

dotnet stryker --mutate "['MyFolder/MyService.cs{10..100}']"
dotnet stryker -m "['MyFolder/MyService.cs{10..100}']"

anhaehne and others added 25 commits July 31, 2019 12:00
* Added support for wild cards
* Added documentation for the new command line argument
build(deps): bump Microsoft.CodeAnalysis.CSharp in /integrationtest (…
@rouke-broersma
Copy link
Member

@anhaehne The problem is this:

image

You're not normalizing the filePattern, so it will never accurately match.

@richardwerkman I'm feeling like our decision to normalize all filepaths to the current filesystem is maybe the wrong choice. Perhaps we should agree on one style of filepaths to be used internally by stryker (including in filters and such) and then only normalize to the current filesystem filepaths when we're interacting with the filesystem. Then in the rest of stryker we can be sure what filepaths should look like, and always convert to "StrykerInternalPathSeperator" or something.

@anhaehne
Copy link
Author

So should we just normalize all paths to forwardslash ('/') since both windows and *nix understand those?

@rouke-broersma
Copy link
Member

So should we just normalize all paths to forwardslash ('/') since both windows and *nix understand those?

If that works, I am okay with that solution. How about you @richardwerkman ?

It does mean we need to normalize every single path or path filter going in and out of stryker. We may be missing some cases right now that accidentally work fine but might break if we change how we normalize.

@anhaehne
Copy link
Author

anhaehne commented Aug 29, 2019

I've looked at the code of System.IO.Path and microsoft seems to just replace all forward and backward slashes with backward slashes on windows [1].

On unix it's just forwards slashes since backwards slashes are not allowed anyways. [2].

When normalizing we should probably just replace both with Path.DirectorySeparatorChar so we can still use methods like Path.Combine without the need to normalize the result every time.

So path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar) should work for every platform.

@rouke-broersma
Copy link
Member

I've looked at the code of System.IO.Path and microsoft seems to just replace all forward and backward slashes with backward slashes on windows [1].

On unix it's just forwards slashes since backwards slashes are not allowed anyways. [2].

When normalizing we should probably just replace both with Path.DirectorySeparatorChar so we can still use methods like Path.Combine without the need to normalize the result every time.

So path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar) should work for every platform.

Ah I did not realize Path.AltDirectorySeparatorChar was / on windows. That is almost what we do already in FilePathUtils.Convert but it would be would be more clean to use AltDirectorySeparatorChar.

@anhaehne
Copy link
Author

anhaehne commented Sep 2, 2019

Ok i found the reason one integration test did work locally on my machine. I renamed a file but only changed the casing, which git obviously didn't care about. 😄 So if there are no more change request we can complete this PR.

@rouke-broersma
Copy link
Member

Awesome! 👍 Will take a look as soon as I have time.

@rouke-broersma
Copy link
Member

@anhaehne While testing locally on a full framework project from my company stryker crashed in an unexpected way while mutating. The latest released version of stryker does not have this problem. I'm currently investigating whether the problem is with this PR or with master.

@anhaehne
Copy link
Author

anhaehne commented Sep 3, 2019

If you got a log or a way to reproduce it, let me know.

@rouke-broersma
Copy link
Member

The issue seems to be with master, but since I can't validate whether this change works on my internal project I'm not gonna merge it until we fix master. I don't see any changes neccesary in the PR at this time though so it should get merged after.

@rouke-broersma
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants