tests: Check return value of ParseParameters(...)
This commit is contained in:
parent
7c5bc2a523
commit
145fe95ec7
2 changed files with 23 additions and 23 deletions
|
@ -28,7 +28,7 @@ static void ResetArgs(const std::string& strArg)
|
|||
vecChar.push_back(s.c_str());
|
||||
|
||||
std::string error;
|
||||
gArgs.ParseParameters(vecChar.size(), vecChar.data(), error);
|
||||
BOOST_CHECK(gArgs.ParseParameters(vecChar.size(), vecChar.data(), error));
|
||||
}
|
||||
|
||||
static void SetupArgs(const std::vector<std::string>& args)
|
||||
|
|
|
@ -210,13 +210,13 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters)
|
|||
|
||||
std::string error;
|
||||
testArgs.SetupArgs(4, avail_args);
|
||||
testArgs.ParseParameters(0, (char**)argv_test, error);
|
||||
BOOST_CHECK(testArgs.ParseParameters(0, (char**)argv_test, error));
|
||||
BOOST_CHECK(testArgs.GetOverrideArgs().empty() && testArgs.GetConfigArgs().empty());
|
||||
|
||||
testArgs.ParseParameters(1, (char**)argv_test, error);
|
||||
BOOST_CHECK(testArgs.ParseParameters(1, (char**)argv_test, error));
|
||||
BOOST_CHECK(testArgs.GetOverrideArgs().empty() && testArgs.GetConfigArgs().empty());
|
||||
|
||||
testArgs.ParseParameters(7, (char**)argv_test, error);
|
||||
BOOST_CHECK(testArgs.ParseParameters(7, (char**)argv_test, error));
|
||||
// expectation: -ignored is ignored (program name argument),
|
||||
// -a, -b and -ccc end up in map, -d ignored because it is after
|
||||
// a non-option argument (non-GNU option parsing)
|
||||
|
@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(util_GetBoolArg)
|
|||
"ignored", "-a", "-nob", "-c=0", "-d=1", "-e=false", "-f=true"};
|
||||
std::string error;
|
||||
testArgs.SetupArgs(6, avail_args);
|
||||
testArgs.ParseParameters(7, (char**)argv_test, error);
|
||||
BOOST_CHECK(testArgs.ParseParameters(7, (char**)argv_test, error));
|
||||
|
||||
// Each letter should be set.
|
||||
for (const char opt : "abcdef")
|
||||
|
@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(util_GetBoolArgEdgeCases)
|
|||
const char *argv_test[] = {"ignored", "-nofoo", "-foo", "-nobar=0"};
|
||||
testArgs.SetupArgs(2, avail_args);
|
||||
std::string error;
|
||||
testArgs.ParseParameters(4, (char**)argv_test, error);
|
||||
BOOST_CHECK(testArgs.ParseParameters(4, (char**)argv_test, error));
|
||||
|
||||
// This was passed twice, second one overrides the negative setting.
|
||||
BOOST_CHECK(!testArgs.IsArgNegated("-foo"));
|
||||
|
@ -290,7 +290,7 @@ BOOST_AUTO_TEST_CASE(util_GetBoolArgEdgeCases)
|
|||
|
||||
// Config test
|
||||
const char *conf_test = "nofoo=1\nfoo=1\nnobar=0\n";
|
||||
testArgs.ParseParameters(1, (char**)argv_test, error);
|
||||
BOOST_CHECK(testArgs.ParseParameters(1, (char**)argv_test, error));
|
||||
testArgs.ReadConfigString(conf_test);
|
||||
|
||||
// This was passed twice, second one overrides the negative setting,
|
||||
|
@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE(util_GetBoolArgEdgeCases)
|
|||
// Combined test
|
||||
const char *combo_test_args[] = {"ignored", "-nofoo", "-bar"};
|
||||
const char *combo_test_conf = "foo=1\nnobar=1\n";
|
||||
testArgs.ParseParameters(3, (char**)combo_test_args, error);
|
||||
BOOST_CHECK(testArgs.ParseParameters(3, (char**)combo_test_args, error));
|
||||
testArgs.ReadConfigString(combo_test_conf);
|
||||
|
||||
// Command line overrides, but doesn't erase old setting
|
||||
|
@ -557,38 +557,38 @@ BOOST_AUTO_TEST_CASE(util_GetChainName)
|
|||
const char* testnetconf = "testnet=1\nregtest=0\n[test]\nregtest=1";
|
||||
std::string error;
|
||||
|
||||
test_args.ParseParameters(0, (char**)argv_testnet, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(0, (char**)argv_testnet, error));
|
||||
BOOST_CHECK_EQUAL(test_args.GetChainName(), "main");
|
||||
|
||||
test_args.ParseParameters(2, (char**)argv_testnet, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_testnet, error));
|
||||
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
|
||||
|
||||
test_args.ParseParameters(2, (char**)argv_regtest, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_regtest, error));
|
||||
BOOST_CHECK_EQUAL(test_args.GetChainName(), "regtest");
|
||||
|
||||
test_args.ParseParameters(3, (char**)argv_test_no_reg, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_test_no_reg, error));
|
||||
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
|
||||
|
||||
test_args.ParseParameters(3, (char**)argv_both, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_both, error));
|
||||
BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error);
|
||||
|
||||
test_args.ParseParameters(0, (char**)argv_testnet, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(0, (char**)argv_testnet, error));
|
||||
test_args.ReadConfigString(testnetconf);
|
||||
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
|
||||
|
||||
test_args.ParseParameters(2, (char**)argv_testnet, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_testnet, error));
|
||||
test_args.ReadConfigString(testnetconf);
|
||||
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
|
||||
|
||||
test_args.ParseParameters(2, (char**)argv_regtest, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_regtest, error));
|
||||
test_args.ReadConfigString(testnetconf);
|
||||
BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error);
|
||||
|
||||
test_args.ParseParameters(3, (char**)argv_test_no_reg, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_test_no_reg, error));
|
||||
test_args.ReadConfigString(testnetconf);
|
||||
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
|
||||
|
||||
test_args.ParseParameters(3, (char**)argv_both, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_both, error));
|
||||
test_args.ReadConfigString(testnetconf);
|
||||
BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error);
|
||||
|
||||
|
@ -596,23 +596,23 @@ BOOST_AUTO_TEST_CASE(util_GetChainName)
|
|||
// [test] regtest=1 potentially relevant) doesn't break things
|
||||
test_args.SelectConfigNetwork("test");
|
||||
|
||||
test_args.ParseParameters(0, (char**)argv_testnet, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(0, (char**)argv_testnet, error));
|
||||
test_args.ReadConfigString(testnetconf);
|
||||
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
|
||||
|
||||
test_args.ParseParameters(2, (char**)argv_testnet, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_testnet, error));
|
||||
test_args.ReadConfigString(testnetconf);
|
||||
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
|
||||
|
||||
test_args.ParseParameters(2, (char**)argv_regtest, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_regtest, error));
|
||||
test_args.ReadConfigString(testnetconf);
|
||||
BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error);
|
||||
|
||||
test_args.ParseParameters(2, (char**)argv_test_no_reg, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_test_no_reg, error));
|
||||
test_args.ReadConfigString(testnetconf);
|
||||
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
|
||||
|
||||
test_args.ParseParameters(3, (char**)argv_both, error);
|
||||
BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_both, error));
|
||||
test_args.ReadConfigString(testnetconf);
|
||||
BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue