Skip to content

Commit da81624

Browse files
MarcoFalkefanquake
authored andcommitted
util: Properly handle -noincludeconf on command line
This bug was introduced in commit fad0867. Unit test Co-Authored-By: Russell Yanofsky <[email protected]> Github-Pull: #22137 Rebased-From: fa910b4
1 parent 513613d commit da81624

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/test/util_tests.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,25 @@ BOOST_FIXTURE_TEST_CASE(util_CheckValue, CheckValueTest)
318318
CheckValue(M::ALLOW_ANY, "-value=abc", Expect{"abc"}.String("abc").Int(0).Bool(false).List({"abc"}));
319319
}
320320

321+
struct NoIncludeConfTest {
322+
std::string Parse(const char* arg)
323+
{
324+
TestArgsManager test;
325+
test.SetupArgs({{"-includeconf", ArgsManager::ALLOW_ANY}});
326+
std::array<const char*, 2> argv{"ignored", arg};
327+
std::string error;
328+
(void)test.ParseParameters(argv.size(), argv.data(), error);
329+
return error;
330+
}
331+
};
332+
333+
BOOST_FIXTURE_TEST_CASE(util_NoIncludeConf, NoIncludeConfTest)
334+
{
335+
BOOST_CHECK_EQUAL(Parse("-noincludeconf"), "");
336+
BOOST_CHECK_EQUAL(Parse("-includeconf"), "-includeconf cannot be used from commandline; -includeconf=\"\"");
337+
BOOST_CHECK_EQUAL(Parse("-includeconf=file"), "-includeconf cannot be used from commandline; -includeconf=\"file\"");
338+
}
339+
321340
BOOST_AUTO_TEST_CASE(util_ParseParameters)
322341
{
323342
TestArgsManager testArgs;

src/util/system.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,14 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
336336
m_settings.command_line_options[key].push_back(value);
337337
}
338338

339-
// we do not allow -includeconf from command line
339+
// we do not allow -includeconf from command line, only -noincludeconf
340340
if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
341-
const auto& include{*util::SettingsSpan(*includes).begin()}; // pick first value as example
342-
error = "-includeconf cannot be used from commandline; -includeconf=" + include.write();
343-
return false;
341+
const util::SettingsSpan values{*includes};
342+
// Range may be empty if -noincludeconf was passed
343+
if (!values.empty()) {
344+
error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write();
345+
return false; // pick first value as example
346+
}
344347
}
345348
return true;
346349
}

0 commit comments

Comments
 (0)