Skip to content

Commit

Permalink
[clangd] Clean up old test fixture/names a little. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-mccall committed Aug 13, 2020
1 parent dd1a900 commit 98cf77e
Showing 1 changed file with 41 additions and 46 deletions.
87 changes: 41 additions & 46 deletions clang-tools-extra/clangd/unittests/ClangdTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 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);
Expand All @@ -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", ""}},
Expand All @@ -218,7 +215,7 @@ int b = a;
/*ExpectErrors=*/false);
}

TEST_F(ClangdVFSTest, Reparse) {
TEST(ClangdServerTest, Reparse) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
Expand Down Expand Up @@ -253,7 +250,7 @@ int b = a;
EXPECT_NE(DumpParse1, DumpParseEmpty);
}

TEST_F(ClangdVFSTest, ReparseOnHeaderChange) {
TEST(ClangdServerTest, ReparseOnHeaderChange) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -433,7 +430,7 @@ std::string x;
}
#endif // LLVM_ON_UNIX

TEST_F(ClangdVFSTest, ForceReparseCompileCommand) {
TEST(ClangdServerTest, ForceReparseCompileCommand) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]]() {}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -607,7 +604,7 @@ struct Something {
EXPECT_THAT(Server.fileStats(), IsEmpty());
}

TEST_F(ClangdVFSTest, InvalidCompileCommand) {
TEST(ClangdServerTest, InvalidCompileCommand) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -857,7 +852,7 @@ int d;
}
}

TEST_F(ClangdThreadingTest, NoConcurrentDiagnostics) {
TEST(ClangdThreadingTest, NoConcurrentDiagnostics) {
class NoConcurrentAccessDiagConsumer : public ClangdServer::Callbacks {
public:
std::atomic<int> Count = {0};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -948,7 +943,7 @@ void f() {}
EXPECT_EQ(Expected, *Changed);
}

TEST_F(ClangdVFSTest, ChangedHeaderFromISystem) {
TEST(ClangdServerTest, ChangedHeaderFromISystem) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
Expand Down Expand Up @@ -1054,7 +1049,7 @@ TEST(ClangdTests, PreambleVFSStatCache) {
}
#endif

TEST_F(ClangdVFSTest, FallbackWhenPreambleIsNotReady) {
TEST(ClangdServerTest, FallbackWhenPreambleIsNotReady) {
MockFS FS;
ErrorCheckingCallbacks DiagConsumer;
MockCompilationDatabase CDB;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 98cf77e

Please sign in to comment.