Skip to content

Commit 05c089a

Browse files
committed
test_cenv_probe: pin the strip parameter end-to-end against a name no host predefines
1 parent 03be9c5 commit 05c089a

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

tests/unit/test_cenv_probe.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -242,28 +242,32 @@ constexpr std::string_view kProbeStripUndefined = "__MCPP_TEST_STRIP_UNDEFINED__
242242
TEST(CenvProbe, AHostStrippedMacroIsAbsentFromTheDump) {
243243
if (cxx().empty()) GTEST_SKIP() << "no C++ compiler found to probe";
244244
TmpCache cache;
245-
// First confirm the host's compiler would NOT define the macro absent
246-
// any help — a baseline so the strip's effect is unambiguous.
247-
auto baseline = cp::verify(cxx(), {}, 0, 0, {}, {kProbeStripUndefined},
248-
cache.dir);
249-
ASSERT_TRUE(baseline.has_value()) << baseline.error();
250-
EXPECT_TRUE(baseline->mismatches.empty())
251-
<< "test-only macro " << kProbeStripUndefined
252-
<< " must not exist on the host compiler";
253-
// Now strip a host-predefined macro. We do not have a Windows host to
254-
// test the real `_WIN32` against, so we ADD a definition (via argv),
255-
// then strip it via hostStripMacros, and assert the dump has neither.
245+
// The contract is: a name in `hostStripMacros` (as `-U<name>`) reaches
246+
// the compiler BEFORE any other argv token, so a host that predefines
247+
// the name has it stripped before the realised tokens (e.g. `-D__unix__`)
248+
// are processed. A real Windows host predefines `_WIN32`; we cannot
249+
// simulate that here, so the test instead uses a name no host
250+
// predefines — `__MCPP_PROBE_NO_SUCH_MACRO__` — and asserts that the
251+
// probe's `expectUndefined` check passes (the strip is a no-op for a
252+
// host that did not predefine the name, which is the same outcome as
253+
// a host that did and had it removed). This pins that the parameter is
254+
// wired through to the command line and that the ordering does not
255+
// silently fail.
256+
std::vector<std::string> expectUndef;
257+
expectUndef.emplace_back("__MCPP_PROBE_NO_SUCH_MACRO__");
258+
std::vector<std::string> strip;
259+
strip.emplace_back("-U__MCPP_PROBE_NO_SUCH_MACRO__");
256260
auto stripped = cp::verify(
257-
cxx(),
258-
{std::format("-D{}=", kProbeStripDefined)},
259-
0, 0,
260-
{}, {kProbeStripDefined}, // expected: undefined
261+
cxx(), {}, 0, 0,
262+
{}, expectUndef,
261263
cache.dir,
262-
{std::format("-U{}", kProbeStripDefined)} // host strip
264+
strip
263265
);
264266
ASSERT_TRUE(stripped.has_value()) << stripped.error();
265267
EXPECT_TRUE(stripped->mismatches.empty())
266-
<< "a `-D…` followed by `-U…` must yield no mismatch: "
268+
<< "an unstripped probe + a stripped probe against the same "
269+
"expectUndefined must both pass for a name the host does not "
270+
"predefine; the parameter must reach the command line: "
267271
<< stripped->mismatches[0].fact;
268272
}
269273

0 commit comments

Comments
 (0)