From eb56f4fe2f5a997d0f93786e7a3dba6671036ad8 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Sun, 17 Nov 2013 16:08:04 +0000 Subject: Relax some preconditions for using FixedCompilationDatabase. FixedCompilationDatabase (FCD) requires that the arguments it consumes after '--' must not include positional parameters or the argv[0] of the tool. This patch relaxes those restrictions. llvm-svn: 194968 --- .../unittests/Tooling/CompilationDatabaseTest.cpp | 44 ++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'clang/unittests/Tooling/CompilationDatabaseTest.cpp') diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp index 6e18cd3..c575dff 100644 --- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp @@ -450,7 +450,9 @@ TEST(ParseFixedCompilationDatabase, ReturnsNullWithoutDoubleDash) { TEST(ParseFixedCompilationDatabase, ReturnsArgumentsAfterDoubleDash) { int Argc = 5; - const char *Argv[] = { "1", "2", "--\0no-constant-folding", "3", "4" }; + const char *Argv[] = { + "1", "2", "--\0no-constant-folding", "-DDEF3", "-DDEF4" + }; OwningPtr Database( FixedCompilationDatabase::loadFromCommandLine(Argc, Argv)); ASSERT_TRUE(Database.isValid()); @@ -460,8 +462,8 @@ TEST(ParseFixedCompilationDatabase, ReturnsArgumentsAfterDoubleDash) { ASSERT_EQ(".", Result[0].Directory); std::vector CommandLine; CommandLine.push_back("clang-tool"); - CommandLine.push_back("3"); - CommandLine.push_back("4"); + CommandLine.push_back("-DDEF3"); + CommandLine.push_back("-DDEF4"); CommandLine.push_back("source"); ASSERT_EQ(CommandLine, Result[0].CommandLine); EXPECT_EQ(2, Argc); @@ -484,5 +486,41 @@ TEST(ParseFixedCompilationDatabase, ReturnsEmptyCommandLine) { EXPECT_EQ(2, Argc); } +TEST(ParseFixedCompilationDatabase, HandlesPositionalArgs) { + const char *Argv[] = {"1", "2", "--", "-c", "somefile.cpp", "-DDEF3"}; + int Argc = sizeof(Argv) / sizeof(char*); + OwningPtr Database( + FixedCompilationDatabase::loadFromCommandLine(Argc, Argv)); + ASSERT_TRUE(Database.isValid()); + std::vector Result = + Database->getCompileCommands("source"); + ASSERT_EQ(1ul, Result.size()); + ASSERT_EQ(".", Result[0].Directory); + std::vector Expected; + Expected.push_back("clang-tool"); + Expected.push_back("-c"); + Expected.push_back("-DDEF3"); + Expected.push_back("source"); + ASSERT_EQ(Expected, Result[0].CommandLine); + EXPECT_EQ(2, Argc); +} + +TEST(ParseFixedCompilationDatabase, HandlesArgv0) { + const char *Argv[] = {"1", "2", "--", "mytool", "somefile.cpp"}; + int Argc = sizeof(Argv) / sizeof(char*); + OwningPtr Database( + FixedCompilationDatabase::loadFromCommandLine(Argc, Argv)); + ASSERT_TRUE(Database.isValid()); + std::vector Result = + Database->getCompileCommands("source"); + ASSERT_EQ(1ul, Result.size()); + ASSERT_EQ(".", Result[0].Directory); + std::vector Expected; + Expected.push_back("clang-tool"); + Expected.push_back("source"); + ASSERT_EQ(Expected, Result[0].CommandLine); + EXPECT_EQ(2, Argc); +} + } // end namespace tooling } // end namespace clang -- cgit v1.1