stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.75k stars 176 forks source link

Mutate expression bodied methods to empty body #2798

Open NBlackout opened 7 months ago

NBlackout commented 7 months ago

Describe the bug No statement removal mutant is being generated for expression-bodied methods (=> [...] instead of { [...] })

Logs expression-body.zip statement-body.zip

Expected behavior I was expecting both method syntaxes to behave similarly for mutant detection/generation.
We use this expression-bodied syntax a lot for one-liner (props, methods, etc.) so this bug (or feature?) is quite important for us.
The workaround would be to force statement body everywhere in our solution, or at least for project under tests.

Desktop (please complete the following information):

Additional context Love mutation testing, love the tool, kudos !

NBlackout commented 7 months ago

This issue might be a duplicate of #134 (sorry I only checked for opened issues). I will read in detail its content 👀

NBlackout commented 7 months ago

From what I understood, ternary operators are properly handled thanks to #17 (which #134 is marked duplicate of, not sure why because issues were not exactly the same even though kinda related). I would say expression-bodied syntax handling can still be improved.

I can provide more information if necessary, or even a simple project with both syntaxes 🙏

dupdob commented 7 months ago

Yes, can you please provide more explicit expectations and/or source code/samples. That would help us provide more accurate answer.

  1. yes, there is no statement mutation for expression bodied method as those do not have any statement inside. We could either extend statement mutator to cover for his or add a new dedicated mutator (my favorite). Please note that different users have different expectations on what is a good mutator, so nothing is as obvious as one would like.
  2. it also affect block mutator: an expression body is not a block statement
  3. all other mutators are applied when relevant.

Hope this helps.

NBlackout commented 7 months ago

Thanks for the feedback ! I'm preparing a sample 👍

NBlackout commented 7 months ago

I can reproduce this issue even with a simple { return 3; } and => 3. You can run mutation test using the project under test launchSettings.json.
Please let me know if setup is incomplete and I will make sure to include more details.

Have a great day 😁

ExpressionBodiedMutationTests.zip