[clang-tools-extra] 98cf77e - [clangd] Clean up old test fixture/names a little. NFC

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 13 08:43:21 PDT 2020


Author: Sam McCall
Date: 2020-08-13T17:43:11+02:00
New Revision: 98cf77e33786eb1d4e258bfafcbd80344ac9b19d

URL: https://github.com/llvm/llvm-project/commit/98cf77e33786eb1d4e258bfafcbd80344ac9b19d
DIFF: https://github.com/llvm/llvm-project/commit/98cf77e33786eb1d4e258bfafcbd80344ac9b19d.diff

LOG: [clangd] Clean up old test fixture/names a little. NFC

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
index a7c25683e9c1..284b241b47fa 100644
--- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -160,36 +160,33 @@ std::string dumpASTWithoutMemoryLocs(ClangdServer &Server, PathRef File) {
   return replacePtrsInDump(dumpAST(Server, File));
 }
 
-class ClangdVFSTest : public ::testing::Test {
-protected:
-  std::string parseSourceAndDumpAST(
-      PathRef SourceFileRelPath, llvm::StringRef SourceContents,
-      std::vector<std::pair<PathRef, llvm::StringRef>> ExtraFiles = {},
-      bool ExpectErrors = false) {
-    MockFS FS;
-    ErrorCheckingCallbacks DiagConsumer;
-    MockCompilationDatabase CDB;
-    ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer);
-    for (const auto &FileWithContents : ExtraFiles)
-      FS.Files[testPath(FileWithContents.first)] =
-          std::string(FileWithContents.second);
-
-    auto SourceFilename = testPath(SourceFileRelPath);
-    Server.addDocument(SourceFilename, SourceContents);
-    auto Result = dumpASTWithoutMemoryLocs(Server, SourceFilename);
-    EXPECT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for diagnostics";
-    EXPECT_EQ(ExpectErrors, DiagConsumer.hadErrorInLastDiags());
-    return Result;
-  }
-};
+std::string parseSourceAndDumpAST(
+    PathRef SourceFileRelPath, llvm::StringRef SourceContents,
+    std::vector<std::pair<PathRef, llvm::StringRef>> ExtraFiles = {},
+    bool ExpectErrors = false) {
+  MockFS FS;
+  ErrorCheckingCallbacks DiagConsumer;
+  MockCompilationDatabase CDB;
+  ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer);
+  for (const auto &FileWithContents : ExtraFiles)
+    FS.Files[testPath(FileWithContents.first)] =
+        std::string(FileWithContents.second);
+
+  auto SourceFilename = testPath(SourceFileRelPath);
+  Server.addDocument(SourceFilename, SourceContents);
+  auto Result = dumpASTWithoutMemoryLocs(Server, SourceFilename);
+  EXPECT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for diagnostics";
+  EXPECT_EQ(ExpectErrors, DiagConsumer.hadErrorInLastDiags());
+  return Result;
+}
 
