3
3
// RUN: %empty-directory(%t)
4
4
// RUN: split-file %s %t
5
5
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
9
13
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
11
23
12
24
//--- test.swift
13
25
@freestanding ( expression) macro testString( _: Any ) -> String = #externalMacro( module: " TestPlugin " , type: " TestStringMacro " )
@@ -19,41 +31,43 @@ func test() {
19
31
// expected-error @-1 {{message from plugin}}
20
32
}
21
33
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: ------------------------------
26
42
27
- import mock_plugin
43
+ //--- plugin.c
44
+ #include " swift-c/MockPlugin/MockPlugin.h "
28
45
29
- mock_plugin . TEST_SPEC = [
46
+ MOCK_PLUGIN ( [
30
47
{
31
48
" expect " : { " getCapability " : { } } ,
32
- " response " : { " getCapabilityResult " : { " capability " : { " protocolVersion " : 1 } } } ,
49
+ " response " : { " getCapabilityResult " : { " capability " : { " protocolVersion " : 1 } } }
33
50
} ,
34
51
{
35
52
" expect " : { " expandFreestandingMacro " : {
36
53
" macro " : { " moduleName " : " TestPlugin " , " typeName " : " TestStringMacro " } ,
37
54
" syntax " : { " kind " : " expression " , " source " : " #testString(123) " } } } ,
38
- " response " : { " expandFreestandingMacroResult " : { " expandedSource " : " \" 123 \" " , " diagnostics " : [ ] } } ,
55
+ " response " : { " expandFreestandingMacroResult " : { " expandedSource " : " \" 123 \" \n + \" foo \" " , " diagnostics " : [ ] } }
39
56
} ,
40
57
{
41
58
" expect " : { " expandFreestandingMacro " : {
42
59
" macro " : { " moduleName " : " TestPlugin " , " typeName " : " TestStringWithErrorMacro " } ,
43
60
" syntax " : { " kind " : " expression " , " source " : " #testStringWithError(321) " } } } ,
44
61
" response " : { " expandFreestandingMacroResult " : {
45
- " expandedSource " : " \" 123 \" " ,
62
+ " expandedSource " : " \" bar \" " ,
46
63
" diagnostics " : [
47
64
{ " 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" } ,
50
67
" message " : " message from plugin " ,
51
68
" highlights " : [ ] ,
52
69
" notes " : [ ] ,
53
70
" fixIts " : [ ] }
54
- ] } } ,
55
- } ,
56
- ]
57
-
58
- mock_plugin. main ( )
59
-
71
+ ] } }
72
+ }
73
+ ] )
0 commit comments