diff options
author | dim <dim@FreeBSD.org> | 2013-12-22 00:07:40 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2013-12-22 00:07:40 +0000 |
commit | 952eddef9aff85b1e92626e89baaf7a360e2ac85 (patch) | |
tree | df8df0b0067b381eab470a3b8f28d14a552a6340 /unittests/Tooling/CompilationDatabaseTest.cpp | |
parent | ea266cad53e3d49771fa38103913d3ec7a166694 (diff) | |
download | FreeBSD-src-952eddef9aff85b1e92626e89baaf7a360e2ac85.zip FreeBSD-src-952eddef9aff85b1e92626e89baaf7a360e2ac85.tar.gz |
Vendor import of clang release_34 branch r197841 (effectively, 3.4 RC3):
https://llvm.org/svn/llvm-project/cfe/branches/release_34@197841
Diffstat (limited to 'unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r-- | unittests/Tooling/CompilationDatabaseTest.cpp | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/unittests/Tooling/CompilationDatabaseTest.cpp b/unittests/Tooling/CompilationDatabaseTest.cpp index c453b05..c575dff 100644 --- a/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/unittests/Tooling/CompilationDatabaseTest.cpp @@ -14,7 +14,7 @@ #include "clang/Tooling/FileMatchTrie.h" #include "clang/Tooling/JSONCompilationDatabase.h" #include "clang/Tooling/Tooling.h" -#include "llvm/Support/PathV2.h" +#include "llvm/Support/Path.h" #include "gtest/gtest.h" namespace clang { @@ -450,18 +450,20 @@ 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); + 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> 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); @@ -472,7 +474,7 @@ TEST(ParseFixedCompilationDatabase, ReturnsEmptyCommandLine) { const char *Argv[] = { "1", "2", "--\0no-constant-folding" }; OwningPtr<FixedCompilationDatabase> Database( FixedCompilationDatabase::loadFromCommandLine(Argc, Argv)); - ASSERT_TRUE(Database); + ASSERT_TRUE(Database.isValid()); std::vector<CompileCommand> Result = Database->getCompileCommands("source"); ASSERT_EQ(1ul, Result.size()); @@ -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 |