[clang-tools-extra] 751d4da - [clangd] Assert that the testcases in LocateSymbol.All have no diagnostics

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 7 09:13:54 PST 2020


Author: Nathan Ridge
Date: 2020-01-07T12:13:32-05:00
New Revision: 751d4dae3284c466481ed20ec0b76e894527d2c6

URL: https://github.com/llvm/llvm-project/commit/751d4dae3284c466481ed20ec0b76e894527d2c6
DIFF: https://github.com/llvm/llvm-project/commit/751d4dae3284c466481ed20ec0b76e894527d2c6.diff

LOG: [clangd] Assert that the testcases in LocateSymbol.All have no diagnostics

Summary: Also fix some bugs in the testcases which this exposed.

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72066

Added: 
    

Modified: 
    clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index a08d117fc2f8..a37b80a99c43 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -253,7 +253,7 @@ TEST(LocateSymbol, All) {
       )cpp",
 
       R"cpp(// Function definition via pointer
-        int [[foo]](int) {}
+        void [[foo]](int) {}
         int main() {
           auto *X = &^foo;
         }
@@ -270,7 +270,7 @@ TEST(LocateSymbol, All) {
         struct Foo { int [[x]]; };
         int main() {
           Foo bar;
-          bar.^x;
+          (void)bar.^x;
         }
       )cpp",
 
@@ -281,13 +281,6 @@ TEST(LocateSymbol, All) {
         };
       )cpp",
 
-      R"cpp(// Field, GNU old-style field designator
-        struct Foo { int [[x]]; };
-        int main() {
-          Foo bar = { ^x : 1 };
-        }
-      )cpp",
-
       R"cpp(// Field, field designator
         struct Foo { int [[x]]; };
         int main() {
@@ -322,19 +315,11 @@ TEST(LocateSymbol, All) {
 
       R"cpp(// Namespace
         namespace $decl[[ns]] {
-        struct Foo { static void bar(); }
+        struct Foo { static void bar(); };
         } // namespace ns
         int main() { ^ns::Foo::bar(); }
       )cpp",
 
-      R"cpp(// Macro
-        #define MACRO 0
-        #define [[MACRO]] 1
-        int main() { return ^MACRO; }
-        #define MACRO 2
-        #undef macro
-      )cpp",
-
       R"cpp(// Macro
        class TTT { public: int a; };
        #define [[FF]](S) if (int b = S.a) {}
@@ -352,7 +337,7 @@ TEST(LocateSymbol, All) {
 
       R"cpp(// Symbol concatenated inside macro (not supported)
        int *pi;
-       #define POINTER(X) p # X;
+       #define POINTER(X) p ## X;
        int i = *POINTER(^i);
       )cpp",
 
@@ -433,10 +418,10 @@ TEST(LocateSymbol, All) {
       )cpp",
 
       R"cpp(// No implicit constructors
-        class X {
+        struct X {
           X(X&& x) = default;
         };
-        X [[makeX]]() {}
+        X $decl[[makeX]]();
         void foo() {
           auto x = m^akeX();
         }
@@ -444,7 +429,7 @@ TEST(LocateSymbol, All) {
 
       R"cpp(
         struct X {
-          X& [[operator]]++() {}
+          X& $decl[[operator]]++();
         };
         void foo(X& x) {
           +^+x;
@@ -529,6 +514,61 @@ TEST(LocateSymbol, All) {
     // parsing.
     TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
 
+    auto AST = TU.build();
+    for (auto &D : AST.getDiagnostics())
+      ADD_FAILURE() << D;
+    ASSERT_TRUE(AST.getDiagnostics().empty()) << Test;
+
+    auto Results = locateSymbolAt(AST, T.point());
+
+    if (!WantDecl) {
+      EXPECT_THAT(Results, IsEmpty()) << Test;
+    } else {
+      ASSERT_THAT(Results, ::testing::SizeIs(1)) << Test;
+      EXPECT_EQ(Results[0].PreferredDeclaration.range, *WantDecl) << Test;
+      llvm::Optional<Range> GotDef;
+      if (Results[0].Definition)
+        GotDef = Results[0].Definition->range;
+      EXPECT_EQ(WantDef, GotDef) << Test;
+    }
+  }
+}
+
+// LocateSymbol test cases that produce warnings.
+// These are separated out from All so that in All we can assert
+// that there are no diagnostics.
+TEST(LocateSymbol, Warnings) {
+  const char *Tests[] = {
+      R"cpp(// Field, GNU old-style field designator
+        struct Foo { int [[x]]; };
+        int main() {
+          Foo bar = { ^x : 1 };
+        }
+      )cpp",
+
+      R"cpp(// Macro
+        #define MACRO 0
+        #define [[MACRO]] 1
+        int main() { return ^MACRO; }
+        #define MACRO 2
+        #undef macro
+      )cpp",
+  };
+
+  for (const char *Test : Tests) {
+    Annotations T(Test);
+    llvm::Optional<Range> WantDecl;
+    llvm::Optional<Range> WantDef;
+    if (!T.ranges().empty())
+      WantDecl = WantDef = T.range();
+    if (!T.ranges("decl").empty())
+      WantDecl = T.range("decl");
+    if (!T.ranges("def").empty())
+      WantDef = T.range("def");
+
+    TestTU TU;
+    TU.Code = T.code();
+
     auto AST = TU.build();
     auto Results = locateSymbolAt(AST, T.point());
 


        


More information about the cfe-commits mailing list