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:
Philip Top
2025-05-09 08:06:25 -07:00
committed by GitHub
parent 1364746d4c
commit 990956f4f8
3 changed files with 30 additions and 3 deletions

View File

@@ -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);
}

View File

@@ -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));