2525// RUN: %S/Inputs/evil_macro_definitions.swift \
2626// RUN: -g -no-toolchain-stdlib-rpath
2727
28- // RUN: %swift-target-frontend \
28+ // RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
2929// RUN: -typecheck -verify \
30- // RUN: -swift-version 5 \
30+ // RUN: -swift-version 5 -enable-experimental-feature Macros \
3131// RUN: -external-plugin-path %t/plugins#%swift-plugin-server \
32- // RUN: -dump-macro-expansions \
32+ // RUN: -module-name MyApp \
3333// RUN: %s \
3434// RUN: 2>&1 | tee %t/macro-expansions.txt
3535
3636// RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt
3737
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\")"}}
3855
3956@freestanding ( expression) macro stringify< T> ( _ value: T ) -> ( T , String ) = #externalMacro( module: " MacroDefinition " , type: " StringifyMacro " )
4057@freestanding ( expression) macro evil( _ value: Int ) -> String = #externalMacro( module: " EvilMacros " , type: " CrashingMacro " )
@@ -43,17 +60,10 @@ func testStringify(a: Int, b: Int) {
4360 let s1 : String = #stringify ( a + b) . 1
4461 print ( s1)
4562
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 )
4765 print ( s2)
4866
4967 let s3 : String = #stringify ( b + a) . 1
5068 print ( s3)
5169}
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