From 952eddef9aff85b1e92626e89baaf7a360e2ac85 Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 22 Dec 2013 00:07:40 +0000 Subject: Vendor import of clang release_34 branch r197841 (effectively, 3.4 RC3): https://llvm.org/svn/llvm-project/cfe/branches/release_34@197841 --- unittests/Tooling/CompilationDatabaseTest.cpp | 50 +++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'unittests/Tooling/CompilationDatabaseTest.cpp') 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 Database( FixedCompilationDatabase::loadFromCommandLine(Argc, Argv)); - ASSERT_TRUE(Database); + ASSERT_TRUE(Database.isValid()); std::vector Result = Database->getCompileCommands("source"); ASSERT_EQ(1ul, Result.size()); 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); @@ -472,7 +474,7 @@ TEST(ParseFixedCompilationDatabase, ReturnsEmptyCommandLine) { const char *Argv[] = { "1", "2", "--\0no-constant-folding" }; OwningPtr Database( FixedCompilationDatabase::loadFromCommandLine(Argc, Argv)); - ASSERT_TRUE(Database); + ASSERT_TRUE(Database.isValid()); std::vector 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 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