stryker-mutator / stryker-net

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

Orchestrate invocations #2747

Closed dupdob closed 9 months ago

dupdob commented 9 months ago

Revise and extend mutation orchestration to simplify the implementation of mutators (e.g: LinqMutator, ConditionalMutator...)

dupdob commented 9 months ago

Overall design changes

Increase granularity for syntax node 'scopes' by adding MemberAccess and 'Member` on top of expression, statement and block:

  1. Member (new): current largest scope: matches a class member or a local function. This scope ensure mutations cannot leak between members. Mutations cannot be injected/controlled at this level
  2. Block: a block of statement(s) (can be empty). Mutation can be injected and controlled at this level via a if statement (between normal and mutated block). Typically used for mutations impacting local declaration (eg array initializer)
  3. Statement: a C# statement. Mutation can be injected and controlled at this level via a if statement (between the normal and mutated statement). Used for the empty statement mutator or expression level mutations that cannot be controlled via a conditional operator, such as: pre/post unary operators
  4. Expression: a C# expression. Account for more than 90% of syntax nodes (almost everything is an expression). Most expressions can be controlled via the conditional operator (a.k.a ternary operator). Exceptions must be declared as MemberAcess
  5. MemberAccess (new): finest scope: describe the access path to class members (eg. System.String.Empty). Mutations cannot be controlled at this level and must be controlled at the enclosing expression level.

I added dedicated orchestrators for the following nodes: MemberAccessSyntax, MemberBindingSyntax, ConditionalAccessSyntax and InvocationExpressionSyntax. Also revised and simplified some existing orchestrators.

Note that this PR may have marginal impact on mutation test results: it is possible the new design may result in more reliable mutations for some edge case. It is difficult to assess. For sure, most, if not all, users will not see any significant change.

dupdob commented 9 months ago

other consideration: as it was a significant refactoring, I reviewed all mutators to see if they would benefit from this change. Also took the opportunity to switch impacted files to filescope namespace, as it appears to be impossible to do it fro the whole project via a dedicated PR

sonarcloud[bot] commented 9 months ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

87.4% 87.4% Coverage
0.0% 0.0% Duplication

richardwerkman commented 9 months ago

@dupdob thanks for your help :) Now the road is clear toward #1031

dupdob commented 9 months ago

thanks @richardwerkman, this means a lot to me. Note that I am working on a document detailing the design, because it is still non trivial and there are still axis of improvements.