Commit 85aa0e7813a8ec927da5fe08bd265f1303cc272e

Authored by Henry Fredrick Schreiner
Committed by Henry Schreiner
1 parent bf4ad1d7

Dropping last (required) usages of clear

include/CLI/App.hpp
... ... @@ -914,6 +914,11 @@ class App {
914 914 if(parsed_)
915 915 clear();
916 916  
  917 + // Redundant (set by _parse on commands/subcommands)
  918 + // but placed here to make sure this is cleared when
  919 + // running parse after an error is thrown, even by _validate.
  920 + parsed_ = true;
  921 +
917 922 _validate();
918 923 _parse(args);
919 924 run_callback();
... ...
tests/AppTest.cpp
... ... @@ -326,7 +326,6 @@ TEST_F(TApp, MissingValueNonRequiredOpt) {
326 326  
327 327 args = {"-c"};
328 328 EXPECT_THROW(run(), CLI::ArgumentMismatch);
329   - app.clear();
330 329  
331 330 args = {"--count"};
332 331 EXPECT_THROW(run(), CLI::ArgumentMismatch);
... ... @@ -340,7 +339,6 @@ TEST_F(TApp, MissingValueMoreThan) {
340 339  
341 340 args = {"-v", "2"};
342 341 EXPECT_THROW(run(), CLI::ArgumentMismatch);
343   - app.clear();
344 342  
345 343 args = {"--vals", "4"};
346 344 EXPECT_THROW(run(), CLI::ArgumentMismatch);
... ... @@ -410,7 +408,6 @@ TEST_F(TApp, RequiredOptsDouble) {
410 408  
411 409 EXPECT_THROW(run(), CLI::ArgumentMismatch);
412 410  
413   - app.clear();
414 411 args = {"--str", "one", "two"};
415 412  
416 413 run();
... ... @@ -426,7 +423,6 @@ TEST_F(TApp, RequiredOptsDoubleShort) {
426 423 args = {"-s", "one"};
427 424  
428 425 EXPECT_THROW(run(), CLI::ArgumentMismatch);
429   - app.clear();
430 426  
431 427 args = {"-s", "one", "-s", "one", "-s", "one"};
432 428  
... ... @@ -440,7 +436,6 @@ TEST_F(TApp, RequiredOptsDoubleNeg) {
440 436 args = {"-s", "one"};
441 437  
442 438 EXPECT_THROW(run(), CLI::ArgumentMismatch);
443   - app.clear();
444 439  
445 440 args = {"-s", "one", "two", "-s", "three"};
446 441  
... ... @@ -503,7 +498,6 @@ TEST_F(TApp, RequiredOptsUnlimited) {
503 498  
504 499 args = {"--str"};
505 500 EXPECT_THROW(run(), CLI::ArgumentMismatch);
506   - app.clear();
507 501  
508 502 args = {"--str", "one", "--str", "two"};
509 503 run();
... ... @@ -546,7 +540,6 @@ TEST_F(TApp, RequiredOptsUnlimitedShort) {
546 540  
547 541 args = {"-s"};
548 542 EXPECT_THROW(run(), CLI::ArgumentMismatch);
549   - app.clear();
550 543  
551 544 args = {"-s", "one", "-s", "two"};
552 545 run();
... ... @@ -660,15 +653,12 @@ TEST_F(TApp, RequiredFlags) {
660 653 app.add_flag("-b")->mandatory(); // Alternate term
661 654  
662 655 EXPECT_THROW(run(), CLI::RequiredError);
663   - app.clear();
664 656  
665 657 args = {"-a"};
666 658 EXPECT_THROW(run(), CLI::RequiredError);
667   - app.clear();
668 659  
669 660 args = {"-b"};
670 661 EXPECT_THROW(run(), CLI::RequiredError);
671   - app.clear();
672 662  
673 663 args = {"-a", "-b"};
674 664 run();
... ... @@ -854,7 +844,6 @@ TEST_F(TApp, FileExists) {
854 844 args = {"--file", myfile};
855 845  
856 846 EXPECT_THROW(run(), CLI::ValidationError);
857   - app.clear();
858 847  
859 848 bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
860 849 EXPECT_TRUE(ok);
... ... @@ -934,7 +923,6 @@ TEST_F(TApp, FailSet) {
934 923  
935 924 args = {"--quick", "3", "--quick=2"};
936 925 EXPECT_THROW(run(), CLI::ArgumentMismatch);
937   - app.clear();
938 926  
939 927 args = {"--quick=hello"};
940 928 EXPECT_THROW(run(), CLI::ConversionError);
... ... @@ -949,7 +937,6 @@ TEST_F(TApp, FailLValueSet) {
949 937  
950 938 args = {"--quick=hello"};
951 939 EXPECT_THROW(run(), CLI::ConversionError);
952   - app.clear();
953 940  
954 941 args = {"--slow=hello"};
955 942 EXPECT_THROW(run(), CLI::ConversionError);
... ... @@ -974,7 +961,6 @@ TEST_F(TApp, InSetIgnoreCase) {
974 961  
975 962 args = {"--quick", "four"};
976 963 EXPECT_THROW(run(), CLI::ConversionError);
977   - app.clear();
978 964  
979 965 args = {"--quick=one", "--quick=two"};
980 966 EXPECT_THROW(run(), CLI::ArgumentMismatch);
... ... @@ -1038,7 +1024,6 @@ TEST_F(TApp, VectorFancyOpts) {
1038 1024  
1039 1025 args = {"one", "two"};
1040 1026 EXPECT_THROW(run(), CLI::RequiredError);
1041   - app.clear();
1042 1027  
1043 1028 EXPECT_THROW(run(), CLI::ParseError);
1044 1029 }
... ... @@ -1089,7 +1074,6 @@ TEST_F(TApp, ExcludesFlags) {
1089 1074  
1090 1075 args = {"--nostr", "-s"};
1091 1076 EXPECT_THROW(run(), CLI::ExcludesError);
1092   - app.clear();
1093 1077  
1094 1078 args = {"--string", "--nostr"};
1095 1079 EXPECT_THROW(run(), CLI::ExcludesError);
... ... @@ -1111,7 +1095,6 @@ TEST_F(TApp, ExcludesMixedFlags) {
1111 1095  
1112 1096 args = {"--no", "--opt1"};
1113 1097 EXPECT_THROW(run(), CLI::ExcludesError);
1114   - app.clear();
1115 1098  
1116 1099 args = {"--no", "--opt2"};
1117 1100 EXPECT_THROW(run(), CLI::ExcludesError);
... ... @@ -1133,15 +1116,12 @@ TEST_F(TApp, NeedsMultiFlags) {
1133 1116  
1134 1117 args = {"--optall"};
1135 1118 EXPECT_THROW(run(), CLI::RequiresError);
1136   - app.clear();
1137 1119  
1138 1120 args = {"--optall", "--opt1"};
1139 1121 EXPECT_THROW(run(), CLI::RequiresError);
1140   - app.clear();
1141 1122  
1142 1123 args = {"--optall", "--opt2", "--opt1"};
1143 1124 EXPECT_THROW(run(), CLI::RequiresError);
1144   - app.clear();
1145 1125  
1146 1126 args = {"--optall", "--opt1", "--opt2", "--opt3"};
1147 1127 run();
... ... @@ -1163,15 +1143,12 @@ TEST_F(TApp, NeedsMixedFlags) {
1163 1143  
1164 1144 args = {"--optall"};
1165 1145 EXPECT_THROW(run(), CLI::RequiresError);
1166   - app.clear();
1167 1146  
1168 1147 args = {"--optall", "--opt1"};
1169 1148 EXPECT_THROW(run(), CLI::RequiresError);
1170   - app.clear();
1171 1149  
1172 1150 args = {"--optall", "--opt2", "--opt1"};
1173 1151 EXPECT_THROW(run(), CLI::RequiresError);
1174   - app.clear();
1175 1152  
1176 1153 args = {"--optall", "--opt1", "--opt2", "--opt3"};
1177 1154 run();
... ... @@ -1189,19 +1166,15 @@ TEST_F(TApp, NeedsChainedFlags) {
1189 1166  
1190 1167 args = {"--opt2"};
1191 1168 EXPECT_THROW(run(), CLI::RequiresError);
1192   - app.clear();
1193 1169  
1194 1170 args = {"--opt3"};
1195 1171 EXPECT_THROW(run(), CLI::RequiresError);
1196   - app.clear();
1197 1172  
1198 1173 args = {"--opt3", "--opt2"};
1199 1174 EXPECT_THROW(run(), CLI::RequiresError);
1200   - app.clear();
1201 1175  
1202 1176 args = {"--opt3", "--opt1"};
1203 1177 EXPECT_THROW(run(), CLI::RequiresError);
1204   - app.clear();
1205 1178  
1206 1179 args = {"--opt2", "--opt1"};
1207 1180 run();
... ... @@ -1235,11 +1208,9 @@ TEST_F(TApp, RangeInt) {
1235 1208  
1236 1209 args = {"--one=1"};
1237 1210 EXPECT_THROW(run(), CLI::ValidationError);
1238   - app.clear();
1239 1211  
1240 1212 args = {"--one=7"};
1241 1213 EXPECT_THROW(run(), CLI::ValidationError);
1242   - app.clear();
1243 1214  
1244 1215 args = {"--one=3"};
1245 1216 run();
... ... @@ -1259,11 +1230,9 @@ TEST_F(TApp, RangeDouble) {
1259 1230  
1260 1231 args = {"--one=1"};
1261 1232 EXPECT_THROW(run(), CLI::ValidationError);
1262   - app.clear();
1263 1233  
1264 1234 args = {"--one=7"};
1265 1235 EXPECT_THROW(run(), CLI::ValidationError);
1266   - app.clear();
1267 1236  
1268 1237 args = {"--one=3"};
1269 1238 run();
... ... @@ -1385,7 +1354,6 @@ TEST_F(TApp, ThrowingTransform) {
1385 1354 args = {"-mone"};
1386 1355  
1387 1356 ASSERT_THROW(run(), CLI::ValidationError);
1388   - app.clear();
1389 1357  
1390 1358 try {
1391 1359 run();
... ... @@ -1456,7 +1424,6 @@ TEST_F(TApp, AddRemoveSetItems) {
1456 1424  
1457 1425 args = {"--type1", "TYPE1"};
1458 1426 EXPECT_THROW(run(), CLI::ConversionError);
1459   - app.clear();
1460 1427  
1461 1428 args = {"--type2", "TYPE2"};
1462 1429 EXPECT_THROW(run(), CLI::ConversionError);
... ... @@ -1488,7 +1455,6 @@ TEST_F(TApp, AddRemoveSetItemsNoCase) {
1488 1455  
1489 1456 args = {"--type1", "TYPe1"};
1490 1457 EXPECT_THROW(run(), CLI::ConversionError);
1491   - app.clear();
1492 1458  
1493 1459 args = {"--type2", "TYpE2"};
1494 1460 EXPECT_THROW(run(), CLI::ConversionError);
... ...
tests/HelpTest.cpp
... ... @@ -326,11 +326,9 @@ TEST(THelp, OnlyOneAllHelp) {
326 326  
327 327 std::vector<std::string> input{"--help-all"};
328 328 EXPECT_THROW(app.parse(input), CLI::ExtrasError);
329   - app.clear();
330 329  
331 330 std::vector<std::string> input2{"--yelp"};
332 331 EXPECT_THROW(app.parse(input2), CLI::CallForAllHelp);
333   - app.clear();
334 332  
335 333 // Remove the flag
336 334 app.set_help_all_flag();
... ...
tests/IniTest.cpp
... ... @@ -366,7 +366,6 @@ TEST_F(TApp, IniRequired) {
366 366 args = {};
367 367  
368 368 EXPECT_THROW(run(), CLI::RequiredError);
369   - app.clear();
370 369  
371 370 args = {"--two=2"};
372 371  
... ...
tests/SubcommandTest.cpp
... ... @@ -36,7 +36,6 @@ TEST_F(TApp, BasicSubcommands) {
36 36  
37 37 args = {"SUb2"};
38 38 EXPECT_THROW(run(), CLI::ExtrasError);
39   - app.clear();
40 39  
41 40 args = {"SUb2"};
42 41 try {
... ... @@ -44,7 +43,6 @@ TEST_F(TApp, BasicSubcommands) {
44 43 } catch(const CLI::ExtrasError &e) {
45 44 EXPECT_THAT(e.what(), HasSubstr("SUb2"));
46 45 }
47   - app.clear();
48 46  
49 47 args = {"sub1", "extra"};
50 48 try {
... ... @@ -82,7 +80,6 @@ TEST_F(TApp, MultiSubFallthrough) {
82 80 app.require_subcommand(1);
83 81  
84 82 EXPECT_THROW(run(), CLI::ExtrasError);
85   - app.clear();
86 83  
87 84 args = {"sub1"};
88 85 run();
... ... @@ -195,11 +192,9 @@ TEST_F(TApp, RuntimeErrorInCallback) {
195 192 } catch(const CLI::RuntimeError &e) {
196 193 EXPECT_EQ(1, e.get_exit_code());
197 194 }
198   - app.clear();
199 195  
200 196 args = {"sub2"};
201 197 EXPECT_THROW(run(), CLI::RuntimeError);
202   - app.clear();
203 198  
204 199 args = {"sub2"};
205 200 try {
... ... @@ -319,7 +314,6 @@ TEST_F(TApp, RequiredSubCom) {
319 314 app.require_subcommand();
320 315  
321 316 EXPECT_THROW(run(), CLI::RequiredError);
322   - app.clear();
323 317  
324 318 args = {"sub1"};
325 319 run();
... ... @@ -358,7 +352,6 @@ TEST_F(TApp, Required1SubCom) {
358 352 app.add_subcommand("sub3");
359 353  
360 354 EXPECT_THROW(run(), CLI::RequiredError);
361   - app.clear();
362 355  
363 356 args = {"sub1"};
364 357 run();
... ... @@ -502,7 +495,6 @@ TEST_F(SubcommandProgram, MultipleArgs) {
502 495 TEST_F(SubcommandProgram, CaseCheck) {
503 496 args = {"Start"};
504 497 EXPECT_THROW(run(), CLI::ExtrasError);
505   - app.clear();
506 498  
507 499 args = {"start"};
508 500 run();
... ... @@ -582,15 +574,12 @@ TEST_F(SubcommandProgram, ExtrasErrors) {
582 574  
583 575 args = {"one", "two", "start", "three", "four"};
584 576 EXPECT_THROW(run(), CLI::ExtrasError);
585   - app.clear();
586 577  
587 578 args = {"start", "three", "four"};
588 579 EXPECT_THROW(run(), CLI::ExtrasError);
589   - app.clear();
590 580  
591 581 args = {"one", "two"};
592 582 EXPECT_THROW(run(), CLI::ExtrasError);
593   - app.clear();
594 583 }
595 584  
596 585 TEST_F(SubcommandProgram, OrderedExtras) {
... ... @@ -598,7 +587,6 @@ TEST_F(SubcommandProgram, OrderedExtras) {
598 587 app.allow_extras();
599 588 args = {"one", "two", "start", "three", "four"};
600 589 EXPECT_THROW(run(), CLI::ExtrasError);
601   - app.clear();
602 590  
603 591 start->allow_extras();
604 592  
... ...