Skip to content

The conformance role does not expand in the test case. #1801

@liaoyuanng

Description

@liaoyuanng

Description

@attached(conformance)
public macro demonstration() = #externalMacro(module: "WWDC23Macros", type: "DemostrationMacro")

extension DemostrationMacro: ConformanceMacro {
    public static func expansion<Declaration, Context>(
        of node: AttributeSyntax,
        providingConformancesOf declaration: Declaration,
        in context: Context
    ) throws -> [(TypeSyntax, GenericWhereClauseSyntax?)] where Declaration : DeclGroupSyntax, Context : MacroExpansionContext {
                
        return [("DemonstrationProtocol", nil)]
}


@main
struct WWDCHelperPlugin: CompilerPlugin {
    let providingMacros: [Macro.Type] = [
        DemostrationMacro.self
    ]
}

// in Test file
let testMacros: [String: Macro.Type] = [
    "demonstration": DemostrationMacro.self,
]

func testMacro() {
        assertMacroExpansion(
            """
            @demonstration()
            class TestClass {
            }
            """,
            expandedSource: """
            
            class TestClass {
            }
            extension TestClass : DemonstrationProtocol  {}
            """,
            macros: testMacros
        )
 }

There is an error when I run the test case:

error: -[WWDC23Tests.WWDC23Tests testMacro] : failed - Actual output (+) differed from expected output (-):
 
class TestClass {
 }extension TestClass : DemonstrationProtocol  {}

But it runs fine when I execute it in the code.
image

It seems that the macro is missing the last line when it expands in the test.

Steps to Reproduce

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions