Skip to content

Add a possibility to validate fixedSource post macro expansion in the assertMacroExpansion #2333

Closed as not planned
@Matejkob

Description

@Matejkob

In light of the discussion here, there's a need to re-evaluate the testing strategy for macro expansions, particularly concerning the application of fix-its. The current methodology asserts the expandedSource before the application of any fix-its, which may not fully validate the macro's behavior in the presence of fixable code errors.

A more robust testing process would involve the assertMacroExpansion function not only applying fix-its to the originalSource but also asserting the result of the macro expansion on the corrected source code. This approach has been effectively utilized in swift-macro-testing by mbrandonw and stephencelis, showcased here.

To align with this improved testing paradigm, I propose the addition of a new parameter—perhaps expandedSourceAfterApplyingFixIt—which would enable users to assert against the post-fix-it expanded source. This addition is crucial as macros may propose fix-its for diagnostics that do not halt the expansion process, such as those with a severity less than error.

By incorporating this feature, assertMacroExpansion would gain the capability to confirm the fixed source after the macro expansion, ensuring a more comprehensive verification process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions