|
11 | 11 | #include "llvm/Support/Debug.h"
|
12 | 12 | #include "gtest/gtest.h"
|
13 | 13 |
|
| 14 | +#include "TestUtils.h" |
| 15 | + |
14 | 16 | #define DEBUG_TYPE "driver-test"
|
15 | 17 |
|
16 | 18 | TEST(DriverTests, Basic) {
|
@@ -129,3 +131,44 @@ TEST(DriverTests, DriverParsesDiagnosticsOptions) {
|
129 | 131 | clang_disposeDiagnosticSet(Diags);
|
130 | 132 | clang_Driver_ExternalActionList_dispose(EAL);
|
131 | 133 | }
|
| 134 | + |
| 135 | +class LibclangDriverResponseFileTest : public LibclangParseTest {}; |
| 136 | + |
| 137 | +TEST_F(LibclangDriverResponseFileTest, DriverResponseFile) { |
| 138 | + // Enable -Weverything (a flag not set by default) via a response file. |
| 139 | + std::string ResponseFilename = "AdditionalOptions.resp"; |
| 140 | + WriteFile(ResponseFilename, "-Weverything\n"); |
| 141 | + |
| 142 | + llvm::SmallString<256> ResponseArg("@"); |
| 143 | + ResponseArg.append(ResponseFilename); |
| 144 | + |
| 145 | + const char *ArgV[] = {"clang", |
| 146 | + ResponseArg.c_str(), |
| 147 | + "-c", |
| 148 | + "t.cpp", |
| 149 | + "-o", |
| 150 | + "t.o"}; |
| 151 | + |
| 152 | + CXDiagnosticSet Diags; |
| 153 | + CXExternalActionList *EAL = clang_Driver_getExternalActionsForCommand_v0( |
| 154 | + std::extent_v<decltype(ArgV)>, ArgV, nullptr, "/", &Diags); |
| 155 | + |
| 156 | + ASSERT_NE(EAL, nullptr); |
| 157 | + ASSERT_EQ(EAL->Count, 1); |
| 158 | + ASSERT_EQ(nullptr, Diags); |
| 159 | + |
| 160 | + auto *CompileAction = EAL->Actions[0]; |
| 161 | + ASSERT_GE(CompileAction->ArgC, 2); |
| 162 | + EXPECT_STREQ(CompileAction->ArgV[0], "clang"); |
| 163 | + EXPECT_STREQ(CompileAction->ArgV[1], "-cc1"); |
| 164 | + |
| 165 | + const char **WFlag = std::find(CompileAction->ArgV, |
| 166 | + CompileAction->ArgV + CompileAction->ArgC, |
| 167 | + llvm::StringRef("-Weverything")); |
| 168 | + |
| 169 | + ASSERT_NE(WFlag, CompileAction->ArgV + CompileAction->ArgC); |
| 170 | + EXPECT_STREQ(*WFlag, "-Weverything"); |
| 171 | + |
| 172 | + clang_disposeDiagnosticSet(Diags); |
| 173 | + clang_Driver_ExternalActionList_dispose(EAL); |
| 174 | +} |
0 commit comments