Skip to content

Commit 7e85ebd

Browse files
committed
[Macros] Add a macro plugin test for extension macros.
1 parent 43e2026 commit 7e85ebd

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// FIXME: Swift parser is not enabled on Linux CI yet.
2+
// REQUIRES: OS=macosx
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: %empty-directory(%t/plugins)
6+
//
7+
//== Build the plugin library
8+
// RUN: %host-build-swift \
9+
// RUN: -swift-version 5 \
10+
// RUN: -emit-library \
11+
// RUN: -o %t/plugins/%target-library-name(MacroDefinition) \
12+
// RUN: -module-name=MacroDefinition \
13+
// RUN: %S/Inputs/syntax_macro_definitions.swift \
14+
// RUN: -g -no-toolchain-stdlib-rpath
15+
16+
// RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
17+
// RUN: -typecheck -verify \
18+
// RUN: -swift-version 5 -enable-experimental-feature ExtensionMacros \
19+
// RUN: -external-plugin-path %t/plugins#%swift-plugin-server \
20+
// RUN: -module-name MyApp \
21+
// RUN: %s \
22+
// RUN: 2>&1 | tee %t/macro-expansions.txt
23+
24+
// RUN: %FileCheck %s < %t/macro-expansions.txt
25+
26+
@attached(extension, conformances: P, names: named(requirement))
27+
macro DelegatedConformance() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceMacro")
28+
29+
protocol P {
30+
static func requirement()
31+
}
32+
33+
struct Wrapped: P {
34+
static func requirement() {
35+
print("Wrapped.requirement")
36+
}
37+
}
38+
39+
@DelegatedConformance
40+
struct Generic<Element> {}
41+
42+
// CHECK: {"expandMacroResult":{"diagnostics":[],"expandedSource":"extension Generic: P where Element: P {\n static func requirement() {\n Element.requirement()\n }\n}"}}
43+
44+
func requiresP(_ value: (some P).Type) {
45+
value.requirement()
46+
}
47+
48+
requiresP(Generic<Wrapped>.self)
49+
50+
struct Outer {
51+
@DelegatedConformance
52+
struct Nested<Element> {}
53+
}
54+
55+
// CHECK: {"expandMacroResult":{"diagnostics":[],"expandedSource":"extension Outer.Nested: P where Element: P {\n static func requirement() {\n Element.requirement()\n }\n}"}}
56+
57+
requiresP(Outer.Nested<Wrapped>.self)

0 commit comments

Comments
 (0)