diff options
author | Manuel Klimek <klimek@google.com> | 2012-05-15 11:46:07 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2012-05-15 11:46:07 +0000 |
commit | 1a8d6861278051b2109c98baf6a7478a6f3f98aa (patch) | |
tree | dd441f1a7cac38d8af0319d5434518af54c78985 /unittests/Tooling/CompilationDatabaseTest.cpp | |
parent | 91720917d4ea35af0f9f15eeebf0daf709c41e98 (diff) |
Fixes crasher bug in JSONCompilationDatabase for invalid input.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156814 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r-- | unittests/Tooling/CompilationDatabaseTest.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/unittests/Tooling/CompilationDatabaseTest.cpp b/unittests/Tooling/CompilationDatabaseTest.cpp index 68d2896f12..7753c15410 100644 --- a/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/unittests/Tooling/CompilationDatabaseTest.cpp @@ -18,6 +18,26 @@ 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 CompileCommand findCompileArgsInJsonDatabase(StringRef FileName, StringRef JSONDatabase, std::string &ErrorMessage) { |