25
25
// RUN: %S/Inputs/evil_macro_definitions.swift \
26
26
// RUN: -g -no-toolchain-stdlib-rpath
27
27
28
- // RUN: %swift-target-frontend \
28
+ // RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
29
29
// RUN: -typecheck -verify \
30
- // RUN: -swift-version 5 \
30
+ // RUN: -swift-version 5 -enable-experimental-feature Macros \
31
31
// RUN: -external-plugin-path %t/plugins#%swift-plugin-server \
32
- // RUN: -dump-macro-expansions \
32
+ // RUN: -module-name MyApp \
33
33
// RUN: %s \
34
34
// RUN: 2>&1 | tee %t/macro-expansions.txt
35
35
36
36
// RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt
37
37
38
+ // CHECK: ->(plugin:[[#PID1:]]) {"getCapability":{}}
39
+ // CHECK-NEXT: <-(plugin:[[#PID1]]) {"getCapabilityResult":{"capability":{"features":["load-plugin-library"],"protocolVersion":4}}}
40
+ // CHECK-NEXT: ->(plugin:[[#PID1]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libMacroDefinition.dylib","moduleName":"MacroDefinition"}}
41
+ // CHECK-NEXT: <-(plugin:[[#PID1]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
42
+ // CHECK-NEXT: ->(plugin:[[#PID1]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libEvilMacros.dylib","moduleName":"EvilMacros"}}
43
+ // CHECK-NEXT: <-(plugin:[[#PID1]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
44
+ // CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"${{.*}}","macro":{"moduleName":"MacroDefinition","name":"stringify","typeName":"StringifyMacro"},"syntax":{"kind":"expression","location":{{{.+}}},"source":"#stringify(a + b)"}}}
45
+ // CHECK-NEXT: <-(plugin:[[#PID1]]) {"expandFreestandingMacroResult":{"diagnostics":[],"expandedSource":"(a + b, \"a + b\")"}}
46
+ // CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"${{.*}}","macro":{"moduleName":"EvilMacros","name":"evil","typeName":"CrashingMacro"},"syntax":{"kind":"expression","location":{{{.+}}},"source":"#evil(42)"}}}
47
+ // ^ This crashes the plugin server.
48
+
49
+ // CHECK-NEXT: ->(plugin:[[#PID2:]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libMacroDefinition.dylib","moduleName":"MacroDefinition"}}
50
+ // CHECK-NEXT: <-(plugin:[[#PID2]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
51
+ // CHECK-NEXT: ->(plugin:[[#PID2]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libEvilMacros.dylib","moduleName":"EvilMacros"}}
52
+ // CHECK-NEXT: <-(plugin:[[#PID2]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
53
+ // CHECK-NEXT: ->(plugin:[[#PID2]]) {"expandFreestandingMacro":{"discriminator":"${{.*}}","macro":{"moduleName":"MacroDefinition","name":"stringify","typeName":"StringifyMacro"},"syntax":{"kind":"expression","location":{{{.+}}},"source":"#stringify(b + a)"}}}
54
+ // CHECK-NEXT: <-(plugin:[[#PID2]]) {"expandFreestandingMacroResult":{"diagnostics":[],"expandedSource":"(b + a, \"b + a\")"}}
38
55
39
56
@freestanding ( expression) macro stringify< T> ( _ value: T ) -> ( T , String ) = #externalMacro( module: " MacroDefinition " , type: " StringifyMacro " )
40
57
@freestanding ( expression) macro evil( _ value: Int ) -> String = #externalMacro( module: " EvilMacros " , type: " CrashingMacro " )
@@ -43,17 +60,10 @@ func testStringify(a: Int, b: Int) {
43
60
let s1 : String = #stringify ( a + b) . 1
44
61
print ( s1)
45
62
46
- let s2 : String = #evil( 42 ) // expected-error {{failedToReceiveMessage (from macro 'evil')}}
63
+ // expected-error @+1 {{failedToReceiveMessage (from macro 'evil')}}
64
+ let s2 : String = #evil( 42 )
47
65
print ( s2)
48
66
49
67
let s3 : String = #stringify ( b + a) . 1
50
68
print ( s3)
51
69
}
52
-
53
- // CHECK: {{^}}------------------------------
54
- // CHECK-NEXT: {{^}}(a + b, "a + b")
55
- // CHECK-NEXT: {{^}}------------------------------
56
-
57
- // CHECK: {{^}}------------------------------
58
- // CHECK-NEXT: {{^}}(b + a, "b + a")
59
- // CHECK-NEXT: {{^}}------------------------------
0 commit comments