summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Tooling/CompilationDatabaseTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2012-07-13 12:31:45 +0000
committerManuel Klimek <klimek@google.com>2012-07-13 12:31:45 +0000
commit60b801619742af8bb5a9c949d6a979e8f48be43b (patch)
treedf7895c27b79b0e77b477fdda815810ac55929e2 /clang/unittests/Tooling/CompilationDatabaseTest.cpp
parent5a5928a5ebad0dff089ce06e3d9200a6392f647d (diff)
downloadbcm5719-llvm-60b801619742af8bb5a9c949d6a979e8f48be43b.tar.gz
bcm5719-llvm-60b801619742af8bb5a9c949d6a979e8f48be43b.zip
Allows retrieving all files in a CompilationDatabase.
Patch by Tobias Koenig, some test changes by myself. llvm-svn: 160167
Diffstat (limited to 'clang/unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r--clang/unittests/Tooling/CompilationDatabaseTest.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 7753c154100..591d48dbbd6 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -38,6 +38,35 @@ TEST(JSONCompilationDatabase, ErrsOnInvalidFormat) {
expectFailure("[{\"command\":\"\",\"file\":\"\"}]", "Missing directory");
}
+static std::vector<std::string> getAllFiles(StringRef JSONDatabase,
+ std::string &ErrorMessage) {
+ llvm::OwningPtr<CompilationDatabase> Database(
+ JSONCompilationDatabase::loadFromBuffer(JSONDatabase, ErrorMessage));
+ if (!Database) {
+ ADD_FAILURE() << ErrorMessage;
+ return std::vector<std::string>();
+ }
+ return Database->getAllFiles();
+}
+
+TEST(JSONCompilationDatabase, GetAllFiles) {
+ std::string ErrorMessage;
+ EXPECT_EQ(std::vector<std::string>(),
+ getAllFiles("[]", ErrorMessage)) << ErrorMessage;
+
+ std::vector<std::string> expected_files;
+ expected_files.push_back("file1");
+ expected_files.push_back("file2");
+ EXPECT_EQ(expected_files, getAllFiles(
+ "[{\"directory\":\"dir\","
+ "\"command\":\"command\","
+ "\"file\":\"file1\"},"
+ " {\"directory\":\"dir\","
+ "\"command\":\"command\","
+ "\"file\":\"file2\"}]",
+ ErrorMessage)) << ErrorMessage;
+}
+
static CompileCommand findCompileArgsInJsonDatabase(StringRef FileName,
StringRef JSONDatabase,
std::string &ErrorMessage) {
@@ -255,6 +284,15 @@ TEST(FixedCompilationDatabase, ReturnsFixedCommandLine) {
EXPECT_EQ(ExpectedCommandLine, Result[0].CommandLine);
}
+TEST(FixedCompilationDatabase, GetAllFiles) {
+ std::vector<std::string> CommandLine;
+ CommandLine.push_back("one");
+ CommandLine.push_back("two");
+ FixedCompilationDatabase Database(".", CommandLine);
+
+ EXPECT_EQ(0ul, Database.getAllFiles().size());
+}
+
TEST(ParseFixedCompilationDatabase, ReturnsNullOnEmptyArgumentList) {
int Argc = 0;
llvm::OwningPtr<FixedCompilationDatabase> Database(
OpenPOWER on IntegriCloud