-
Notifications
You must be signed in to change notification settings - Fork 424
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
Conversation
There was a problem hiding this 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
Tests/SwiftSyntaxMacroExpansionTest/AttributeRemoverTests.swift
Outdated
Show resolved
Hide resolved
Tests/SwiftSyntaxMacroExpansionTest/AttributeRemoverTests.swift
Outdated
Show resolved
Hide resolved
Tests/SwiftSyntaxMacroExpansionTest/AttributeRemoverTests.swift
Outdated
Show resolved
Hide resolved
Tests/SwiftSyntaxMacroExpansionTest/AttributeRemoverTests.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
@ahoppen I think this PR is just about ready for final review, pending your review of the latest changes. (Particularly the And, when you say to, I'll squash this PR into a single commit and mark the PR as "Ready" instead of "Draft". |
There was a problem hiding this 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.
e5069f1
to
80113cd
Compare
@ahoppen Squashed. Let me know if there's anything else! |
@swift-ci please test |
@swift-ci Please test |
@swift-ci Please test macOS |
Following discussions in #2215, this PR isolates
AttributeRemoverTests
toAttributeRemover
(SwiftSyntaxMacroExpansion
module).Test Changes:
fileprivate
assert helper:assertSyntaxRemovingTestAttributes
.Core Changes:
SyntaxNode
's id-onlyEquatable
conformance, refactorAttributeRemover
to remove attributes matching a predicate:AttributeRemover.init(removingWhere:)
of type(AttributeSyntax) -> Bool)
. This change allowsAttributeRemover
to be used without first plucking theAttributeSyntax
values to be removed from the live tree.AttributeRemover
class with@_spi(Testing)
to make the class visible from the test module without includingAttributeRemover
in the public API.