summaryrefslogtreecommitdiff
path: root/unittests/Tooling/CompilationDatabaseTest.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-12-04 07:26:44 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-12-04 07:26:44 +0000
commit7e96bfb4d507700a122f270a11ce3fc0e8e36c85 (patch)
tree373b58577b83eede589540df135b3b3d6bdc373a /unittests/Tooling/CompilationDatabaseTest.cpp
parent1fec8fcfffb653a32fb147505677b3fe1fef2503 (diff)
downloadclang-7e96bfb4d507700a122f270a11ce3fc0e8e36c85.tar.gz
clang-7e96bfb4d507700a122f270a11ce3fc0e8e36c85.tar.bz2
clang-7e96bfb4d507700a122f270a11ce3fc0e8e36c85.tar.xz
Introduce CompilationDatabase::getAllCompileCommands() that returns all
compile commands of the database and expose it via the libclang API. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169226 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r--unittests/Tooling/CompilationDatabaseTest.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/unittests/Tooling/CompilationDatabaseTest.cpp b/unittests/Tooling/CompilationDatabaseTest.cpp
index 5ed4240c1e..3abb818ff2 100644
--- a/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -51,6 +51,17 @@ static std::vector<std::string> getAllFiles(StringRef JSONDatabase,
return Database->getAllFiles();
}
+static std::vector<CompileCommand> getAllCompileCommands(StringRef JSONDatabase,
+ std::string &ErrorMessage) {
+ llvm::OwningPtr<CompilationDatabase> Database(
+ JSONCompilationDatabase::loadFromBuffer(JSONDatabase, ErrorMessage));
+ if (!Database) {
+ ADD_FAILURE() << ErrorMessage;
+ return std::vector<CompileCommand>();
+ }
+ return Database->getAllCompileCommands();
+}
+
TEST(JSONCompilationDatabase, GetAllFiles) {
std::string ErrorMessage;
EXPECT_EQ(std::vector<std::string>(),
@@ -72,6 +83,35 @@ TEST(JSONCompilationDatabase, GetAllFiles) {
ErrorMessage)) << ErrorMessage;
}
+TEST(JSONCompilationDatabase, GetAllCompileCommands) {
+ std::string ErrorMessage;
+ EXPECT_EQ(0u,
+ getAllCompileCommands("[]", ErrorMessage).size()) << ErrorMessage;
+
+ StringRef Directory1("//net/dir1");
+ StringRef FileName1("file1");
+ StringRef Command1("command1");
+ StringRef Directory2("//net/dir2");
+ StringRef FileName2("file1");
+ StringRef Command2("command1");
+
+ std::vector<CompileCommand> Commands = getAllCompileCommands(
+ ("[{\"directory\":\"" + Directory1 + "\"," +
+ "\"command\":\"" + Command1 + "\","
+ "\"file\":\"" + FileName1 + "\"},"
+ " {\"directory\":\"" + Directory2 + "\"," +
+ "\"command\":\"" + Command2 + "\","
+ "\"file\":\"" + FileName2 + "\"}]").str(),
+ ErrorMessage);
+ EXPECT_EQ(2U, Commands.size()) << ErrorMessage;
+ EXPECT_EQ(Directory1, Commands[0].Directory) << ErrorMessage;
+ ASSERT_EQ(1u, Commands[0].CommandLine.size());
+ EXPECT_EQ(Command1, Commands[0].CommandLine[0]) << ErrorMessage;
+ EXPECT_EQ(Directory2, Commands[1].Directory) << ErrorMessage;
+ ASSERT_EQ(1u, Commands[1].CommandLine.size());
+ EXPECT_EQ(Command2, Commands[1].CommandLine[0]) << ErrorMessage;
+}
+
static CompileCommand findCompileArgsInJsonDatabase(StringRef FileName,
StringRef JSONDatabase,
std::string &ErrorMessage) {
@@ -376,6 +416,15 @@ TEST(FixedCompilationDatabase, GetAllFiles) {
EXPECT_EQ(0ul, Database.getAllFiles().size());
}
+TEST(FixedCompilationDatabase, GetAllCompileCommands) {
+ std::vector<std::string> CommandLine;
+ CommandLine.push_back("one");
+ CommandLine.push_back("two");
+ FixedCompilationDatabase Database(".", CommandLine);
+
+ EXPECT_EQ(0ul, Database.getAllCompileCommands().size());
+}
+
TEST(ParseFixedCompilationDatabase, ReturnsNullOnEmptyArgumentList) {
int Argc = 0;
llvm::OwningPtr<FixedCompilationDatabase> Database(