arphaman created this revision.
arphaman added reviewers: sammccall, jkorous.
Herald added subscribers: usaxena95, ributzka, kadircet, dexonsmith, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

This patch adds a test case that verifies that `-fmodules -fimplicit-modules` 
work in Clangd when building the AST for Objective-C sources.

I based it on the test case attached to 
https://github.com/clangd/clangd/issues/198. I'm still looking into 
https://github.com/clangd/clangd/issues/198, but it might be unrelated to 
`-fimplicit-modules` support.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71586

Files:
  clang-tools-extra/clangd/test/Inputs/implicit-modules/MyModule.h
  clang-tools-extra/clangd/test/Inputs/implicit-modules/compile_commands.json
  clang-tools-extra/clangd/test/Inputs/implicit-modules/hdr.h
  clang-tools-extra/clangd/test/Inputs/implicit-modules/implicit-modules.m
  clang-tools-extra/clangd/test/Inputs/implicit-modules/module.modulemap
  clang-tools-extra/clangd/test/Inputs/implicit-modules/open.jsonrpc
  clang-tools-extra/clangd/test/implicit-modules.test

Index: clang-tools-extra/clangd/test/implicit-modules.test
===================================================================
--- /dev/null
+++ 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
Index: clang-tools-extra/clangd/test/Inputs/implicit-modules/open.jsonrpc
===================================================================
--- /dev/null
+++ 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"}
Index: clang-tools-extra/clangd/test/Inputs/implicit-modules/module.modulemap
===================================================================
--- /dev/null
+++ 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
Index: clang-tools-extra/clangd/test/Inputs/implicit-modules/implicit-modules.m
===================================================================
--- /dev/null
+++ 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);
+}
Index: clang-tools-extra/clangd/test/Inputs/implicit-modules/hdr.h
===================================================================
--- /dev/null
+++ clang-tools-extra/clangd/test/Inputs/implicit-modules/hdr.h
@@ -0,0 +1 @@
+char foo(int x, int y);
Index: clang-tools-extra/clangd/test/Inputs/implicit-modules/compile_commands.json
===================================================================
--- /dev/null
+++ 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"
+}]
Index: clang-tools-extra/clangd/test/Inputs/implicit-modules/MyModule.h
===================================================================
--- /dev/null
+++ clang-tools-extra/clangd/test/Inputs/implicit-modules/MyModule.h
@@ -0,0 +1 @@
+#import "hdr.h"
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to