aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Ridge <zeratul976@hotmail.com>2020-01-02 01:08:05 -0500
committerNathan Ridge <zeratul976@hotmail.com>2020-01-07 12:13:32 -0500
commit751d4dae3284c466481ed20ec0b76e894527d2c6 (patch)
treea293f48c4c84ccf33395fae3b5503a049729021b
parent57835d0198418ca6e397f4b0a50dc6057d93c04c (diff)
downloadllvm-751d4dae3284c466481ed20ec0b76e894527d2c6.zip
llvm-751d4dae3284c466481ed20ec0b76e894527d2c6.tar.gz
llvm-751d4dae3284c466481ed20ec0b76e894527d2c6.tar.bz2
[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
-rw-r--r--clang-tools-extra/clangd/unittests/XRefsTests.cpp84
1 files changed, 62 insertions, 22 deletions
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index a08d117..a37b80a 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,20 +315,12 @@ 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) {}
void f() {
@@ -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;
@@ -530,6 +515,61 @@ TEST(LocateSymbol, All) {
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());
if (!WantDecl) {