mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-17 05:30:43 +02:00
Add util_ArgParsing test
ArgsManager test coverage for parsing of integer and boolean values is currently very poor and doesn't give us a way of knowing whether changes to ArgsManager may unintentionally break backwards compatibility, so this adds a new test to catch regressions.
This commit is contained in:
parent
e204dc11b5
commit
286f197704
@ -231,6 +231,60 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters)
|
|||||||
BOOST_CHECK(testArgs.GetArgs("-ccc").size() == 2);
|
BOOST_CHECK(testArgs.GetArgs("-ccc").size() == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void TestParse(const std::string& str, bool expected_bool, int64_t expected_int)
|
||||||
|
{
|
||||||
|
TestArgsManager test;
|
||||||
|
test.SetupArgs({{"-value", ArgsManager::ALLOW_ANY}});
|
||||||
|
std::string arg = "-value=" + str;
|
||||||
|
const char* argv[] = {"ignored", arg.c_str()};
|
||||||
|
std::string error;
|
||||||
|
BOOST_CHECK(test.ParseParameters(2, (char**)argv, error));
|
||||||
|
BOOST_CHECK_EQUAL(test.GetBoolArg("-value", false), expected_bool);
|
||||||
|
BOOST_CHECK_EQUAL(test.GetBoolArg("-value", true), expected_bool);
|
||||||
|
BOOST_CHECK_EQUAL(test.GetArg("-value", 99998), expected_int);
|
||||||
|
BOOST_CHECK_EQUAL(test.GetArg("-value", 99999), expected_int);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test bool and int parsing.
|
||||||
|
BOOST_AUTO_TEST_CASE(util_ArgParsing)
|
||||||
|
{
|
||||||
|
// Some of these cases could be ambiguous or surprising to users, and might
|
||||||
|
// be worth triggering errors or warnings in the future. But for now basic
|
||||||
|
// test coverage is useful to avoid breaking backwards compatibility
|
||||||
|
// unintentionally.
|
||||||
|
TestParse("", true, 0);
|
||||||
|
TestParse(" ", false, 0);
|
||||||
|
TestParse("0", false, 0);
|
||||||
|
TestParse("0 ", false, 0);
|
||||||
|
TestParse(" 0", false, 0);
|
||||||
|
TestParse("+0", false, 0);
|
||||||
|
TestParse("-0", false, 0);
|
||||||
|
TestParse("5", true, 5);
|
||||||
|
TestParse("5 ", true, 5);
|
||||||
|
TestParse(" 5", true, 5);
|
||||||
|
TestParse("+5", true, 5);
|
||||||
|
TestParse("-5", true, -5);
|
||||||
|
TestParse("0 5", false, 0);
|
||||||
|
TestParse("5 0", true, 5);
|
||||||
|
TestParse("050", true, 50);
|
||||||
|
TestParse("0.", false, 0);
|
||||||
|
TestParse("5.", true, 5);
|
||||||
|
TestParse("0.0", false, 0);
|
||||||
|
TestParse("0.5", false, 0);
|
||||||
|
TestParse("5.0", true, 5);
|
||||||
|
TestParse("5.5", true, 5);
|
||||||
|
TestParse("x", false, 0);
|
||||||
|
TestParse("x0", false, 0);
|
||||||
|
TestParse("x5", false, 0);
|
||||||
|
TestParse("0x", false, 0);
|
||||||
|
TestParse("5x", true, 5);
|
||||||
|
TestParse("0x5", false, 0);
|
||||||
|
TestParse("false", false, 0);
|
||||||
|
TestParse("true", false, 0);
|
||||||
|
TestParse("yes", false, 0);
|
||||||
|
TestParse("no", false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(util_GetBoolArg)
|
BOOST_AUTO_TEST_CASE(util_GetBoolArg)
|
||||||
{
|
{
|
||||||
TestArgsManager testArgs;
|
TestArgsManager testArgs;
|
||||||
|
Loading…
Reference in New Issue
Block a user