mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
Dropping last (required) usages of clear
This commit is contained in:
parent
bf4ad1d717
commit
85aa0e7813
@ -914,6 +914,11 @@ class App {
|
|||||||
if(parsed_)
|
if(parsed_)
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
// Redundant (set by _parse on commands/subcommands)
|
||||||
|
// but placed here to make sure this is cleared when
|
||||||
|
// running parse after an error is thrown, even by _validate.
|
||||||
|
parsed_ = true;
|
||||||
|
|
||||||
_validate();
|
_validate();
|
||||||
_parse(args);
|
_parse(args);
|
||||||
run_callback();
|
run_callback();
|
||||||
|
@ -326,7 +326,6 @@ TEST_F(TApp, MissingValueNonRequiredOpt) {
|
|||||||
|
|
||||||
args = {"-c"};
|
args = {"-c"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--count"};
|
args = {"--count"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
@ -340,7 +339,6 @@ TEST_F(TApp, MissingValueMoreThan) {
|
|||||||
|
|
||||||
args = {"-v", "2"};
|
args = {"-v", "2"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--vals", "4"};
|
args = {"--vals", "4"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
@ -410,7 +408,6 @@ TEST_F(TApp, RequiredOptsDouble) {
|
|||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
|
|
||||||
app.clear();
|
|
||||||
args = {"--str", "one", "two"};
|
args = {"--str", "one", "two"};
|
||||||
|
|
||||||
run();
|
run();
|
||||||
@ -426,7 +423,6 @@ TEST_F(TApp, RequiredOptsDoubleShort) {
|
|||||||
args = {"-s", "one"};
|
args = {"-s", "one"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"-s", "one", "-s", "one", "-s", "one"};
|
args = {"-s", "one", "-s", "one", "-s", "one"};
|
||||||
|
|
||||||
@ -440,7 +436,6 @@ TEST_F(TApp, RequiredOptsDoubleNeg) {
|
|||||||
args = {"-s", "one"};
|
args = {"-s", "one"};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"-s", "one", "two", "-s", "three"};
|
args = {"-s", "one", "two", "-s", "three"};
|
||||||
|
|
||||||
@ -503,7 +498,6 @@ TEST_F(TApp, RequiredOptsUnlimited) {
|
|||||||
|
|
||||||
args = {"--str"};
|
args = {"--str"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--str", "one", "--str", "two"};
|
args = {"--str", "one", "--str", "two"};
|
||||||
run();
|
run();
|
||||||
@ -546,7 +540,6 @@ TEST_F(TApp, RequiredOptsUnlimitedShort) {
|
|||||||
|
|
||||||
args = {"-s"};
|
args = {"-s"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"-s", "one", "-s", "two"};
|
args = {"-s", "one", "-s", "two"};
|
||||||
run();
|
run();
|
||||||
@ -660,15 +653,12 @@ TEST_F(TApp, RequiredFlags) {
|
|||||||
app.add_flag("-b")->mandatory(); // Alternate term
|
app.add_flag("-b")->mandatory(); // Alternate term
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
EXPECT_THROW(run(), CLI::RequiredError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"-a"};
|
args = {"-a"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
EXPECT_THROW(run(), CLI::RequiredError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"-b"};
|
args = {"-b"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
EXPECT_THROW(run(), CLI::RequiredError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"-a", "-b"};
|
args = {"-a", "-b"};
|
||||||
run();
|
run();
|
||||||
@ -854,7 +844,6 @@ TEST_F(TApp, FileExists) {
|
|||||||
args = {"--file", myfile};
|
args = {"--file", myfile};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
EXPECT_THROW(run(), CLI::ValidationError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
|
bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
|
||||||
EXPECT_TRUE(ok);
|
EXPECT_TRUE(ok);
|
||||||
@ -934,7 +923,6 @@ TEST_F(TApp, FailSet) {
|
|||||||
|
|
||||||
args = {"--quick", "3", "--quick=2"};
|
args = {"--quick", "3", "--quick=2"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--quick=hello"};
|
args = {"--quick=hello"};
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
EXPECT_THROW(run(), CLI::ConversionError);
|
||||||
@ -949,7 +937,6 @@ TEST_F(TApp, FailLValueSet) {
|
|||||||
|
|
||||||
args = {"--quick=hello"};
|
args = {"--quick=hello"};
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
EXPECT_THROW(run(), CLI::ConversionError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--slow=hello"};
|
args = {"--slow=hello"};
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
EXPECT_THROW(run(), CLI::ConversionError);
|
||||||
@ -974,7 +961,6 @@ TEST_F(TApp, InSetIgnoreCase) {
|
|||||||
|
|
||||||
args = {"--quick", "four"};
|
args = {"--quick", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
EXPECT_THROW(run(), CLI::ConversionError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--quick=one", "--quick=two"};
|
args = {"--quick=one", "--quick=two"};
|
||||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||||
@ -1038,7 +1024,6 @@ TEST_F(TApp, VectorFancyOpts) {
|
|||||||
|
|
||||||
args = {"one", "two"};
|
args = {"one", "two"};
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
EXPECT_THROW(run(), CLI::RequiredError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ParseError);
|
EXPECT_THROW(run(), CLI::ParseError);
|
||||||
}
|
}
|
||||||
@ -1089,7 +1074,6 @@ TEST_F(TApp, ExcludesFlags) {
|
|||||||
|
|
||||||
args = {"--nostr", "-s"};
|
args = {"--nostr", "-s"};
|
||||||
EXPECT_THROW(run(), CLI::ExcludesError);
|
EXPECT_THROW(run(), CLI::ExcludesError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--string", "--nostr"};
|
args = {"--string", "--nostr"};
|
||||||
EXPECT_THROW(run(), CLI::ExcludesError);
|
EXPECT_THROW(run(), CLI::ExcludesError);
|
||||||
@ -1111,7 +1095,6 @@ TEST_F(TApp, ExcludesMixedFlags) {
|
|||||||
|
|
||||||
args = {"--no", "--opt1"};
|
args = {"--no", "--opt1"};
|
||||||
EXPECT_THROW(run(), CLI::ExcludesError);
|
EXPECT_THROW(run(), CLI::ExcludesError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--no", "--opt2"};
|
args = {"--no", "--opt2"};
|
||||||
EXPECT_THROW(run(), CLI::ExcludesError);
|
EXPECT_THROW(run(), CLI::ExcludesError);
|
||||||
@ -1133,15 +1116,12 @@ TEST_F(TApp, NeedsMultiFlags) {
|
|||||||
|
|
||||||
args = {"--optall"};
|
args = {"--optall"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
EXPECT_THROW(run(), CLI::RequiresError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--optall", "--opt1"};
|
args = {"--optall", "--opt1"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
EXPECT_THROW(run(), CLI::RequiresError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--optall", "--opt2", "--opt1"};
|
args = {"--optall", "--opt2", "--opt1"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
EXPECT_THROW(run(), CLI::RequiresError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--optall", "--opt1", "--opt2", "--opt3"};
|
args = {"--optall", "--opt1", "--opt2", "--opt3"};
|
||||||
run();
|
run();
|
||||||
@ -1163,15 +1143,12 @@ TEST_F(TApp, NeedsMixedFlags) {
|
|||||||
|
|
||||||
args = {"--optall"};
|
args = {"--optall"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
EXPECT_THROW(run(), CLI::RequiresError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--optall", "--opt1"};
|
args = {"--optall", "--opt1"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
EXPECT_THROW(run(), CLI::RequiresError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--optall", "--opt2", "--opt1"};
|
args = {"--optall", "--opt2", "--opt1"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
EXPECT_THROW(run(), CLI::RequiresError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--optall", "--opt1", "--opt2", "--opt3"};
|
args = {"--optall", "--opt1", "--opt2", "--opt3"};
|
||||||
run();
|
run();
|
||||||
@ -1189,19 +1166,15 @@ TEST_F(TApp, NeedsChainedFlags) {
|
|||||||
|
|
||||||
args = {"--opt2"};
|
args = {"--opt2"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
EXPECT_THROW(run(), CLI::RequiresError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--opt3"};
|
args = {"--opt3"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
EXPECT_THROW(run(), CLI::RequiresError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--opt3", "--opt2"};
|
args = {"--opt3", "--opt2"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
EXPECT_THROW(run(), CLI::RequiresError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--opt3", "--opt1"};
|
args = {"--opt3", "--opt1"};
|
||||||
EXPECT_THROW(run(), CLI::RequiresError);
|
EXPECT_THROW(run(), CLI::RequiresError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--opt2", "--opt1"};
|
args = {"--opt2", "--opt1"};
|
||||||
run();
|
run();
|
||||||
@ -1235,11 +1208,9 @@ TEST_F(TApp, RangeInt) {
|
|||||||
|
|
||||||
args = {"--one=1"};
|
args = {"--one=1"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
EXPECT_THROW(run(), CLI::ValidationError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--one=7"};
|
args = {"--one=7"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
EXPECT_THROW(run(), CLI::ValidationError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--one=3"};
|
args = {"--one=3"};
|
||||||
run();
|
run();
|
||||||
@ -1259,11 +1230,9 @@ TEST_F(TApp, RangeDouble) {
|
|||||||
|
|
||||||
args = {"--one=1"};
|
args = {"--one=1"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
EXPECT_THROW(run(), CLI::ValidationError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--one=7"};
|
args = {"--one=7"};
|
||||||
EXPECT_THROW(run(), CLI::ValidationError);
|
EXPECT_THROW(run(), CLI::ValidationError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--one=3"};
|
args = {"--one=3"};
|
||||||
run();
|
run();
|
||||||
@ -1385,7 +1354,6 @@ TEST_F(TApp, ThrowingTransform) {
|
|||||||
args = {"-mone"};
|
args = {"-mone"};
|
||||||
|
|
||||||
ASSERT_THROW(run(), CLI::ValidationError);
|
ASSERT_THROW(run(), CLI::ValidationError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
run();
|
run();
|
||||||
@ -1456,7 +1424,6 @@ TEST_F(TApp, AddRemoveSetItems) {
|
|||||||
|
|
||||||
args = {"--type1", "TYPE1"};
|
args = {"--type1", "TYPE1"};
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
EXPECT_THROW(run(), CLI::ConversionError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--type2", "TYPE2"};
|
args = {"--type2", "TYPE2"};
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
EXPECT_THROW(run(), CLI::ConversionError);
|
||||||
@ -1488,7 +1455,6 @@ TEST_F(TApp, AddRemoveSetItemsNoCase) {
|
|||||||
|
|
||||||
args = {"--type1", "TYPe1"};
|
args = {"--type1", "TYPe1"};
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
EXPECT_THROW(run(), CLI::ConversionError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--type2", "TYpE2"};
|
args = {"--type2", "TYpE2"};
|
||||||
EXPECT_THROW(run(), CLI::ConversionError);
|
EXPECT_THROW(run(), CLI::ConversionError);
|
||||||
|
@ -326,11 +326,9 @@ TEST(THelp, OnlyOneAllHelp) {
|
|||||||
|
|
||||||
std::vector<std::string> input{"--help-all"};
|
std::vector<std::string> input{"--help-all"};
|
||||||
EXPECT_THROW(app.parse(input), CLI::ExtrasError);
|
EXPECT_THROW(app.parse(input), CLI::ExtrasError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
std::vector<std::string> input2{"--yelp"};
|
std::vector<std::string> input2{"--yelp"};
|
||||||
EXPECT_THROW(app.parse(input2), CLI::CallForAllHelp);
|
EXPECT_THROW(app.parse(input2), CLI::CallForAllHelp);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
// Remove the flag
|
// Remove the flag
|
||||||
app.set_help_all_flag();
|
app.set_help_all_flag();
|
||||||
|
@ -366,7 +366,6 @@ TEST_F(TApp, IniRequired) {
|
|||||||
args = {};
|
args = {};
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
EXPECT_THROW(run(), CLI::RequiredError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"--two=2"};
|
args = {"--two=2"};
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ TEST_F(TApp, BasicSubcommands) {
|
|||||||
|
|
||||||
args = {"SUb2"};
|
args = {"SUb2"};
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"SUb2"};
|
args = {"SUb2"};
|
||||||
try {
|
try {
|
||||||
@ -44,7 +43,6 @@ TEST_F(TApp, BasicSubcommands) {
|
|||||||
} catch(const CLI::ExtrasError &e) {
|
} catch(const CLI::ExtrasError &e) {
|
||||||
EXPECT_THAT(e.what(), HasSubstr("SUb2"));
|
EXPECT_THAT(e.what(), HasSubstr("SUb2"));
|
||||||
}
|
}
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"sub1", "extra"};
|
args = {"sub1", "extra"};
|
||||||
try {
|
try {
|
||||||
@ -82,7 +80,6 @@ TEST_F(TApp, MultiSubFallthrough) {
|
|||||||
app.require_subcommand(1);
|
app.require_subcommand(1);
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"sub1"};
|
args = {"sub1"};
|
||||||
run();
|
run();
|
||||||
@ -195,11 +192,9 @@ TEST_F(TApp, RuntimeErrorInCallback) {
|
|||||||
} catch(const CLI::RuntimeError &e) {
|
} catch(const CLI::RuntimeError &e) {
|
||||||
EXPECT_EQ(1, e.get_exit_code());
|
EXPECT_EQ(1, e.get_exit_code());
|
||||||
}
|
}
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"sub2"};
|
args = {"sub2"};
|
||||||
EXPECT_THROW(run(), CLI::RuntimeError);
|
EXPECT_THROW(run(), CLI::RuntimeError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"sub2"};
|
args = {"sub2"};
|
||||||
try {
|
try {
|
||||||
@ -319,7 +314,6 @@ TEST_F(TApp, RequiredSubCom) {
|
|||||||
app.require_subcommand();
|
app.require_subcommand();
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
EXPECT_THROW(run(), CLI::RequiredError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"sub1"};
|
args = {"sub1"};
|
||||||
run();
|
run();
|
||||||
@ -358,7 +352,6 @@ TEST_F(TApp, Required1SubCom) {
|
|||||||
app.add_subcommand("sub3");
|
app.add_subcommand("sub3");
|
||||||
|
|
||||||
EXPECT_THROW(run(), CLI::RequiredError);
|
EXPECT_THROW(run(), CLI::RequiredError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"sub1"};
|
args = {"sub1"};
|
||||||
run();
|
run();
|
||||||
@ -502,7 +495,6 @@ TEST_F(SubcommandProgram, MultipleArgs) {
|
|||||||
TEST_F(SubcommandProgram, CaseCheck) {
|
TEST_F(SubcommandProgram, CaseCheck) {
|
||||||
args = {"Start"};
|
args = {"Start"};
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"start"};
|
args = {"start"};
|
||||||
run();
|
run();
|
||||||
@ -582,15 +574,12 @@ TEST_F(SubcommandProgram, ExtrasErrors) {
|
|||||||
|
|
||||||
args = {"one", "two", "start", "three", "four"};
|
args = {"one", "two", "start", "three", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"start", "three", "four"};
|
args = {"start", "three", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
args = {"one", "two"};
|
args = {"one", "two"};
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||||
app.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SubcommandProgram, OrderedExtras) {
|
TEST_F(SubcommandProgram, OrderedExtras) {
|
||||||
@ -598,7 +587,6 @@ TEST_F(SubcommandProgram, OrderedExtras) {
|
|||||||
app.allow_extras();
|
app.allow_extras();
|
||||||
args = {"one", "two", "start", "three", "four"};
|
args = {"one", "two", "start", "three", "four"};
|
||||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||||
app.clear();
|
|
||||||
|
|
||||||
start->allow_extras();
|
start->allow_extras();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user