Skip to content

Commit d5b8c84

Browse files
committed
[Macros] Use SWIFT_DUMP_PLUGIN_MESSAGING to test exectuable plugins
And stop using '-dump-macro-expansions'
1 parent bd9af09 commit d5b8c84

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

test/Macros/macro_plugin_basic.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@
1111
// RUN: -o %t/mock-plugin \
1212
// RUN: %t/plugin.c
1313

14-
// RUN: %swift-target-frontend \
14+
// RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
1515
// RUN: -typecheck -verify \
1616
// RUN: -swift-version 5 \
1717
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
18-
// RUN: -dump-macro-expansions \
18+
// RUN: -module-name MyApp \
1919
// RUN: %t/test.swift \
2020
// RUN: 2>&1 | tee %t/macro-expansions.txt
2121

2222
// RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt
2323

24+
// CHECK: ->(plugin:[[#PID:]]) {"getCapability":{}}
25+
// CHECK: <-(plugin:[[#PID]]) {"getCapabilityResult":{"capability":{"protocolVersion":1}}}
26+
// CHECK: ->(plugin:[[#PID]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"testString","typeName":"TestStringMacro"},"syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"BUILD_DIR{{.+}}test.swift","line":5,"offset":301},"source":"#testString(123)"}}}
27+
// CHECK: <-(plugin:[[#PID]]) {"expandFreestandingMacroResult":{"diagnostics":[],"expandedSource":"\"123\"\n + \"foo \""}}
28+
// CHECK: ->(plugin:[[#PID]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"testStringWithError","typeName":"TestStringWithErrorMacro"},"syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"BUILD_DIR{{.+}}test.swift","line":6,"offset":336},"source":"#testStringWithError(321)"}}}
29+
// CHECK: <-(plugin:[[#PID]]) {"expandFreestandingMacroResult":{"diagnostics":[{"fixIts":[],"highlights":[],"message":"message from plugin","notes":[],"position":{"fileName":"BUILD_DIR{{.*}}test.swift","offset":336},"severity":"error"}],"expandedSource":"\"bar\""}}
30+
2431
//--- test.swift
2532
@freestanding(expression) macro testString(_: Any) -> String = #externalMacro(module: "TestPlugin", type: "TestStringMacro")
2633
@freestanding(expression) macro testStringWithError(_: Any) -> String = #externalMacro(module: "TestPlugin", type: "TestStringWithErrorMacro")
@@ -31,15 +38,6 @@ func test() {
3138
// expected-error @-1 {{message from plugin}}
3239
}
3340

34-
// CHECK: ------------------------------
35-
// CHECK-NEXT: {{^}}"123"
36-
// CHECK-NEXT: {{^}} + "foo "
37-
// CHECK-NEXT: ------------------------------
38-
39-
// CHECK: ------------------------------
40-
// CHECK-NEXT: {{^}}"bar"
41-
// CHECK-NEXT: ------------------------------
42-
4341
//--- plugin.c
4442
#include "swift-c/MockPlugin/MockPlugin.h"
4543

test/Macros/macro_plugin_error.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@
1111
// RUN: -o %t/mock-plugin \
1212
// RUN: %t/plugin.c
1313

14-
// RUN: %swift-target-frontend \
14+
// RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
1515
// RUN: -typecheck -verify \
1616
// RUN: -swift-version 5 -enable-experimental-feature Macros \
1717
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
18-
// RUN: -dump-macro-expansions \
19-
// RUN: %t/test.swift
18+
// RUN: -module-name MyApp \
19+
// RUN: %t/test.swift \
20+
// RUN: 2>&1 | tee %t/macro-expansions.txt
21+
22+
// RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt
23+
24+
// CHECK: ->(plugin:[[#PID1:]]) {"getCapability":{}}
25+
// CHECK-NEXT: <-(plugin:[[#PID1]]) {"getCapabilityResult":{"capability":{"protocolVersion":1}}}
26+
// CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"fooMacro","typeName":"FooMacro"},"syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"BUILD_DIR{{.+}}test.swift","line":6,"offset":200},"source":"#fooMacro(1)"}}}
27+
// CHECK-NEXT: <-(plugin:[[#PID1]]) {"invalidResponse":{}}
28+
// CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"fooMacro","typeName":"FooMacro"},"syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"BUILD_DIR{{.+}}test.swift","line":8,"offset":304},"source":"#fooMacro(2)"}}}
29+
// ^ This messages causes the mock plugin exit because there's no matching expected message.
30+
31+
// CHECK: ->(plugin:[[#PID2:]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"fooMacro","typeName":"FooMacro"},"syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"BUILD_DIR{{.+}}test.swift","line":10,"offset":386},"source":"#fooMacro(3)"}}}
32+
// CHECK-NEXT: <-(plugin:[[#PID2:]]) {"expandFreestandingMacroResult":{"diagnostics":[],"expandedSource":"3.description"}}
2033

2134
//--- test.swift
2235
@freestanding(expression) macro fooMacro(_: Any) -> String = #externalMacro(module: "TestPlugin", type: "FooMacro")

test/Macros/macro_plugin_server.swift

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,33 @@
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

Comments
 (0)