33// RUN: %empty-directory(%t)
44// RUN: split-file %s %t
55
6- // RUN: sed -i '' -e 's#PYTHON_EXEC_PATH#%{python}#' %t/plugin
7- // RUN: sed -i '' -e 's#UTILS_DIR_PATH#%utils#' %t/plugin
8- // RUN: chmod +x %t/plugin
6+ // RUN: %clang \
7+ // RUN: -isysroot %sdk \
8+ // RUN: -I %swift_src_root/include \
9+ // RUN: -L %swift-lib-dir -l_swiftMockPlugin \
10+ // RUN: -Wl,-rpath,%swift-lib-dir \
11+ // RUN: -o %t/mock-plugin \
12+ // RUN: %t/plugin.c
913
10- // RUN: %swift-target-frontend -typecheck -verify -swift-version 5 -enable-experimental-feature Macros -load-plugin-executable %t/plugin#TestPlugin %t/test.swift
14+ // RUN: %swift-target-frontend \
15+ // RUN: -typecheck -verify \
16+ // RUN: -swift-version 5 -enable-experimental-feature Macros \
17+ // RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \
18+ // RUN: -dump-macro-expansions \
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
1123
1224//--- test.swift
1325@freestanding ( expression) macro testString( _: Any ) -> String = #externalMacro( module: " TestPlugin " , type: " TestStringMacro " )
@@ -19,41 +31,43 @@ func test() {
1931 // expected-error @-1 {{message from plugin}}
2032}
2133
22- //--- plugin
23- #!PYTHON_EXEC_PATH
24- import sys
25- sys. path. append ( 'UTILS_DIR_PATH')
34+ // CHECK: ------------------------------
35+ // CHECK-NEXT: {{^}}"123"
36+ // CHECK-NEXT: {{^}} + "foo "
37+ // CHECK-NEXT: ------------------------------
38+
39+ // CHECK: ------------------------------
40+ // CHECK-NEXT: {{^}}"bar"
41+ // CHECK-NEXT: ------------------------------
2642
27- import mock_plugin
43+ //--- plugin.c
44+ #include " swift-c/MockPlugin/MockPlugin.h "
2845
29- mock_plugin . TEST_SPEC = [
46+ MOCK_PLUGIN ( [
3047 {
3148 " expect " : { " getCapability " : { } } ,
32- " response " : { " getCapabilityResult " : { " capability " : { " protocolVersion " : 1 } } } ,
49+ " response " : { " getCapabilityResult " : { " capability " : { " protocolVersion " : 1 } } }
3350 } ,
3451 {
3552 " expect " : { " expandFreestandingMacro " : {
3653 " macro " : { " moduleName " : " TestPlugin " , " typeName " : " TestStringMacro " } ,
3754 " syntax " : { " kind " : " expression " , " source " : " #testString(123) " } } } ,
38- " response " : { " expandFreestandingMacroResult " : { " expandedSource " : " \" 123 \" " , " diagnostics " : [ ] } } ,
55+ " response " : { " expandFreestandingMacroResult " : { " expandedSource " : " \" 123 \" \n + \" foo \" " , " diagnostics " : [ ] } }
3956 } ,
4057 {
4158 " expect " : { " expandFreestandingMacro " : {
4259 " macro " : { " moduleName " : " TestPlugin " , " typeName " : " TestStringWithErrorMacro " } ,
4360 " syntax " : { " kind " : " expression " , " source " : " #testStringWithError(321) " } } } ,
4461 " response " : { " expandFreestandingMacroResult " : {
45- " expandedSource " : " \" 123 \" " ,
62+ " expandedSource " : " \" bar \" " ,
4663 " diagnostics " : [
4764 { " severity " : " error " ,
48- " position " : { " offset " : " ={ req[ expandFreestandingMacro][ syntax][ location][ offset]} " ,
49- " fileName " : " { req[ expandFreestandingMacro][ syntax][ location][ fileName]} " } ,
65+ " position " : { " offset " : " =req. expandFreestandingMacro. syntax. location. offset " ,
66+ " fileName " : " = req. expandFreestandingMacro. syntax. location. fileName" } ,
5067 " message " : " message from plugin " ,
5168 " highlights " : [ ] ,
5269 " notes " : [ ] ,
5370 " fixIts " : [ ] }
54- ] } } ,
55- } ,
56- ]
57-
58- mock_plugin. main ( )
59-
71+ ] } }
72+ }
73+ ] )
0 commit comments