Replies: 3 comments 1 reply
-
How to improve on this?One can think of several ways to improve on this, depending on the end result. Note that those are not mutually exclusive and be added next to another for a better experience at the end. 1. TransparencyThe objective is to report the existence of this helpers, thus helping users understand what is actually hapenning.
2. Inject them only when necessary.The objective is to reduce the number of situations where helpers are injected:
3. Remove the needs for themThe idea here is to get read of them altogether. This would be the best experience, assuming it can be done.
|
Beta Was this translation helpful? Give feedback.
-
What's nextI have posted this list for several reasons:
|
Beta Was this translation helpful? Give feedback.
-
Thank you for this helpful explanation! For issue #2283, I've been working on altering the block mutator to add the
Here, you would actually prefer the if-block to be removed entirely, because it would compile anyways and has a different effect than replacing the
Something similar might also be useful for the Statement mutator, but I haven't looked into that mutator yet. I guess that if those two mutators can deal with return statements properly, we no longer need to use the |
Beta Was this translation helpful? Give feedback.
-
Intro
As of today, Stryker.Net injects some non visible helpers. Those are non visible because they are not part of the mutation report, and helpers because they permit some mutations to compile properly.
To be more specific, having them prevent triggering Safe mode which would result in all mutations from one (or more) method(s) to be marked as compile error.
I opened this discussion to explain this in details and potentially discuss how this could be improved.
Safe mode and associated problems.
Stryker.Net uses a attempt and remove approach to mutation: all possible mutations are generated and injected in the (in-memory) source files and then compiled. After that, Stryker removes mutations that result in compilation error (and mark them as compilation error).
As Stryker compiles all mutations at once, it needs a way to identify which mutation triggered each compilation error. The association is made thanks to the error location: if an error happens within the mutation, the mutation is removed and voilà , the error will be gone on next build attempt.
But some errors happen outside any mutation, those are often error related to variables (use of uninitialized variables and related) or to flow control (return missing and related).
These errors are triggered by mutations impacting code flow control (
if
,while
,for
....).As Stryker does not know which mutation triggers this kind of error, it removes every mutations from the method (or construction, function...). I understand it may be a bit drastic, but first versions of Stryker would simply stop when this happened.
C# is too smart for us
Note that this problem arises because the C# compiler does a good job at static analysis and therefore allow some constructions that would not be possible otherwise. One of the best example is return elision, such as:
Helpers
Helpers are injected to limit the triggering of same mode. As of today, two exist:
return default;
statement is injected at the end of a method if it is notvoid
and does not have a return as a last statement. It prevents the missing return error.default
at the start of the method. It prevents any 'out parameters value has not been set before returning' error. Those are injected in every method with parametersWhy are those invisible
As there is no sure way to detect when an error could happen, these helpers are injected everywhere they may be necessary. As they are not related to any specific mutation, they do not appear in the report.
There are side effect
The major drawback of these, is that they 'fix' mutations that would otherwise be legitimate compilation errors. And then users wonder why some mutations are reported as survived or killed when they should haven been flagged as compilation errors.
Beta Was this translation helpful? Give feedback.
All reactions