-
Notifications
You must be signed in to change notification settings - Fork 442
Enhance assertMacroExpansion to Validate Post-Fix-It Macro Expansions #2355
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
Conversation
6f3c6e7
to
c7055b3
Compare
Blocked by #2329 |
c7055b3
to
c023cc9
Compare
This commit introduces an enhancement to the `assertMacroExpansion` function in SwiftSyntax's testing suite. The key addition is the capability to validate macro expansions on source code after the application of Fix-Its. This change ensures a more robust and comprehensive testing process, particularly for macros that propose fix-its for diagnostics. Modifications include: - Addition of a new parameter `expandedFixedSource` in test assertions. This parameter allows users to assert against the expanded source code after applying Fix-Its. - Update of `assertMacroExpansion` to handle the new testing workflow. It now performs macro expansion tests on both the original and the fixed source code, ensuring that both the pre-fix and post-fix states are correctly validated. - Refinement of the internal logic for applying Fix-Its and conducting macro expansion tests, ensuring accuracy and efficiency in the testing process. - Update of test cases in `AddBlockerTests.swift` and `AddCompletionHandlerMacroTests.swift` to demonstrate and validate the new functionality. Resolves: swiftlang#2333
c023cc9
to
9d0491a
Compare
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’m not sure how useful this is since the compiler would never automatically apply the Fix-Its and then expand the macro. IMO you should write a test case that checks the error case (and fixedSource
) and then test the actual expansion in a different test case.
Thank you for your input. I understand your point about the compiler's typical behavior. However, the enhancement to By incorporating |
I understand the motivation here, but |
In that case I'm closing the PR and associated issue |
There are also downsides to not automatically expanding fix-its that are worth considering. It becomes very easy to assert that some fix-it is emitted but forget to test how the fix-it applies to the source code. In fact, Apple's recent swift-mmio makes this mistake a number of times where it is never asserted how the fix-it applies. So, while the test size can increase with the automatic application of fix-its, it does make the test more correct and less chance of forgetting something. And in our experience, it's still possible to keep the test size down to a reasonable size, even for complex macros (here's an example). |
It would be beneficial if the application of fix-its were covered in those test cases. However, if I'm not mistaken, the current official version of |
FWIW @kimdv added the capability to test the fixed source in #2021 but it’s not part of a swift-syntax release yet. |
This PR introduces an enhancement to the
assertMacroExpansion
function in SwiftSyntax's testing suite. The key addition is the capability to validate macro expansions on source code after the application of Fix-Its. This change ensures a more robust and comprehensive testing process, particularly for macros that propose fix-its for diagnostics.Modifications include:
expandedFixedSource
in test assertions. This parameter allows users to assert against the expanded source code after applying Fix-Its.assertMacroExpansion
to handle the new testing workflow. It now performs macro expansion tests on both the original and the fixed source code, ensuring that both the pre-fix and post-fix states are correctly validated.AddBlockerTests.swift
andAddCompletionHandlerMacroTests.swift
to demonstrate and validate the new functionality.Resolves: #2333