Files
swift-mirror/test/Frontend/DiagnosticVerifier/expansion-remarks.swift
Henrik G. Olsson 040c9e6729 [macros] add -Rmacro-expansions
This adds the -Rmacro-expansions flag. It provides similar functionality
to -dump-macro-expansions, but instead of dumping the macro expansion to
stderr, it emits it line by line as remarks. This is useful for testing
with -verify, where both macro expansion content and warnings need to be
tested at the same time.
2025-11-05 18:45:34 -08:00

37 lines
1.6 KiB
Swift

// REQUIRES: swift_swift_parser, executable_test
// RUN: %empty-directory(%t)
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(UnstringifyMacroDefinition) -module-name=UnstringifyMacroDefinition %S/Inputs/macro/unstringify-macro.swift -g -no-toolchain-stdlib-rpath
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -Rmacro-expansions
@attached(peer, names: overloaded)
macro unstringifyPeer(_ s: String) =
#externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro")
// expected-note@+1 *{{in expansion of macro 'unstringifyPeer' on global function 'foo()' here}}
@unstringifyPeer("func foo(_ x: Int) {\nlet a = 2\nlet b = x\n}")
func foo() {}
/*
expected-expansion@-2:14{{
expected-remark@1{{macro content: |func foo(_ x: Int) {|}}
expected-remark@2{{macro content: | let a = 2|}}
expected-warning@2{{initialization of immutable value 'a' was never used; consider replacing with assignment to '_' or removing it}}
expected-remark@3{{macro content: | let b = x|}}
expected-warning@3{{initialization of immutable value 'b' was never used; consider replacing with assignment to '_' or removing it}}
expected-remark@4{{macro content: |}|}}
}}
*/
@freestanding(expression) public macro ExprMacro() -> String = #file
func bar() {
// expected-note@+1{{in expansion of macro 'ExprMacro' here}}
let _ = #ExprMacro()
/*
expected-expansion@-2:13{{
expected-remark@1{{macro content: |#file|}}
}}
*/
}