Debian Codegraph @

clang-tools-extra/clangd/test/modules.test

raw
1 # A smoke test to check the modules can work basically.
2 #
3 # Windows have different escaping modes.
4 # FIXME: We should add one for windows.
5 # UNSUPPORTED: system-windows
6 #
7 # RUN: rm -fr %t
8 # RUN: mkdir -p %t
9 # RUN: split-file %s %t
10 #
11 # RUN: sed -e "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json.tmp
12 # RUN: sed -e "s|CLANG_CC|%clang|g" %t/compile_commands.json.tmp > %t/compile_commands.json
13 # RUN: sed -e "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc
14 #
15 # RUN: clangd -experimental-modules-support -lit-test < %t/definition.jsonrpc \
16 # RUN: | FileCheck -strict-whitespace %t/definition.jsonrpc
17
18 #--- A.cppm
19 export module A;
20 export void printA() {}
21
22 #--- Use.cpp
23 import A;
24 void foo() {
25 print
26 }
27
28 #--- compile_commands.json.tmpl
29 [
30 {
31 "directory": "DIR",
32 "command": "CLANG_CC -fprebuilt-module-path=DIR -std=c++20 -o DIR/main.cpp.o -c DIR/Use.cpp",
33 "file": "DIR/Use.cpp"
34 },
35 {
36 "directory": "DIR",
37 "command": "CLANG_CC -std=c++20 DIR/A.cppm --precompile -o DIR/A.pcm",
38 "file": "DIR/A.cppm"
39 }
40 ]
41
42 #--- definition.jsonrpc.tmpl
43 {
44 "jsonrpc": "2.0",
45 "id": 0,
46 "method": "initialize",
47 "params": {
48 "processId": 123,
49 "rootPath": "clangd",
50 "capabilities": {
51 "textDocument": {
52 "completion": {
53 "completionItem": {
54 "snippetSupport": true
55 }
56 }
57 }
58 },
59 "trace": "off"
60 }
61 }
62 ---
63 {
64 "jsonrpc": "2.0",
65 "method": "textDocument/didOpen",
66 "params": {
67 "textDocument": {
68 "uri": "file://DIR/Use.cpp",
69 "languageId": "cpp",
70 "version": 1,
71 "text": "import A;\nvoid foo() {\n print\n}\n"
72 }
73 }
74 }
75
76 # CHECK: "message"{{.*}}printA{{.*}}(fix available)
77
78 ---
79 {"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file://DIR/Use.cpp"},"context":{"triggerKind":1},"position":{"line":2,"character":6}}}
80 ---
81 {"jsonrpc":"2.0","id":2,"method":"shutdown"}
82 ---
83 {"jsonrpc":"2.0","method":"exit"}