diff --git a/clang-tools-extra/clangd/test/Inputs/implicit-modules/MyModule.h b/clang-tools-extra/clangd/test/Inputs/implicit-modules/MyModule.h new file mode 100644 --- /dev/null +++ b/clang-tools-extra/clangd/test/Inputs/implicit-modules/MyModule.h @@ -0,0 +1 @@ +#import "hdr.h" diff --git a/clang-tools-extra/clangd/test/Inputs/implicit-modules/compile_commands.json b/clang-tools-extra/clangd/test/Inputs/implicit-modules/compile_commands.json new file mode 100644 --- /dev/null +++ b/clang-tools-extra/clangd/test/Inputs/implicit-modules/compile_commands.json @@ -0,0 +1,5 @@ +[{ + "directory": "DIRECTORY", + "command": "clang -c implicit-modules.m -I DIRECTORY -fmodules -fimplicit-modules", + "file": "DIRECTORY/implicit-modules.m" +}] diff --git a/clang-tools-extra/clangd/test/Inputs/implicit-modules/hdr.h b/clang-tools-extra/clangd/test/Inputs/implicit-modules/hdr.h new file mode 100644 --- /dev/null +++ b/clang-tools-extra/clangd/test/Inputs/implicit-modules/hdr.h @@ -0,0 +1 @@ +char foo(int x, int y); diff --git a/clang-tools-extra/clangd/test/Inputs/implicit-modules/implicit-modules.m b/clang-tools-extra/clangd/test/Inputs/implicit-modules/implicit-modules.m new file mode 100644 --- /dev/null +++ b/clang-tools-extra/clangd/test/Inputs/implicit-modules/implicit-modules.m @@ -0,0 +1,6 @@ +@import MyModule; + +int main() { + void *_ = foo(1, 2); + return foo(1, 2); +} diff --git a/clang-tools-extra/clangd/test/Inputs/implicit-modules/module.modulemap b/clang-tools-extra/clangd/test/Inputs/implicit-modules/module.modulemap new file mode 100644 --- /dev/null +++ b/clang-tools-extra/clangd/test/Inputs/implicit-modules/module.modulemap @@ -0,0 +1,6 @@ +module MyModule { + umbrella header "MyModule.h" + + export * + module * { export * } +} \ No newline at end of file diff --git a/clang-tools-extra/clangd/test/Inputs/implicit-modules/open.jsonrpc b/clang-tools-extra/clangd/test/Inputs/implicit-modules/open.jsonrpc new file mode 100644 --- /dev/null +++ b/clang-tools-extra/clangd/test/Inputs/implicit-modules/open.jsonrpc @@ -0,0 +1,52 @@ +{ + "jsonrpc": "2.0", + "id": 0, + "method": "initialize", + "params": { + "processId": 123, + "rootPath": "clangd", + "capabilities": {}, + "trace": "off" + } +} +--- +{ + "jsonrpc": "2.0", + "method": "textDocument/didOpen", + "params": { + "textDocument": { + "uri": "file://DIRECTORY/implicit-modules.m", + "languageId": "objective-c", + "version": 1, + "text": "@import MyModule;\n\nint main(){\nvoid *_ = foo(1, 2);\nreturn foo(1, 2);\n}" + } + } +} +--- +{ + "jsonrpc": "2.0", + "id": 1, + "method": "sync", + "params": null +} +# CHECK: "diagnostics": [ +# CHECK: { +# CHECK: "code": "-Wint-conversion", +# CHECK: "message": "Incompatible integer to pointer conversion initializing 'void *' with an expression of type 'char'", +# CHECK: "range": { +# CHECK: "end": { +# CHECK: "character": 7, +# CHECK: "line": 3 +# CHECK: }, +# CHECK: "start": { +# CHECK: "character": 6, +# CHECK: "line": 3 +# CHECK: } +# CHECK: }, +# CHECK: "severity": 2, +# CHECK: "source": "clang" +# CHECK: } +--- +{"jsonrpc":"2.0","id":3,"method":"shutdown"} +--- +{"jsonrpc":"2.0","method":"exit"} diff --git a/clang-tools-extra/clangd/test/implicit-modules.test b/clang-tools-extra/clangd/test/implicit-modules.test new file mode 100644 --- /dev/null +++ b/clang-tools-extra/clangd/test/implicit-modules.test @@ -0,0 +1,11 @@ +# We need to splice paths into file:// URIs for this test. +# UNSUPPORTED: windows-msvc + +# Use a copy of inputs, as we'll mutate it (as will the background index). +# RUN: rm -rf %t +# RUN: cp -r %S/Inputs/implicit-modules %t +# Need to embed the correct temp path in the actual JSON-RPC requests. +# RUN: sed -i -e "s|DIRECTORY|%t|" %t/open.jsonrpc +# RUN: sed -i -e "s|DIRECTORY|%t|" %t/compile_commands.json + +# RUN: clangd -lit-test < %t/open.jsonrpc | FileCheck %t/open.jsonrpc