diff options
author | Edwin Vane <revane@gmail.com> | 2013-11-17 16:08:04 +0000 |
---|---|---|
committer | Edwin Vane <revane@gmail.com> | 2013-11-17 16:08:04 +0000 |
commit | eb56f4fe2f5a997d0f93786e7a3dba6671036ad8 (patch) | |
tree | a939580a75b7b0d9875cae9bf50282ba72f22e34 /clang/unittests/Tooling/CompilationDatabaseTest.cpp | |
parent | ce0697f4759ce369bd28d31a6ed5813d776663de (diff) | |
download | llvm-eb56f4fe2f5a997d0f93786e7a3dba6671036ad8.zip llvm-eb56f4fe2f5a997d0f93786e7a3dba6671036ad8.tar.gz llvm-eb56f4fe2f5a997d0f93786e7a3dba6671036ad8.tar.bz2 |
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
Diffstat (limited to 'clang/unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/CompilationDatabaseTest.cpp | 44 |
1 files changed, 41 insertions, 3 deletions
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<FixedCompilationDatabase> Database( FixedCompilationDatabase::loadFromCommandLine(Argc, Argv)); ASSERT_TRUE(Database.isValid()); @@ -460,8 +462,8 @@ TEST(ParseFixedCompilationDatabase, ReturnsArgumentsAfterDoubleDash) { 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("-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<FixedCompilationDatabase> Database( + FixedCompilationDatabase::loadFromCommandLine(Argc, Argv)); + ASSERT_TRUE(Database.isValid()); + std::vector<CompileCommand> Result = + Database->getCompileCommands("source"); + ASSERT_EQ(1ul, Result.size()); + ASSERT_EQ(".", Result[0].Directory); + std::vector<std::string> 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<FixedCompilationDatabase> Database( + FixedCompilationDatabase::loadFromCommandLine(Argc, Argv)); + ASSERT_TRUE(Database.isValid()); + std::vector<CompileCommand> Result = + Database->getCompileCommands("source"); + ASSERT_EQ(1ul, Result.size()); + ASSERT_EQ(".", Result[0].Directory); + std::vector<std::string> 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 |