Debian Codegraph @

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

raw
1 # A smoke test to check that a simple dependency chain for modules can work.
2 #
3 # FIXME: The test fails on Windows; see comments on https://github.com/llvm/llvm-project/pull/142828
4 # UNSUPPORTED: system-windows
5 #
6 # RUN: rm -fr %t
7 # RUN: mkdir -p %t
8 # RUN: split-file %s %t
9 #
10 # RUN: sed -e "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json.tmp
11 # RUN: sed -e "s|CLANG_CC|%clang|g" %t/compile_commands.json.tmp > %t/compile_commands.json
12 # RUN: sed -e "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc.tmp
13 #
14 # On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
15 # (with the extra slash in the front), so we add it here.
16 # RUN: sed -E -e 's|"file://([A-Z]):/|"file:///\1:/|g' %/t/definition.jsonrpc.tmp > %/t/definition.jsonrpc
17 #
18 # RUN: clangd -experimental-modules-support -lit-test < %t/definition.jsonrpc \
19 # RUN: | FileCheck -strict-whitespace %t/definition.jsonrpc
20
21 #--- A-frag.cppm
22 export module A:frag;
23 export void printA() {}
24
25 #--- A.cppm
26 export module A;
27 export import :frag;
28
29 #--- Use.cpp
30 import A;
31 void foo() {
32 print
33 }
34
35 #--- compile_commands.json.tmpl
36 [
37 {
38 "directory": "DIR",
39 "command": "CLANG_CC -fprebuilt-module-path=DIR -std=c++20 -o DIR/main.cpp.o -c DIR/Use.cpp",
40 "file": "DIR/Use.cpp"
41 },
42 {
43 "directory": "DIR",
44 "command": "CLANG_CC -std=c++20 DIR/A.cppm --precompile -o DIR/A.pcm",
45 "file": "DIR/A.cppm"
46 },
47 {
48 "directory": "DIR",
49 "command": "CLANG_CC -std=c++20 DIR/A-frag.cppm --precompile -o DIR/A-frag.pcm",
50 "file": "DIR/A-frag.cppm"
51 }
52 ]
53
54 #--- definition.jsonrpc.tmpl
55 {
56 "jsonrpc": "2.0",
57 "id": 0,
58 "method": "initialize",
59 "params": {
60 "processId": 123,
61 "rootPath": "clangd",
62 "capabilities": {
63 "textDocument": {
64 "completion": {
65 "completionItem": {
66 "snippetSupport": true
67 }
68 }
69 }
70 },
71 "trace": "off"
72 }
73 }
74 ---
75 {
76 "jsonrpc": "2.0",
77 "method": "textDocument/didOpen",
78 "params": {
79 "textDocument": {
80 "uri": "file://DIR/Use.cpp",
81 "languageId": "cpp",
82 "version": 1,
83 "text": "import A;\nvoid foo() {\n print\n}\n"
84 }
85 }
86 }
87
88 # CHECK: "message"{{.*}}printA{{.*}}(fix available)
89
90 ---
91 {"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file://DIR/Use.cpp"},"context":{"triggerKind":1},"position":{"line":2,"character":6}}}
92 ---
93 {"jsonrpc":"2.0","id":2,"method":"shutdown"}
94 ---
95 {"jsonrpc":"2.0","method":"exit"}