-TEST_F(ClangdVFSTest, Parse) {
+TEST(ClangdServerTest, Parse) {
   // FIXME: figure out a stable format for AST dumps, so that we can check the
   // output of the dump itself is equal to the expected one, not just that it's
   // 
diff erent.
-  auto Empty = parseSourceAndDumpAST("foo.cpp", "", {});
-  auto OneDecl = parseSourceAndDumpAST("foo.cpp", "int a;", {});
-  auto SomeDecls = parseSourceAndDumpAST("foo.cpp", "int a; int b; int c;", {});
+  auto Empty = parseSourceAndDumpAST("foo.cpp", "");
+  auto OneDecl = parseSourceAndDumpAST("foo.cpp", "int a;");
+  auto SomeDecls = parseSourceAndDumpAST("foo.cpp", "int a; int b; int c;");
   EXPECT_NE(Empty, OneDecl);
   EXPECT_NE(Empty, SomeDecls);
   EXPECT_NE(SomeDecls, OneDecl);
@@ -202,7 +199,7 @@ TEST_F(ClangdVFSTest, Parse) {
   EXPECT_EQ(SomeDecls, SomeDecls2);
 }
 
-TEST_F(ClangdVFSTest, ParseWithHeader) {
+TEST(ClangdServerTest, ParseWithHeader) {
   parseSourceAndDumpAST("foo.cpp", "#include \"foo.h\"", {},
                         /*ExpectErrors=*/true);
   parseSourceAndDumpAST("foo.cpp", "#include \"foo.h\"", {{"foo.h", ""}},
@@ -218,7 +215,7 @@ int b = a;
                         /*ExpectErrors=*/false);
 }
 
-TEST_F(ClangdVFSTest, Reparse) {
+TEST(ClangdServerTest, Reparse) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;
@@ -253,7 +250,7 @@ int b = a;
   EXPECT_NE(DumpParse1, DumpParseEmpty);
 }
 
-TEST_F(ClangdVFSTest, ReparseOnHeaderChange) {
+TEST(ClangdServerTest, ReparseOnHeaderChange) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;
@@ -291,7 +288,7 @@ int b = a;
   EXPECT_NE(DumpParse1, DumpParseDifferent);
 }
 
-TEST_F(ClangdVFSTest, PropagatesContexts) {
+TEST(ClangdServerTest, PropagatesContexts) {
   static Key<int> Secret;
   struct ContextReadingFS : public ThreadsafeFS {
     mutable int Got;
@@ -364,7 +361,7 @@ TEST(ClangdServerTest, RespectsConfig) {
   EXPECT_NE(Result->front().PreferredDeclaration.range, Example.range());
 }
 
-TEST_F(ClangdVFSTest, PropagatesVersion) {
+TEST(ClangdServerTest, PropagatesVersion) {
   MockCompilationDatabase CDB;
   MockFS FS;
   struct Callbacks : public ClangdServer::Callbacks {
@@ -383,7 +380,7 @@ TEST_F(ClangdVFSTest, PropagatesVersion) {
 
 // Only enable this test on Unix
 #ifdef LLVM_ON_UNIX
-TEST_F(ClangdVFSTest, SearchLibDir) {
+TEST(ClangdServerTest, SearchLibDir) {
   // Checks that searches for GCC installation is done through vfs.
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
@@ -433,7 +430,7 @@ std::string x;
 }
 #endif // LLVM_ON_UNIX
 
-TEST_F(ClangdVFSTest, ForceReparseCompileCommand) {
+TEST(ClangdServerTest, ForceReparseCompileCommand) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;
@@ -469,7 +466,7 @@ struct bar { T x; };
   EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
 }
 
-TEST_F(ClangdVFSTest, ForceReparseCompileCommandDefines) {
+TEST(ClangdServerTest, ForceReparseCompileCommandDefines) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;
@@ -501,7 +498,7 @@ int main() { return 0; }
 }
 
 // Test ClangdServer.reparseOpenedFiles.
-TEST_F(ClangdVFSTest, ReparseOpenedFiles) {
+TEST(ClangdServerTest, ReparseOpenedFiles) {
   Annotations FooSource(R"cpp(
 #ifdef MACRO
 static void $one[[bob]]() {}
@@ -571,7 +568,7 @@ MATCHER_P4(Stats, Name, UsesMemory, PreambleBuilds, ASTBuilds, "") {
              std::tie(PreambleBuilds, ASTBuilds);
 }
 
-TEST_F(ClangdVFSTest, FileStats) {
+TEST(ClangdServerTest, FileStats) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;
@@ -607,7 +604,7 @@ struct Something {
   EXPECT_THAT(Server.fileStats(), IsEmpty());
 }
 
-TEST_F(ClangdVFSTest, InvalidCompileCommand) {
+TEST(ClangdServerTest, InvalidCompileCommand) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;
@@ -637,9 +634,7 @@ TEST_F(ClangdVFSTest, InvalidCompileCommand) {
                           Field(&CodeCompletion::Name, "main")));
 }
 
-class ClangdThreadingTest : public ClangdVFSTest {};
-
-TEST_F(ClangdThreadingTest, StressTest) {
+TEST(ClangdThreadingTest, StressTest) {
   // Without 'static' clang gives an error for a usage inside TestDiagConsumer.
   static const unsigned FilesCount = 5;
   const unsigned RequestsCount = 500;
@@ -857,7 +852,7 @@ int d;
   }
 }
 
-TEST_F(ClangdThreadingTest, NoConcurrentDiagnostics) {
+TEST(ClangdThreadingTest, NoConcurrentDiagnostics) {
   class NoConcurrentAccessDiagConsumer : public ClangdServer::Callbacks {
   public:
     std::atomic<int> Count = {0};
@@ -919,7 +914,7 @@ int d;
   ASSERT_EQ(DiagConsumer.Count, 2); // Sanity check - we actually ran both?
 }
 
-TEST_F(ClangdVFSTest, FormatCode) {
+TEST(ClangdServerTest, FormatCode) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;
@@ -948,7 +943,7 @@ void f() {}
   EXPECT_EQ(Expected, *Changed);
 }
 
-TEST_F(ClangdVFSTest, ChangedHeaderFromISystem) {
+TEST(ClangdServerTest, ChangedHeaderFromISystem) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;
@@ -1054,7 +1049,7 @@ TEST(ClangdTests, PreambleVFSStatCache) {
 }
 #endif
 
-TEST_F(ClangdVFSTest, FallbackWhenPreambleIsNotReady) {
+TEST(ClangdServerTest, FallbackWhenPreambleIsNotReady) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;
@@ -1100,7 +1095,7 @@ TEST_F(ClangdVFSTest, FallbackWhenPreambleIsNotReady) {
                         Field(&CodeCompletion::Scope, ""))));
 }
 
-TEST_F(ClangdVFSTest, FallbackWhenWaitingForCompileCommand) {
+TEST(ClangdServerTest, FallbackWhenWaitingForCompileCommand) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   // Returns compile command only when notified.
@@ -1177,7 +1172,7 @@ TEST(ClangdServerTest, CustomAction) {
 // Tests fails when built with asan due to stack overflow. So skip running the
 // test as a workaround.
 #if !defined(__has_feature) || !__has_feature(address_sanitizer)
-TEST_F(ClangdVFSTest, TestStackOverflow) {
+TEST(ClangdServerTest, TestStackOverflow) {
   MockFS FS;
   ErrorCheckingCallbacks DiagConsumer;
   MockCompilationDatabase CDB;


        


More information about the cfe-commits mailing list