mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
util: Properly handle -noincludeconf on command line
This bug was introduced in commit
fad0867d6a
.
Unit test
Co-Authored-By: Russell Yanofsky <russ@yanofsky.org>
This commit is contained in:
parent
a9435e3445
commit
fa910b4765
2 changed files with 26 additions and 4 deletions
|
@ -329,6 +329,25 @@ BOOST_FIXTURE_TEST_CASE(util_CheckValue, CheckValueTest)
|
||||||
CheckValue(M::ALLOW_ANY, "-value=abc", Expect{"abc"}.String("abc").Int(0).Bool(false).List({"abc"}));
|
CheckValue(M::ALLOW_ANY, "-value=abc", Expect{"abc"}.String("abc").Int(0).Bool(false).List({"abc"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct NoIncludeConfTest {
|
||||||
|
std::string Parse(const char* arg)
|
||||||
|
{
|
||||||
|
TestArgsManager test;
|
||||||
|
test.SetupArgs({{"-includeconf", ArgsManager::ALLOW_ANY}});
|
||||||
|
std::array argv{"ignored", arg};
|
||||||
|
std::string error;
|
||||||
|
(void)test.ParseParameters(argv.size(), argv.data(), error);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(util_NoIncludeConf, NoIncludeConfTest)
|
||||||
|
{
|
||||||
|
BOOST_CHECK_EQUAL(Parse("-noincludeconf"), "");
|
||||||
|
BOOST_CHECK_EQUAL(Parse("-includeconf"), "-includeconf cannot be used from commandline; -includeconf=\"\"");
|
||||||
|
BOOST_CHECK_EQUAL(Parse("-includeconf=file"), "-includeconf cannot be used from commandline; -includeconf=\"file\"");
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(util_ParseParameters)
|
BOOST_AUTO_TEST_CASE(util_ParseParameters)
|
||||||
{
|
{
|
||||||
TestArgsManager testArgs;
|
TestArgsManager testArgs;
|
||||||
|
|
|
@ -365,11 +365,14 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
|
||||||
m_settings.command_line_options[key].push_back(value);
|
m_settings.command_line_options[key].push_back(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we do not allow -includeconf from command line
|
// we do not allow -includeconf from command line, only -noincludeconf
|
||||||
if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
|
if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
|
||||||
const auto& include{*util::SettingsSpan(*includes).begin()}; // pick first value as example
|
const util::SettingsSpan values{*includes};
|
||||||
error = "-includeconf cannot be used from commandline; -includeconf=" + include.write();
|
// Range may be empty if -noincludeconf was passed
|
||||||
return false;
|
if (!values.empty()) {
|
||||||
|
error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write();
|
||||||
|
return false; // pick first value as example
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue