summaryrefslogtreecommitdiffstats
path: root/unittests/Tooling/CompilationDatabaseTest.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2012-08-15 20:02:54 +0000
committerdim <dim@FreeBSD.org>2012-08-15 20:02:54 +0000
commit554bcb69c2d785a011a30e7db87a36a87fe7db10 (patch)
tree9abb1a658a297776086f4e0dfa6ca533de02104e /unittests/Tooling/CompilationDatabaseTest.cpp
parentbb67ca86b31f67faee50bd10c3b036d65751745a (diff)
downloadFreeBSD-src-554bcb69c2d785a011a30e7db87a36a87fe7db10.zip
FreeBSD-src-554bcb69c2d785a011a30e7db87a36a87fe7db10.tar.gz
Vendor import of clang trunk r161861:
http://llvm.org/svn/llvm-project/cfe/trunk@161861
Diffstat (limited to 'unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r--unittests/Tooling/CompilationDatabaseTest.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/unittests/Tooling/CompilationDatabaseTest.cpp b/unittests/Tooling/CompilationDatabaseTest.cpp
index 68d2896..591d48d 100644
--- a/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -18,6 +18,55 @@
namespace clang {
namespace tooling {
+static void expectFailure(StringRef JSONDatabase, StringRef Explanation) {
+ std::string ErrorMessage;
+ EXPECT_EQ(NULL, JSONCompilationDatabase::loadFromBuffer(JSONDatabase,
+ ErrorMessage))
+ << "Expected an error because of: " << Explanation;
+}
+
+TEST(JSONCompilationDatabase, ErrsOnInvalidFormat) {
+ expectFailure("", "Empty database");
+ expectFailure("{", "Invalid JSON");
+ expectFailure("[[]]", "Array instead of object");
+ expectFailure("[{\"a\":[]}]", "Array instead of value");
+ expectFailure("[{\"a\":\"b\"}]", "Unknown key");
+ expectFailure("[{[]:\"\"}]", "Incorrectly typed entry");
+ expectFailure("[{}]", "Empty entry");
+ expectFailure("[{\"directory\":\"\",\"command\":\"\"}]", "Missing file");
+ expectFailure("[{\"directory\":\"\",\"file\":\"\"}]", "Missing command");
+ 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) {
@@ -235,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