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

Improve procarg0 handling #1326

Merged
merged 6 commits into from
Apr 29, 2022
Merged

Improve procarg0 handling #1326

merged 6 commits into from
Apr 29, 2022

Conversation

dgollahon
Copy link
Collaborator

This PR does several things, all motivated by improving procarg0 support:

  • Cleans up some mutant ignores
    • NOTE: Makes reliance on 2.7+ slightly tighter. Not sure if that affects any custom support cases.
  • Fixes crash with certain block argument edge cases such as foo { |(*)| }.
  • Fixes mutation from foo { |(a, b)| } to foo { |(_a, b)| } and foo { |(a, _b)| } instead of the less useful mutation to only foo { |_a| }.
  • Adds a foo { |(a, b)| } -> foo { |a, b| } mutation.
  • Fixes corpus tests which were previously not testing the modern parser AST

@dgollahon dgollahon force-pushed the improve-procarg0-handling branch from 6fa0f20 to f4f90d4 Compare April 29, 2022 02:01
@dgollahon dgollahon requested a review from mbj April 29, 2022 02:02
- These are now fully covered.
- Since ruby 2.7+ defines `start_with?` on symbols as well as strings, the `#to_s` here is irrelevant. This locks `mutant` a bit more tightly to ruby 2.7+ but I think, based on the gemspec, that that's probably acceptable.
- It's possible to have an unnamed procarg0 argument by doing something like this: `foo { |(*)| }` and a few other niche cases. This resolves those crashes.
- Also solves a bug where the mutation to prefix `_` to potentially unused arguments wasn't applying properly in cases like this: `foo { |(a,b)| }` and instead of prefixing both `a` as `_a` and `b` as `_b` it would only emit the strange case of `foo { |_a| }`
- Additionally, we have slightly simpler code by just recursing and letting the rename be handled by the `arg` node mutator.
@dgollahon dgollahon force-pushed the improve-procarg0-handling branch from 6bb4ba3 to ab0bc91 Compare April 29, 2022 02:05
- Adds mutations of the form `foo { |(a, b)| }` -> `foo { |a, b| }. This does not apply in the case of 1 argument because that would force writing `foo { |a,| }` over `foo { |a| }`
- Closes #784
- I discovered the procarg0 edge case because I was trying to test something unrelated via the corpus tests. Unfortunately, the corpus tests were never upgraded to use the modern AST as brought in through `unparser`. This means that we've actually had corpus tests that were not generating valid mutations or properly exercising the parts of mutant that make use of the modern AST for years.
@dgollahon dgollahon force-pushed the improve-procarg0-handling branch from 79371e4 to 8eea07e Compare April 29, 2022 02:12
@mbj mbj merged commit bc9a73d into main Apr 29, 2022
@mbj mbj deleted the improve-procarg0-handling branch April 29, 2022 10:01
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.

2 participants