|
7 | 7 | import std; |
8 | 8 | import mcpp.manifest; |
9 | 9 | import mcpp.config; |
| 10 | +import mcpp.build.build_program; |
10 | 11 | import mcpp.libs.toml; |
11 | 12 | import mcpp.build.directives; |
12 | 13 | import mcpp.toolchain.dialect; |
@@ -232,6 +233,29 @@ TEST(Sources, OverrideVersionIsCheckedAgainstRequirements) { |
232 | 233 | EXPECT_EQ(reqs[0], ">=3.31 by mcpp:plugins"); |
233 | 234 | } |
234 | 235 |
|
| 236 | +// ── The response file a long compile command goes through ─────────────────── |
| 237 | + |
| 238 | +TEST(Sources, ResponseFileWritesOneArgumentPerLineAndQuotesWhatNeedsIt) { |
| 239 | + const std::vector<std::string> args{ |
| 240 | + "-std=c++23", |
| 241 | + "-fmodule-file=mcpp=/home/u/p/mcpp.pcm", |
| 242 | + "/Tp C:/Program Files/x/build.mcpp", |
| 243 | + R"(-DNAME="v")", |
| 244 | + "C:\\with space\\dir\\", |
| 245 | + }; |
| 246 | + const auto body = mcpp::build::response_file_body(args); |
| 247 | + EXPECT_EQ(std::ranges::count(body, '\n'), 5); |
| 248 | + EXPECT_NE(body.find("-std=c++23\n"), std::string::npos) << body; |
| 249 | + // Quoted only where it has to be. |
| 250 | + EXPECT_NE(body.find("-fmodule-file=mcpp=/home/u/p/mcpp.pcm\n"), std::string::npos) << body; |
| 251 | + EXPECT_NE(body.find("\"/Tp C:/Program Files/x/build.mcpp\"\n"), std::string::npos) << body; |
| 252 | + // A quote inside the argument survives as one. |
| 253 | + EXPECT_NE(body.find("\"-DNAME=\\\"v\\\"\"\n"), std::string::npos) << body; |
| 254 | + // The run of backslashes that ends the argument is doubled, so it does not |
| 255 | + // escape the closing quote. |
| 256 | + EXPECT_NE(body.find("\"C:\\with space\\dir\\\\\"\n"), std::string::npos) << body; |
| 257 | +} |
| 258 | + |
235 | 259 | // ── [xlings.overrides] in config.toml ─────────────────────────────────────── |
236 | 260 |
|
237 | 261 | TEST(Sources, ConfigOverridesParseWithTheManifestsTwoShapes) { |
|
0 commit comments