-
Notifications
You must be signed in to change notification settings - Fork 250
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
Ignore specific mutations #1472
Comments
This is very important to me. I have so many props in my vue components library. Example
And Stryker applies ObjectLiteral mutator to prop definition. I do not need to test this case, because this is just a some kind of type definition. |
Note: mutation switching is tracked in #1514. Once we have that (and one parser and AST), this feature should be easier to implement. Let's keep this in mind when we implement #1514
How would you prefer to exclude these? I would guess that you don't want to add |
Yeah, it would be cool to exclude such cases by regexp. Or by custom filter function that will take AST node as argument with possibility to check parent nodes |
Nice one @kmdrGroch! That looks promising! What is your end goal regarding syntax and features? |
@simondel I am going to make features like these: these 2 are to enable/disable globally (In a current file of course) these 2 are fully implemented right now + I have also been working on disabling the first occurrence of given mutator like Any feedback is nice |
Maybe you could use the same syntax as
|
looks nice !
|
So after rethinking it I think I will make options like: // stryker:on - globally switches mutations on // stryker:on ArrayLiteral // stryker:next-on |
@nicojs We have had 'ignoring' mutators for a while now. We mark the mutations as 'skipped' status instead of ignore. We should probably agree on using the same status name to indicate excluded mutations. |
Thanks for taking the effort to work on this highly requested feature @tsachis Keep in mind that a user-facing API has not yet been finalized. This will most likely mean rework for your PR, or it could mean that your PR will not be merged at all because the way your solution works may be radically different from the defined requirements. |
considering exact post made by @simondel (mean this issue), I think this branch is the closest one to solve it: https://github.com/kmdrGroch/stryker/tree/fix-1472. Tho I had some problems with typescript part (Javascript part works just fine) |
@kmdrGroch Using inline comments to exclude mutations is a very useful feature. Adding a way to globally exclude patterns is another important feature that can cover that use case, and help users improve process performance and filter out noise from the output. @simondel the above PR is just a POC. I understand the final API can be completely different, and I would be happy to contribute and push this feature forward. |
we could think of making so we ignore phrases starting from sth, like Cheers |
Looking at the checklist of #1514, it's going to take quite a bit to get this into a release. Hopefully I won't create many mutants by the time I can use stryker. Keep it up 💪 |
@Ranguna if it is super necessary for your project, I could try implementing it specifically for your use (but I need to know which mutator you are using and what features you want), but it wouldn't be supported by Stryker officially. |
Thank you for the incredible support @kmdrGroch! It's not really super necessary. Stryker would just be a nice thing to have but we can live without it for the time being. Unfortunately I'll be using the mutator that you've been having problems with, the typescript mutator. My use case would be something like this:
It would be nice if I could ignore mutations on As much as I'm thankful, I don't know if having a specific build for my project would be a good idea since I'm not sure how I'd handle future Stryker (break/conflicting) updates later on. Again, thank you very much for the support! |
Another reason is the sometimes there is more than one way to get the same value. Consider:,
Here. the boundary values 0 an 1 both 'work' through 2 paths, so one mutation (> to >= or < to <=) can't actually force a failure. With some herculean effort (due to typescript and legacy testing code), I could maybe spy on the standard lib, to determine which path and 'error' in the test if the 'wrong' path is taken, but really, the point is that 0 -> 0, and 1 -> 255. It doesn't matter to me which rule is uses. So being able to say 'ignore this' isn't putting me at risk I am unwilling to take. |
I guess that could count as equivalent mutant. We covered it in documentation :) |
Yes, it's covered here: https://stryker-mutator.io/docs/mutation-testing-elements/equivalent-mutants/ It is a valid case for exclusion of the mutant, we should be able to cover this feature after the v5 release (which will be ~May) |
If not too late, I see the project already uses
I basically have the same issue as logging, but with the |
@rouke-broersma what syntax are you guys using to ignore mutants? |
|
Thanks @rouke-broersma In short, syntax for Stryker.NET:
This is pretty extensive, but we can choose to start by implementing parts of it. NB: I think |
The feature has not yet been released. You can discuss the specific semantics with @dupdob as I personally don't mind either once or next. |
I picked I though a lot about this, and
In any case, changing this is not difficult. We could even accept both forms, assuming the meaning is the same. One last thing: trying to implement a 'next-line-only' feature would require a lot of work, as in C#, like in other C derived languages, |
This feature got released in StrykerJS 5.4. See https://stryker-mutator.io/docs/stryker-js/disable-mutants#using-a--stryker-disable-comment for information. Examples: function max(a, b) {
// Stryker disable next-line EqualityOperator
return a < b ? b : a;
} // Stryker disable all
function max(a, b) {
return a < b ? b : a;
}
// Stryker restore all
function min(a, b) {
return a < b ? b : a;
} // Stryker disable EqualityOperator,ObjectLiteral: We'll implement tests for these next sprint
function max(a, b) {
return a < b ? b : a;
} // Stryker disable all
function max(a, b) {
// Stryker restore EqualityOperator
return a < b ? b : a;
} |
Nice to see this feature! function max(a, b) {
// stryker-disable-next-line EqualityOperator
return a < b ? b : a;
} vs function max(a, b) {
// Stryker disable next-line EqualityOperator
return a < b ? b : a;
} |
I personally think the comment is technical enough. You would have to write pretty strange comments if you accidentally write an ignore comment... It's also something we need to align on with Stryker.NET, Stryker4s and other future Stryker versions and they're already using this syntax 🤷♂️ |
Nice to see this feature! But commenting whenever we use certain pattern would be a hard task to do particularly in case of large repo with recurring pattern. Do we have any option in configuration that will enable us to ignore certain patterns. Like disabling objectLiteral mutant where .propType is defined. We can consider the same example in this issue #1653 |
In some projects, there are mutations that users want to exclude. An example of this is logging. We've had multiple questions of users that do not want to test (some) logging.
Why?
Why not?
Proposed implementation
We can use inline comments to disable certain mutators or disable Stryker entirely. For example:
// stryker-mutator disable next
or/* stryker-mutator disable next */
: this would disable all mutators Stryker on the next AST node (statement)// stryker-mutator disable next ['StringLiteral']
or/*stryker-mutator disable next ['StringLiteral']*/
: this would only disable theStringLiteral
mutator for the next AST node (statement).During the mutating process, we could keep track of the comments. We should still generate the mutants, but output them as
"MutantState.Ignored"
(new state) so it can be reported accordingly by different reporters.Timeline
We want to introduce a parser API to support an easy and safe way to make the exclusions. This issue will lay the groundwork for it: #1893. Before this is done, we will not support this option.
This main post will be kept up to date with the latest info
Related issues:
#1174, #1470, #1464, #1653
Related pull requests:
#1810, #1912, #2084
The text was updated successfully, but these errors were encountered: