summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2012-04-18 07:41:50 +0000
committerManuel Klimek <klimek@google.com>2012-04-18 07:41:50 +0000
commit30318e6df9c8c24d080211dfb92ef8065fa7381c (patch)
tree928c1951e5c086cb47024a690c0fa85579ed2a59 /unittests
parent6403683411dac55afbe3435ceb19033e27cd9f96 (diff)
Adds a FixedCompilationDatabase to be able to specify tool parameters
at the command line. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154989 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Tooling/CompilationDatabaseTest.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/unittests/Tooling/CompilationDatabaseTest.cpp b/unittests/Tooling/CompilationDatabaseTest.cpp
index 9747de2554..68d2896f12 100644
--- a/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -219,5 +219,74 @@ TEST(unescapeJsonCommandLine, ParsesQuotedStringWithoutClosingQuote) {
EXPECT_EQ("", Empty[0]);
}
+TEST(FixedCompilationDatabase, ReturnsFixedCommandLine) {
+ std::vector<std::string> CommandLine;
+ CommandLine.push_back("one");
+ CommandLine.push_back("two");
+ FixedCompilationDatabase Database(".", CommandLine);
+ std::vector<CompileCommand> Result =
+ Database.getCompileCommands("source");
+ ASSERT_EQ(1ul, Result.size());
+ std::vector<std::string> ExpectedCommandLine(1, "clang-tool");
+ ExpectedCommandLine.insert(ExpectedCommandLine.end(),
+ CommandLine.begin(), CommandLine.end());
+ ExpectedCommandLine.push_back("source");
+ EXPECT_EQ(".", Result[0].Directory);
+ EXPECT_EQ(ExpectedCommandLine, Result[0].CommandLine);
+}
+
+TEST(ParseFixedCompilationDatabase, ReturnsNullOnEmptyArgumentList) {
+ int Argc = 0;
+ llvm::OwningPtr<FixedCompilationDatabase> Database(
+ FixedCompilationDatabase::loadFromCommandLine(Argc, NULL));
+ EXPECT_FALSE(Database);
+ EXPECT_EQ(0, Argc);
+}
+
+TEST(ParseFixedCompilationDatabase, ReturnsNullWithoutDoubleDash) {
+ int Argc = 2;
+ const char *Argv[] = { "1", "2" };
+ llvm::OwningPtr<FixedCompilationDatabase> Database(
+ FixedCompilationDatabase::loadFromCommandLine(Argc, Argv));
+ EXPECT_FALSE(Database);
+ EXPECT_EQ(2, Argc);
+}
+
+TEST(ParseFixedCompilationDatabase, ReturnsArgumentsAfterDoubleDash) {
+ int Argc = 5;
+ const char *Argv[] = { "1", "2", "--\0no-constant-folding", "3", "4" };
+ llvm::OwningPtr<FixedCompilationDatabase> Database(
+ FixedCompilationDatabase::loadFromCommandLine(Argc, Argv));
+ ASSERT_TRUE(Database);
+ std::vector<CompileCommand> Result =
+ Database->getCompileCommands("source");
+ ASSERT_EQ(1ul, Result.size());
+ ASSERT_EQ(".", Result[0].Directory);
+ std::vector<std::string> CommandLine;
+ CommandLine.push_back("clang-tool");
+ CommandLine.push_back("3");
+ CommandLine.push_back("4");
+ CommandLine.push_back("source");
+ ASSERT_EQ(CommandLine, Result[0].CommandLine);
+ EXPECT_EQ(2, Argc);
+}
+
+TEST(ParseFixedCompilationDatabase, ReturnsEmptyCommandLine) {
+ int Argc = 3;
+ const char *Argv[] = { "1", "2", "--\0no-constant-folding" };
+ llvm::OwningPtr<FixedCompilationDatabase> Database(
+ FixedCompilationDatabase::loadFromCommandLine(Argc, Argv));
+ ASSERT_TRUE(Database);
+ std::vector<CompileCommand> Result =
+ Database->getCompileCommands("source");
+ ASSERT_EQ(1ul, Result.size());
+ ASSERT_EQ(".", Result[0].Directory);
+ std::vector<std::string> CommandLine;
+ CommandLine.push_back("clang-tool");
+ CommandLine.push_back("source");
+ ASSERT_EQ(CommandLine, Result[0].CommandLine);
+ EXPECT_EQ(2, Argc);
+}
+
} // end namespace tooling
} // end namespace clang