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

Add new --git-diff-lines option to generate Mutants only for the changed *lines* #1632

Merged
merged 2 commits into from Jan 3, 2022

Conversation

maks-rafalko
Copy link
Member

@maks-rafalko maks-rafalko commented Dec 30, 2021

I've posted a question recently in twitter (https://twitter.com/infection_php/status/1475841561695072259) asking what is the most wanted feature needed in Infection for developers.

One of the interesting feature request was to mutate only changed/added lines (note: currently in master as a minimum, we can mutate only added/changed files by --git-diff-filter=AM)

So, here is an implementation of the new option - --git-diff-lines that parsers git diff output, finds changed/added lines and filters out all mutants that are not for these lines.

This option automatically mutates only Added and Modified files (--git-diff-filter=AM under the hood).

Useful to check how your changes impacts MSI in a feature branch. Useful for those who do not want / can't write tests for the whole legacy file, but wants to cover their own changes.

@Ocramius - this is your feature request, if you have some time, please help us testing on one of your projects. I've prepared a PHAR for this PR:

infection.phar.zip

How to use (as an example):

infection.phar --git-diff-lines -j4  -s 

by default it does a diff with master branch, but this can be changed:

infection.phar --git-diff-lines --git-diff-base=main -j4  -s 

…hanged *lines*

This option automatically mutants only **A**dded and **M**odified files, and finds and mutates only changed/created lines.

Useful to check how your changes impacts MSI in a feature branch
@maks-rafalko maks-rafalko added DX Developer Experience Feature labels Dec 30, 2021
@maks-rafalko maks-rafalko added this to the next milestone Dec 30, 2021
@guidobonuzzi
Copy link

Thanks, @maks-rafalko, this is fantastic! With this solution, I can check the MSI of my branch in less than 20 seconds instead of minutes.

Impressed!

I also tried the --git-diff-base option but it crashed with

In RunCommand.php line 420:
                                                            
  Cannot pass "--git-diff-base" without "--git-diff-filter"

@maks-rafalko
Copy link
Member Author

I also tried the --git-diff-base option but it crashed with

fixed! Here is a new PHAR

infection.phar.zip

Happy new Year!

Copy link

@guidobonuzzi guidobonuzzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@maks-rafalko maks-rafalko changed the title Add new --git-diff-lines option to generated Mutants only for the changed *lines* Add new --git-diff-lines option to generate Mutants only for the changed *lines* Jan 3, 2022
@maks-rafalko maks-rafalko merged commit e55f980 into master Jan 3, 2022
@maks-rafalko maks-rafalko deleted the feature/git-diff-lines branch January 3, 2022 23:39
@maks-rafalko
Copy link
Member Author

Thanks for testing it, @guidobonuzzi. Let's get it merged.

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

Successfully merging this pull request may close these issues.

None yet

2 participants