Skip to content

Commit 990956f

Browse files
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>
1 parent 1364746 commit 990956f

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

include/CLI/impl/App_inl.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,10 @@ CLI11_INLINE bool App::_parse_positional(std::vector<std::string> &args, bool ha
18001800
}
18011801
}
18021802
if(positionals_at_end_) {
1803-
throw CLI::ExtrasError(name_, args);
1803+
std::vector<std::string> rargs;
1804+
rargs.resize(args.size());
1805+
std::reverse_copy(args.begin(), args.end(), rargs.begin());
1806+
throw CLI::ExtrasError(name_, rargs);
18041807
}
18051808
/// If this is an option group don't deal with it
18061809
if(parent_ != nullptr && name_.empty()) {

tests/AppTest.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,21 @@ TEST_CASE_METHOD(TApp, "ExpectedRangeParam", "[app]") {
12591259
args = {"-s", "one", "two", "three", "four", "five"};
12601260

12611261
CHECK_THROWS_AS(run(), CLI::ExtrasError);
1262+
1263+
args = {"-s", "one", "two", "three", "four", "five", "six", "seven"};
1264+
1265+
try {
1266+
run();
1267+
CHECK(false);
1268+
} catch(const CLI::ExtrasError &err) {
1269+
std::string message = err.what();
1270+
auto fiveloc = message.find("five");
1271+
auto sixloc = message.find("six");
1272+
auto sevenloc = message.find("seven");
1273+
CHECK(fiveloc < sixloc);
1274+
CHECK(sixloc < sevenloc);
1275+
CHECK(sevenloc != std::string::npos);
1276+
}
12621277
}
12631278

12641279
TEST_CASE_METHOD(TApp, "ExpectedRangePositional", "[app]") {
@@ -1325,7 +1340,15 @@ TEST_CASE_METHOD(TApp, "PositionalAtEnd", "[app]") {
13251340
CHECK("param1" == foo);
13261341

13271342
args = {"param2", "-O", "Test"};
1328-
CHECK_THROWS_AS(run(), CLI::ExtrasError);
1343+
try {
1344+
run();
1345+
CHECK(false);
1346+
} catch(const CLI::ExtrasError &err) {
1347+
std::string message = err.what();
1348+
auto oloc = message.find("-O");
1349+
auto tloc = message.find("Test");
1350+
CHECK(oloc < tloc);
1351+
}
13291352
}
13301353

13311354
// Tests positionals at end
@@ -2387,6 +2410,7 @@ TEST_CASE_METHOD(TApp, "AllowExtrasCascade", "[app]") {
23872410
TEST_CASE_METHOD(TApp, "ExtrasErrorRvalueParse", "[app]") {
23882411

23892412
args = {"-x", "45", "-f", "27"};
2413+
23902414
CHECK_THROWS_AS(app.parse(std::vector<std::string>({"-x", "45", "-f", "27"})), CLI::ExtrasError);
23912415
}
23922416

tests/HelpersTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ TEST_CASE("StringTools: escapeConversion", "[helpers]") {
395395
TEST_CASE("StringTools: quotedString", "[helpers]") {
396396

397397
std::string rstring = "'B\"(\\x35\\xa7)\"'";
398-
auto s2 = rstring;
398+
std::string s2{rstring};
399399
CLI::detail::process_quoted_string(s2);
400400
CHECK(s2[0] == static_cast<char>(0x35));
401401
CHECK(s2[1] == static_cast<char>(0xa7));

0 commit comments

Comments
 (0)