Skip to content

Commit eb386f6

Browse files
committed
test: the response file's quoting, the part of it a host cannot demonstrate
1 parent d2ba022 commit eb386f6

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎tests/unit/test_sources.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import std;
88
import mcpp.manifest;
99
import mcpp.config;
10+
import mcpp.build.build_program;
1011
import mcpp.libs.toml;
1112
import mcpp.build.directives;
1213
import mcpp.toolchain.dialect;
@@ -232,6 +233,29 @@ TEST(Sources, OverrideVersionIsCheckedAgainstRequirements) {
232233
EXPECT_EQ(reqs[0], ">=3.31 by mcpp:plugins");
233234
}
234235

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+
235259
// ── [xlings.overrides] in config.toml ───────────────────────────────────────
236260

237261
TEST(Sources, ConfigOverridesParseWithTheManifestsTwoShapes) {

0 commit comments

Comments
 (0)