mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Macros] Use SWIFT_DUMP_PLUGIN_MESSAGING to test exectuable plugins
And stop using '-dump-macro-expansions'
This commit is contained in:
@@ -11,16 +11,23 @@
|
|||||||
// RUN: -o %t/mock-plugin \
|
// RUN: -o %t/mock-plugin \
|
||||||
// RUN: %t/plugin.c
|
// RUN: %t/plugin.c
|
||||||
|
|
||||||
// RUN: %swift-target-frontend \
|
// RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
|
||||||
// RUN: -typecheck -verify \
|
// RUN: -typecheck -verify \
|
||||||
// RUN: -swift-version 5 \
|
// RUN: -swift-version 5 \
|
||||||
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
|
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
|
||||||
// RUN: -dump-macro-expansions \
|
// RUN: -module-name MyApp \
|
||||||
// RUN: %t/test.swift \
|
// RUN: %t/test.swift \
|
||||||
// RUN: 2>&1 | tee %t/macro-expansions.txt
|
// RUN: 2>&1 | tee %t/macro-expansions.txt
|
||||||
|
|
||||||
// RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt
|
// RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt
|
||||||
|
|
||||||
|
// CHECK: ->(plugin:[[#PID:]]) {"getCapability":{}}
|
||||||
|
// CHECK: <-(plugin:[[#PID]]) {"getCapabilityResult":{"capability":{"protocolVersion":1}}}
|
||||||
|
// 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)"}}}
|
||||||
|
// CHECK: <-(plugin:[[#PID]]) {"expandFreestandingMacroResult":{"diagnostics":[],"expandedSource":"\"123\"\n + \"foo \""}}
|
||||||
|
// 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)"}}}
|
||||||
|
// CHECK: <-(plugin:[[#PID]]) {"expandFreestandingMacroResult":{"diagnostics":[{"fixIts":[],"highlights":[],"message":"message from plugin","notes":[],"position":{"fileName":"BUILD_DIR{{.*}}test.swift","offset":336},"severity":"error"}],"expandedSource":"\"bar\""}}
|
||||||
|
|
||||||
//--- test.swift
|
//--- test.swift
|
||||||
@freestanding(expression) macro testString(_: Any) -> String = #externalMacro(module: "TestPlugin", type: "TestStringMacro")
|
@freestanding(expression) macro testString(_: Any) -> String = #externalMacro(module: "TestPlugin", type: "TestStringMacro")
|
||||||
@freestanding(expression) macro testStringWithError(_: Any) -> String = #externalMacro(module: "TestPlugin", type: "TestStringWithErrorMacro")
|
@freestanding(expression) macro testStringWithError(_: Any) -> String = #externalMacro(module: "TestPlugin", type: "TestStringWithErrorMacro")
|
||||||
@@ -31,15 +38,6 @@ func test() {
|
|||||||
// expected-error @-1 {{message from plugin}}
|
// expected-error @-1 {{message from plugin}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: ------------------------------
|
|
||||||
// CHECK-NEXT: {{^}}"123"
|
|
||||||
// CHECK-NEXT: {{^}} + "foo "
|
|
||||||
// CHECK-NEXT: ------------------------------
|
|
||||||
|
|
||||||
// CHECK: ------------------------------
|
|
||||||
// CHECK-NEXT: {{^}}"bar"
|
|
||||||
// CHECK-NEXT: ------------------------------
|
|
||||||
|
|
||||||
//--- plugin.c
|
//--- plugin.c
|
||||||
#include "swift-c/MockPlugin/MockPlugin.h"
|
#include "swift-c/MockPlugin/MockPlugin.h"
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,25 @@
|
|||||||
// RUN: -o %t/mock-plugin \
|
// RUN: -o %t/mock-plugin \
|
||||||
// RUN: %t/plugin.c
|
// RUN: %t/plugin.c
|
||||||
|
|
||||||
// RUN: %swift-target-frontend \
|
// RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
|
||||||
// RUN: -typecheck -verify \
|
// RUN: -typecheck -verify \
|
||||||
// RUN: -swift-version 5 -enable-experimental-feature Macros \
|
// RUN: -swift-version 5 -enable-experimental-feature Macros \
|
||||||
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
|
// RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
|
||||||
// RUN: -dump-macro-expansions \
|
// RUN: -module-name MyApp \
|
||||||
// RUN: %t/test.swift
|
// RUN: %t/test.swift \
|
||||||
|
// RUN: 2>&1 | tee %t/macro-expansions.txt
|
||||||
|
|
||||||
|
// RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt
|
||||||
|
|
||||||
|
// CHECK: ->(plugin:[[#PID1:]]) {"getCapability":{}}
|
||||||
|
// CHECK-NEXT: <-(plugin:[[#PID1]]) {"getCapabilityResult":{"capability":{"protocolVersion":1}}}
|
||||||
|
// 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)"}}}
|
||||||
|
// CHECK-NEXT: <-(plugin:[[#PID1]]) {"invalidResponse":{}}
|
||||||
|
// 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)"}}}
|
||||||
|
// ^ This messages causes the mock plugin exit because there's no matching expected message.
|
||||||
|
|
||||||
|
// 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)"}}}
|
||||||
|
// CHECK-NEXT: <-(plugin:[[#PID2:]]) {"expandFreestandingMacroResult":{"diagnostics":[],"expandedSource":"3.description"}}
|
||||||
|
|
||||||
//--- test.swift
|
//--- test.swift
|
||||||
@freestanding(expression) macro fooMacro(_: Any) -> String = #externalMacro(module: "TestPlugin", type: "FooMacro")
|
@freestanding(expression) macro fooMacro(_: Any) -> String = #externalMacro(module: "TestPlugin", type: "FooMacro")
|
||||||
|
|||||||
@@ -25,16 +25,33 @@
|
|||||||
// RUN: %S/Inputs/evil_macro_definitions.swift \
|
// RUN: %S/Inputs/evil_macro_definitions.swift \
|
||||||
// RUN: -g -no-toolchain-stdlib-rpath
|
// RUN: -g -no-toolchain-stdlib-rpath
|
||||||
|
|
||||||
// RUN: %swift-target-frontend \
|
// RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
|
||||||
// RUN: -typecheck -verify \
|
// RUN: -typecheck -verify \
|
||||||
// RUN: -swift-version 5 \
|
// RUN: -swift-version 5 -enable-experimental-feature Macros \
|
||||||
// RUN: -external-plugin-path %t/plugins#%swift-plugin-server \
|
// RUN: -external-plugin-path %t/plugins#%swift-plugin-server \
|
||||||
// RUN: -dump-macro-expansions \
|
// RUN: -module-name MyApp \
|
||||||
// RUN: %s \
|
// RUN: %s \
|
||||||
// RUN: 2>&1 | tee %t/macro-expansions.txt
|
// RUN: 2>&1 | tee %t/macro-expansions.txt
|
||||||
|
|
||||||
// RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt
|
// RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt
|
||||||
|
|
||||||
|
// CHECK: ->(plugin:[[#PID1:]]) {"getCapability":{}}
|
||||||
|
// CHECK-NEXT: <-(plugin:[[#PID1]]) {"getCapabilityResult":{"capability":{"features":["load-plugin-library"],"protocolVersion":4}}}
|
||||||
|
// CHECK-NEXT: ->(plugin:[[#PID1]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libMacroDefinition.dylib","moduleName":"MacroDefinition"}}
|
||||||
|
// CHECK-NEXT: <-(plugin:[[#PID1]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
|
||||||
|
// CHECK-NEXT: ->(plugin:[[#PID1]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libEvilMacros.dylib","moduleName":"EvilMacros"}}
|
||||||
|
// CHECK-NEXT: <-(plugin:[[#PID1]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
|
||||||
|
// CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"${{.*}}","macro":{"moduleName":"MacroDefinition","name":"stringify","typeName":"StringifyMacro"},"syntax":{"kind":"expression","location":{{{.+}}},"source":"#stringify(a + b)"}}}
|
||||||
|
// CHECK-NEXT: <-(plugin:[[#PID1]]) {"expandFreestandingMacroResult":{"diagnostics":[],"expandedSource":"(a + b, \"a + b\")"}}
|
||||||
|
// CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"${{.*}}","macro":{"moduleName":"EvilMacros","name":"evil","typeName":"CrashingMacro"},"syntax":{"kind":"expression","location":{{{.+}}},"source":"#evil(42)"}}}
|
||||||
|
// ^ This crashes the plugin server.
|
||||||
|
|
||||||
|
// CHECK-NEXT: ->(plugin:[[#PID2:]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libMacroDefinition.dylib","moduleName":"MacroDefinition"}}
|
||||||
|
// CHECK-NEXT: <-(plugin:[[#PID2]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
|
||||||
|
// CHECK-NEXT: ->(plugin:[[#PID2]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libEvilMacros.dylib","moduleName":"EvilMacros"}}
|
||||||
|
// CHECK-NEXT: <-(plugin:[[#PID2]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
|
||||||
|
// CHECK-NEXT: ->(plugin:[[#PID2]]) {"expandFreestandingMacro":{"discriminator":"${{.*}}","macro":{"moduleName":"MacroDefinition","name":"stringify","typeName":"StringifyMacro"},"syntax":{"kind":"expression","location":{{{.+}}},"source":"#stringify(b + a)"}}}
|
||||||
|
// CHECK-NEXT: <-(plugin:[[#PID2]]) {"expandFreestandingMacroResult":{"diagnostics":[],"expandedSource":"(b + a, \"b + a\")"}}
|
||||||
|
|
||||||
@freestanding(expression) macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
|
@freestanding(expression) macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
|
||||||
@freestanding(expression) macro evil(_ value: Int) -> String = #externalMacro(module: "EvilMacros", type: "CrashingMacro")
|
@freestanding(expression) macro evil(_ value: Int) -> String = #externalMacro(module: "EvilMacros", type: "CrashingMacro")
|
||||||
@@ -43,17 +60,10 @@ func testStringify(a: Int, b: Int) {
|
|||||||
let s1: String = #stringify(a + b).1
|
let s1: String = #stringify(a + b).1
|
||||||
print(s1)
|
print(s1)
|
||||||
|
|
||||||
let s2: String = #evil(42) // expected-error {{failedToReceiveMessage (from macro 'evil')}}
|
// expected-error @+1 {{failedToReceiveMessage (from macro 'evil')}}
|
||||||
|
let s2: String = #evil(42)
|
||||||
print(s2)
|
print(s2)
|
||||||
|
|
||||||
let s3: String = #stringify(b + a).1
|
let s3: String = #stringify(b + a).1
|
||||||
print(s3)
|
print(s3)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: {{^}}------------------------------
|
|
||||||
// CHECK-NEXT: {{^}}(a + b, "a + b")
|
|
||||||
// CHECK-NEXT: {{^}}------------------------------
|
|
||||||
|
|
||||||
// CHECK: {{^}}------------------------------
|
|
||||||
// CHECK-NEXT: {{^}}(b + a, "b + a")
|
|
||||||
// CHECK-NEXT: {{^}}------------------------------
|
|
||||||
|
|||||||
Reference in New Issue
Block a user