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

Unit testing of AttributeRemover #2247

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

gohanlon
Copy link
Contributor

@gohanlon gohanlon commented Sep 29, 2023

Following discussions in #2215, this PR isolates AttributeRemoverTests to AttributeRemover (SwiftSyntaxMacroExpansion module).

Test Changes:

  • Added a fileprivate assert helper: assertSyntaxRemovingTestAttributes.

Core Changes:

  • Rather than depending on SyntaxNode's id-only Equatable conformance, refactor AttributeRemover to remove attributes matching a predicate: AttributeRemover.init(removingWhere:) of type (AttributeSyntax) -> Bool). This change allows AttributeRemover to be used without first plucking the AttributeSyntax values to be removed from the live tree.
  • Marks the AttributeRemover class with @_spi(Testing) to make the class visible from the test module without including AttributeRemover in the public API.

@gohanlon
Copy link
Contributor Author

@ahoppen @bnbarham @Matejkob Do you think unit testing of AttributeRemover is worth pursuing?

Copy link
Collaborator

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

I like this. A couple of comments inline

Copy link
Collaborator

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thanks. Looks good to me. Just one small comment for adding documentation.

@gohanlon
Copy link
Contributor Author

gohanlon commented Oct 7, 2023

@ahoppen I think this PR is just about ready for final review, pending your review of the latest changes. (Particularly the init(where:) to init(removingWhere:) rename and the doc comment I added.)

And, when you say to, I'll squash this PR into a single commit and mark the PR as "Ready" instead of "Draft".

Copy link
Collaborator

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Great. Let's get this in.

* Add a private assert helper: `assertSyntaxRemovingTestAttributes`
* Make `AttributeRemover` SPI (`@_spi(Testing)`)
* Rather than depending on `SyntaxNode`'s id-only `Equatable`
  conformance, refactor `AttributeRemover` to remove attributes matching
  a predicate: `AttributeRemover.init(removingWhere:)` of type
  `(AttributeSyntax) -> Bool)`. This change allows `AttributeRemover` to
  be used without first plucking the `AttributeSyntax` values to be
  removed from a live tree.

Note: Unlike `assertMacroExpansion`, the new
`assertSyntaxRemovingTestAttributes` does not trim newlines before
comparing values. The trimming by `assertMacroExpansion` was masking a
(minor) bug in `AttributeRemover` where an extra leading newline remains
when the removed attribute has no proceeding tokens. For now, this
commit "fixes" the failing tests by including the unwanted leading
newlines in the expected test output, while also adding "FIXME" comments
to draw attention to the need for a future fix.
@gohanlon gohanlon marked this pull request as ready for review October 7, 2023 16:24
@gohanlon
Copy link
Contributor Author

gohanlon commented Oct 7, 2023

@ahoppen Squashed. Let me know if there's anything else!

@kimdv
Copy link
Collaborator

kimdv commented Oct 7, 2023

@swift-ci please test

@ahoppen
Copy link
Collaborator

ahoppen commented Oct 9, 2023

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge October 9, 2023 17:58
@ahoppen
Copy link
Collaborator

ahoppen commented Oct 9, 2023

@swift-ci Please test macOS

@ahoppen ahoppen merged commit ab46cdd into apple:main Oct 9, 2023
3 checks passed
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.

None yet

3 participants