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
// different.
- 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);
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", ""}},
/*ExpectErrors=*/false);
}
-TEST_F(ClangdVFSTest, Reparse) {
+TEST(ClangdServerTest, Reparse) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
EXPECT_NE(DumpParse1, DumpParseEmpty);
}
-TEST_F(ClangdVFSTest, ReparseOnHeaderChange) {
+TEST(ClangdServerTest, ReparseOnHeaderChange) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
EXPECT_NE(DumpParse1, DumpParseDifferent);
}
-TEST_F(ClangdVFSTest, PropagatesContexts) {
+TEST(ClangdServerTest, PropagatesContexts) {
static Key<int> Secret;
struct ContextReadingFS : public ThreadsafeFS {
mutable int Got;
EXPECT_NE(Result->front().PreferredDeclaration.range, Example.range());
}
-TEST_F(ClangdVFSTest, PropagatesVersion) {
+TEST(ClangdServerTest, PropagatesVersion) {
MockCompilationDatabase CDB;
MockFS FS;
struct Callbacks : public ClangdServer::Callbacks {
// 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;
}
#endif // LLVM_ON_UNIX
-TEST_F(ClangdVFSTest, ForceReparseCompileCommand) {
+TEST(ClangdServerTest, ForceReparseCompileCommand) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
}
-TEST_F(ClangdVFSTest, ForceReparseCompileCommandDefines) {
+TEST(ClangdServerTest, ForceReparseCompileCommandDefines) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
}
// Test ClangdServer.reparseOpenedFiles.
-TEST_F(ClangdVFSTest, ReparseOpenedFiles) {
+TEST(ClangdServerTest, ReparseOpenedFiles) {
Annotations FooSource(R"cpp(
#ifdef MACRO
static void $one[[bob]]() {}
std::tie(PreambleBuilds, ASTBuilds);
}
-TEST_F(ClangdVFSTest, FileStats) {
+TEST(ClangdServerTest, FileStats) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
EXPECT_THAT(Server.fileStats(), IsEmpty());
}
-TEST_F(ClangdVFSTest, InvalidCompileCommand) {
+TEST(ClangdServerTest, InvalidCompileCommand) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
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;
}
}
-TEST_F(ClangdThreadingTest, NoConcurrentDiagnostics) {
+TEST(ClangdThreadingTest, NoConcurrentDiagnostics) {
class NoConcurrentAccessDiagConsumer : public ClangdServer::Callbacks {
public:
std::atomic<int> Count = {0};
ASSERT_EQ(DiagConsumer.Count, 2); // Sanity check - we actually ran both?
}
-TEST_F(ClangdVFSTest, FormatCode) {
+TEST(ClangdServerTest, FormatCode) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
EXPECT_EQ(Expected, *Changed);
}
-TEST_F(ClangdVFSTest, ChangedHeaderFromISystem) {
+TEST(ClangdServerTest, ChangedHeaderFromISystem) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
}
#endif
-TEST_F(ClangdVFSTest, FallbackWhenPreambleIsNotReady) {
+TEST(ClangdServerTest, FallbackWhenPreambleIsNotReady) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
Field(&CodeCompletion::Scope, ""))));
}
-TEST_F(ClangdVFSTest, FallbackWhenWaitingForCompileCommand) {
+TEST(ClangdServerTest, FallbackWhenWaitingForCompileCommand) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
// Returns compile command only when notified.
// 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;