aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/CompilationDatabaseTest.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2020-12-04 09:58:50 +0100
committerSam McCall <sam.mccall@gmail.com>2020-12-07 13:07:10 +0100
commita1cb9cbf5c4939e78a6c3b3677cf8e3dbdf51932 (patch)
tree316d4ad5197b5dbd38baad41528a6394dc012297 /clang/unittests/Tooling/CompilationDatabaseTest.cpp
parent347ea1af348e7b48341be4d85b10a7076483f59c (diff)
downloadllvm-a1cb9cbf5c4939e78a6c3b3677cf8e3dbdf51932.zip
llvm-a1cb9cbf5c4939e78a6c3b3677cf8e3dbdf51932.tar.gz
llvm-a1cb9cbf5c4939e78a6c3b3677cf8e3dbdf51932.tar.bz2
Add ability to load a FixedCompilationDatabase from a buffer.
Previously, loading one from a file meant allowing the library to do the IO. Clangd would prefer to do such IO itself (e.g. to allow caching). Differential Revision: https://reviews.llvm.org/D92640
Diffstat (limited to 'clang/unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r--clang/unittests/Tooling/CompilationDatabaseTest.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 168a1d6..a3ea899 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -543,6 +543,27 @@ TEST(FixedCompilationDatabase, GetAllCompileCommands) {
EXPECT_EQ(0ul, Database.getAllCompileCommands().size());
}
+TEST(FixedCompilationDatabase, FromBuffer) {
+ const char *Data = R"(
+
+ -DFOO=BAR
+
+--baz
+
+ )";
+ std::string ErrorMsg;
+ auto CDB =
+ FixedCompilationDatabase::loadFromBuffer("/cdb/dir", Data, ErrorMsg);
+
+ std::vector<CompileCommand> Result = CDB->getCompileCommands("/foo/bar.cc");
+ ASSERT_EQ(1ul, Result.size());
+ EXPECT_EQ("/cdb/dir", Result.front().Directory);
+ EXPECT_EQ("/foo/bar.cc", Result.front().Filename);
+ EXPECT_THAT(
+ Result.front().CommandLine,
+ ElementsAre(EndsWith("clang-tool"), "-DFOO=BAR", "--baz", "/foo/bar.cc"));
+}
+
TEST(ParseFixedCompilationDatabase, ReturnsNullOnEmptyArgumentList) {
int Argc = 0;
std::string ErrorMsg;