Skip to content

Commit 0896d0a

Browse files
MarcoFalkeryanofsky
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]>
1 parent 5f18d33 commit 0896d0a

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
@@ -324,11 +324,14 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
324324
m_settings.command_line_options[key].push_back(value);
325325
}
326326

327-
// we do not allow -includeconf from command line
327+
// we do not allow -includeconf from command line, only -noincludeconf
328328
if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
329-
const auto& include{*util::SettingsSpan(*includes).begin()}; // pick first value as example
330-
error = "-includeconf cannot be used from commandline; -includeconf=" + include.write();
331-
return false;
329+
const util::SettingsSpan values{*includes};
330+
// Range may be empty if -noincludeconf was passed
331+
if (!values.empty()) {
332+
error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write();
333+
return false; // pick first value as example
334+
}
332335
}
333336
return true;
334337
}

0 commit comments

Comments
 (0)