mirror of
https://github.com/CLIUtils/CLI11.git
synced 2026-01-19 04:52:08 +00:00
add checks and fixes for extrasError argument order (#1162)
Adds tests and checks for Extras Error Builds on #1158 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1259,6 +1259,21 @@ TEST_CASE_METHOD(TApp, "ExpectedRangeParam", "[app]") {
|
||||
args = {"-s", "one", "two", "three", "four", "five"};
|
||||
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
|
||||
args = {"-s", "one", "two", "three", "four", "five", "six", "seven"};
|
||||
|
||||
try {
|
||||
run();
|
||||
CHECK(false);
|
||||
} catch(const CLI::ExtrasError &err) {
|
||||
std::string message = err.what();
|
||||
auto fiveloc = message.find("five");
|
||||
auto sixloc = message.find("six");
|
||||
auto sevenloc = message.find("seven");
|
||||
CHECK(fiveloc < sixloc);
|
||||
CHECK(sixloc < sevenloc);
|
||||
CHECK(sevenloc != std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TApp, "ExpectedRangePositional", "[app]") {
|
||||
@@ -1325,7 +1340,15 @@ TEST_CASE_METHOD(TApp, "PositionalAtEnd", "[app]") {
|
||||
CHECK("param1" == foo);
|
||||
|
||||
args = {"param2", "-O", "Test"};
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
try {
|
||||
run();
|
||||
CHECK(false);
|
||||
} catch(const CLI::ExtrasError &err) {
|
||||
std::string message = err.what();
|
||||
auto oloc = message.find("-O");
|
||||
auto tloc = message.find("Test");
|
||||
CHECK(oloc < tloc);
|
||||
}
|
||||
}
|
||||
|
||||
// Tests positionals at end
|
||||
@@ -2387,6 +2410,7 @@ TEST_CASE_METHOD(TApp, "AllowExtrasCascade", "[app]") {
|
||||
TEST_CASE_METHOD(TApp, "ExtrasErrorRvalueParse", "[app]") {
|
||||
|
||||
args = {"-x", "45", "-f", "27"};
|
||||
|
||||
CHECK_THROWS_AS(app.parse(std::vector<std::string>({"-x", "45", "-f", "27"})), CLI::ExtrasError);
|
||||
}
|
||||
|
||||
|
||||
@@ -395,7 +395,7 @@ TEST_CASE("StringTools: escapeConversion", "[helpers]") {
|
||||
TEST_CASE("StringTools: quotedString", "[helpers]") {
|
||||
|
||||
std::string rstring = "'B\"(\\x35\\xa7)\"'";
|
||||
auto s2 = rstring;
|
||||
std::string s2{rstring};
|
||||
CLI::detail::process_quoted_string(s2);
|
||||
CHECK(s2[0] == static_cast<char>(0x35));
|
||||
CHECK(s2[1] == static_cast<char>(0xa7));
|
||||
|
||||
Reference in New Issue
Block a user