aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/CompilationDatabaseTest.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2024-01-19 14:02:04 +0100
committerGitHub <noreply@github.com>2024-01-19 14:02:04 +0100
commit1ab418beb3cc9c31ebb2d5779069426d761ceb8f (patch)
treec1ab3ce7eb67b72b701927c3a0ede08ea4d81ce2 /clang/unittests/Tooling/CompilationDatabaseTest.cpp
parent689da340edaa9f61dfae90e94ac69bfe189ee78f (diff)
downloadllvm-1ab418beb3cc9c31ebb2d5779069426d761ceb8f.zip
llvm-1ab418beb3cc9c31ebb2d5779069426d761ceb8f.tar.gz
llvm-1ab418beb3cc9c31ebb2d5779069426d761ceb8f.tar.bz2
[Tooling] Fix FixedCompilationDatabase with header compile flags (#73913)
Summary: The logic to strip positional args feels very fragile, but it's terribly useful when you want to use a tool on a file and have the exact argv. Today doesn't work with header-parsing actions because these are "precompile" rather than "compile", from tooling's perspective it's all the same. Reviewers: kadircet Subscribers:
Diffstat (limited to 'clang/unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r--clang/unittests/Tooling/CompilationDatabaseTest.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 5173d47..45062cf 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -647,12 +647,30 @@ TEST(ParseFixedCompilationDatabase, HandlesPositionalArgs) {
FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMsg);
ASSERT_TRUE((bool)Database);
ASSERT_TRUE(ErrorMsg.empty());
+ std::vector<CompileCommand> Result = Database->getCompileCommands("source");
+ ASSERT_EQ(1ul, Result.size());
+ ASSERT_EQ(".", Result[0].Directory);
+ ASSERT_THAT(Result[0].CommandLine,
+ ElementsAre(EndsWith("clang-tool"), "-c", "-DDEF3", "source"));
+ EXPECT_EQ(2, Argc);
+}
+
+TEST(ParseFixedCompilationDatabase, HandlesPositionalArgsHeader) {
+ const char *Argv[] = {"1", "2", "--", "-xc++-header",
+ "-c", "somefile.h", "-DDEF3"};
+ int Argc = std::size(Argv);
+ std::string ErrorMsg;
+ std::unique_ptr<FixedCompilationDatabase> Database =
+ FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMsg);
+ ASSERT_TRUE((bool)Database);
+ ASSERT_TRUE(ErrorMsg.empty());
std::vector<CompileCommand> Result =
Database->getCompileCommands("source");
ASSERT_EQ(1ul, Result.size());
ASSERT_EQ(".", Result[0].Directory);
ASSERT_THAT(Result[0].CommandLine,
- ElementsAre(EndsWith("clang-tool"), "-c", "-DDEF3", "source"));
+ ElementsAre(EndsWith("clang-tool"), "-xc++-header", "-c",
+ "-DDEF3", "source"));
EXPECT_EQ(2, Argc);
}