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

docs(mutators): add mutant operator name proposal #1458

Merged
merged 6 commits into from
Mar 15, 2024

Conversation

nicojs
Copy link
Member

@nicojs nicojs commented Oct 22, 2021

A proposal for mutant operator names. They are loosely based on the naming scheme found in infection PHP and pitest.

The goal of each mutant operator name is to have a conclusive name that describes the mutation. I used the following naming scheme:

*NodeIdentification*[To*Replacement*]*Mutation*

  • NodeIdentification: Name the AST node being mutated.
  • Mutation: Name the mutation being done:
    1. "Removal" when the node was removed.
    2. "Negation" when a node is replaced by its opposite ¹
    3. "Boundary" when a node is replaced by a similar node to test a boundary condition (like < to <=)
    4. "Replacement" when a node is replaced by something other than the opposite or boundary.
  • Replacement (only when the mutation was "Replacement"), name the node being replaced to ²

¹ I choose to interpret the "opposite" loosely here. When in doubt, I decided to use it. For example: "AdditionAssignmentNegation" for += to -= and "AllMethodCallNegation" for All to Any.
² When naming the replacement node, I removed "expression", "operator" and "method call" for brevity. For example: "SingleOrDefaultMethodCallToFirstOrDefaultReplacement" and "NullishCoalescingOperatorToLogicalAndReplacement".

When identifying AST nodes, I did lean towards the JavaScript node types. Please verify if this is OK for C# and Scala, if not, please correct me. I used the following sources:

We also have mutations that replace a part of a node, instead of the node itself. I had to invent logical names for them. They are summed up here:

  • "FilledStringLiteralToEmptyReplacement" and friends
  • "ObjectLiteralPropertiesRemoval"
  • "ArrayConstructorItemsRemoval"
  • "OptionalMemberExpressionOptionalRemoval"
  • "OptionalComputedMemberExpressionOptionalRemoval"
  • "OptionalCallExpressionOptionalRemoval"

I didn't do all of them, because I first want feedback on these names.

| MaxMethodCallNegation | `a.max` | `a.min` |
| MinMethodCallNegation | `a.min` | `a.max` |
| MaxByMethodCallNegation | `a.maxBy(b)` | `a.minBy(b)` |
| MinByMethodCallNegation | `a.minBy(b)` | `a.maxBy(b)` |
Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I probably went a bit too far here. Since:

forall is not the opposite of exists
drop is not the opposite of take

🤷‍♀️

@nicojs nicojs changed the title docs(mutantors): add mutant operator name proposal docs(mutators): add mutant operator name proposal Oct 26, 2021
@nicojs nicojs mentioned this pull request Dec 10, 2022
| ------------------------------------------------ | ----------------------------- | ----------------------------- |
| LogicalAndOperatorNegation | `a && b` | <code>a &vert;&vert; b</code> |
| LogicalOrOperatorNegation | <code>a &vert;&vert; b</code> | `a && b` |
| NullishCoalescingOperatorToLogicalAndReplacement | `a ?? b` | `a && b` |
Copy link

Choose a reason for hiding this comment

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

"Nullish" is not a concept in the .NET world, and I wouldn't know what to expect from this. Although I don't have a better idea, maybe only something even more verbose like "NullNullishCoalescingOperatorToLogicalAndReplacement".

(just passing by here - actually I think all this PR is a good idea)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think Nullish makes sense anyway. The end result is that the value is treated in such a way that it is the same as Null, so NullCoalescing is good enough imo.

@rouke-broersma
Copy link
Member

I would propose to remove the syntax type and other classifiers (negation, operator, expression etc) where possible.

For example:

AdditionOperatorNegation -> Addition
AdditionAssignmentNegation -> AdditionAssignment

In the spirit of KISS, I think we should simplify where possible.

@dvcopae
Copy link

dvcopae commented Feb 1, 2024

Proposal has been extended in #2995.

@nicojs
Copy link
Member Author

nicojs commented Mar 1, 2024

I've changed the PR based on a conversation we just had.

Attendees: @hugo-vrijswijk @rouke-broersma @richardwerkman @xandervedder

  • Remove the technical node names from the node identifier. Like MethodCall, Expression and Literal.
    • This improves readability and makes it easier for non-technical people to understand (mind you, easier, not easy 😉).
  • Remove Replacement postfix. The AbcToXyz should be clear enough
  • Change Nullish in favor of Null for example: NullCoalescingAssignmentToAndAssignment instead of NullishCoalescingAssignmentToAndAssignment
  • LogicalAnd And. LogicalOr Or. LogicalNot Not.
  • OptionalMemberToRequired instead of OptionalMemberRemoval (my idea ☝)

docs/supported-mutators.md Outdated Show resolved Hide resolved
@nicojs nicojs enabled auto-merge (squash) March 15, 2024 10:05
@nicojs nicojs merged commit 9f8e129 into master Mar 15, 2024
6 checks passed
@nicojs nicojs deleted the docs/mutant-operator-names branch March 15, 2024 10:08
Comment on lines +302 to +303
| FilledInterpolatedStringToEmpty | `s"foo ${bar}"` (string interpolation) | `s""` ¹ |
| FilledInterpolatedStringToEmpty | `\`foo ${bar}\`` | `\`\`` |
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, sorry! #3066 fixes that.

Btw, it's not the line breaks, but the way of escaping backticks.

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

Successfully merging this pull request may close these issues.

5 participants