Commit 8635c4d0eb458621a294a0851ba9736f025e29b7

Authored by Henry Fredrick Schreiner
Committed by Henry Schreiner
1 parent 3cb75b90

Dropping reset in favor of clear

include/CLI/App.hpp
... ... @@ -878,6 +878,21 @@ class App {
878 878 ///@}
879 879 /// @name Parsing
880 880 ///@{
  881 + //
  882 + /// Reset the parsed data
  883 + void clear() {
  884 +
  885 + parsed_ = false;
  886 + missing_.clear();
  887 + parsed_subcommands_.clear();
  888 +
  889 + for(const Option_p &opt : options_) {
  890 + opt->clear();
  891 + }
  892 + for(const App_p &app : subcommands_) {
  893 + app->clear();
  894 + }
  895 + }
881 896  
882 897 /// Parses the command line - throws errors
883 898 /// This must be called after the options are in but before the rest of the program.
... ... @@ -895,6 +910,10 @@ class App {
895 910 /// The real work is done here. Expects a reversed vector.
896 911 /// Changes the vector to the remaining options.
897 912 void parse(std::vector<std::string> &args) {
  913 + // Clear if parsed
  914 + if(parsed_)
  915 + clear();
  916 +
898 917 _validate();
899 918 _parse(args);
900 919 run_callback();
... ... @@ -930,21 +949,6 @@ class App {
930 949 return e.get_exit_code();
931 950 }
932 951  
933   - /// Reset the parsed data
934   - void reset() {
935   -
936   - parsed_ = false;
937   - missing_.clear();
938   - parsed_subcommands_.clear();
939   -
940   - for(const Option_p &opt : options_) {
941   - opt->clear();
942   - }
943   - for(const App_p &app : subcommands_) {
944   - app->reset();
945   - }
946   - }
947   -
948 952 ///@}
949 953 /// @name Post parsing
950 954 ///@{
... ...
tests/AppTest.cpp
... ... @@ -152,13 +152,10 @@ TEST_F(TApp, BoolAndIntFlags) {
152 152 EXPECT_EQ(1, iflag);
153 153 EXPECT_EQ((unsigned int)1, uflag);
154 154  
155   - app.reset();
156   -
157 155 args = {"-b", "-b"};
158   - EXPECT_NO_THROW(run());
  156 + ASSERT_NO_THROW(run());
159 157 EXPECT_TRUE(bflag);
160 158  
161   - app.reset();
162 159 bflag = false;
163 160  
164 161 args = {"-iiiuu"};
... ... @@ -173,11 +170,9 @@ TEST_F(TApp, BoolOnlyFlag) {
173 170 app.add_flag("-b", bflag)->multi_option_policy(CLI::MultiOptionPolicy::Throw);
174 171  
175 172 args = {"-b"};
176   - EXPECT_NO_THROW(run());
  173 + ASSERT_NO_THROW(run());
177 174 EXPECT_TRUE(bflag);
178 175  
179   - app.reset();
180   -
181 176 args = {"-b", "-b"};
182 177 EXPECT_THROW(run(), CLI::ConversionError);
183 178 }
... ... @@ -331,8 +326,7 @@ TEST_F(TApp, MissingValueNonRequiredOpt) {
331 326  
332 327 args = {"-c"};
333 328 EXPECT_THROW(run(), CLI::ArgumentMismatch);
334   -
335   - app.reset();
  329 + app.clear();
336 330  
337 331 args = {"--count"};
338 332 EXPECT_THROW(run(), CLI::ArgumentMismatch);
... ... @@ -346,8 +340,7 @@ TEST_F(TApp, MissingValueMoreThan) {
346 340  
347 341 args = {"-v", "2"};
348 342 EXPECT_THROW(run(), CLI::ArgumentMismatch);
349   -
350   - app.reset();
  343 + app.clear();
351 344  
352 345 args = {"--vals", "4"};
353 346 EXPECT_THROW(run(), CLI::ArgumentMismatch);
... ... @@ -363,8 +356,6 @@ TEST_F(TApp, NoMissingValueMoreThan) {
363 356 run();
364 357 EXPECT_EQ(vals1, std::vector<int>({2, 3, 4}));
365 358  
366   - app.reset();
367   -
368 359 args = {"--vals", "2", "3", "4"};
369 360 run();
370 361 EXPECT_EQ(vals2, std::vector<int>({2, 3, 4}));
... ... @@ -419,7 +410,7 @@ TEST_F(TApp, RequiredOptsDouble) {
419 410  
420 411 EXPECT_THROW(run(), CLI::ArgumentMismatch);
421 412  
422   - app.reset();
  413 + app.clear();
423 414 args = {"--str", "one", "two"};
424 415  
425 416 run();
... ... @@ -435,8 +426,7 @@ TEST_F(TApp, RequiredOptsDoubleShort) {
435 426 args = {"-s", "one"};
436 427  
437 428 EXPECT_THROW(run(), CLI::ArgumentMismatch);
438   -
439   - app.reset();
  429 + app.clear();
440 430  
441 431 args = {"-s", "one", "-s", "one", "-s", "one"};
442 432  
... ... @@ -450,20 +440,15 @@ TEST_F(TApp, RequiredOptsDoubleNeg) {
450 440 args = {"-s", "one"};
451 441  
452 442 EXPECT_THROW(run(), CLI::ArgumentMismatch);
453   -
454   - app.reset();
  443 + app.clear();
455 444  
456 445 args = {"-s", "one", "two", "-s", "three"};
457 446  
458   - EXPECT_NO_THROW(run());
459   -
  447 + ASSERT_NO_THROW(run());
460 448 EXPECT_EQ(strs, std::vector<std::string>({"one", "two", "three"}));
461 449  
462   - app.reset();
463 450 args = {"-s", "one", "two"};
464   -
465   - EXPECT_NO_THROW(run());
466   -
  451 + ASSERT_NO_THROW(run());
467 452 EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
468 453 }
469 454  
... ... @@ -483,7 +468,6 @@ TEST_F(TApp, PositionalNoSpace) {
483 468 EXPECT_EQ(options.size(), (size_t)1);
484 469 EXPECT_EQ(options.at(0), "Test");
485 470  
486   - app.reset();
487 471 args = {"-OTest", "param1", "param2"};
488 472 run();
489 473  
... ... @@ -505,7 +489,6 @@ TEST_F(TApp, PositionalNoSpaceLong) {
505 489 EXPECT_EQ(options.size(), (size_t)1);
506 490 EXPECT_EQ(options.at(0), "Test");
507 491  
508   - app.reset();
509 492 args = {"--option=Test", "param1", "param2"};
510 493 run();
511 494  
... ... @@ -520,25 +503,22 @@ TEST_F(TApp, RequiredOptsUnlimited) {
520 503  
521 504 args = {"--str"};
522 505 EXPECT_THROW(run(), CLI::ArgumentMismatch);
  506 + app.clear();
523 507  
524   - app.reset();
525 508 args = {"--str", "one", "--str", "two"};
526 509 run();
527 510 EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
528 511  
529   - app.reset();
530 512 args = {"--str", "one", "two"};
531 513 run();
532 514 EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
533 515  
534 516 // It's better to feed a hungry option than to feed allow_extras
535   - app.reset();
536 517 app.allow_extras();
537 518 run();
538 519 EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
539 520 EXPECT_EQ(app.remaining(), std::vector<std::string>({}));
540 521  
541   - app.reset();
542 522 app.allow_extras(false);
543 523 std::vector<std::string> remain;
544 524 app.add_option("positional", remain);
... ... @@ -546,14 +526,12 @@ TEST_F(TApp, RequiredOptsUnlimited) {
546 526 EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
547 527 EXPECT_EQ(remain, std::vector<std::string>());
548 528  
549   - app.reset();
550 529 args = {"--str", "one", "--", "two"};
551 530  
552 531 run();
553 532 EXPECT_EQ(strs, std::vector<std::string>({"one"}));
554 533 EXPECT_EQ(remain, std::vector<std::string>({"two"}));
555 534  
556   - app.reset();
557 535 args = {"one", "--str", "two"};
558 536  
559 537 run();
... ... @@ -568,25 +546,22 @@ TEST_F(TApp, RequiredOptsUnlimitedShort) {
568 546  
569 547 args = {"-s"};
570 548 EXPECT_THROW(run(), CLI::ArgumentMismatch);
  549 + app.clear();
571 550  
572   - app.reset();
573 551 args = {"-s", "one", "-s", "two"};
574 552 run();
575 553 EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
576 554  
577   - app.reset();
578 555 args = {"-s", "one", "two"};
579 556 run();
580 557 EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
581 558  
582 559 // It's better to feed a hungry option than to feed allow_extras
583   - app.reset();
584 560 app.allow_extras();
585 561 run();
586 562 EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
587 563 EXPECT_EQ(app.remaining(), std::vector<std::string>({}));
588 564  
589   - app.reset();
590 565 app.allow_extras(false);
591 566 std::vector<std::string> remain;
592 567 app.add_option("positional", remain);
... ... @@ -594,14 +569,12 @@ TEST_F(TApp, RequiredOptsUnlimitedShort) {
594 569 EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
595 570 EXPECT_EQ(remain, std::vector<std::string>());
596 571  
597   - app.reset();
598 572 args = {"-s", "one", "--", "two"};
599 573  
600 574 run();
601 575 EXPECT_EQ(strs, std::vector<std::string>({"one"}));
602 576 EXPECT_EQ(remain, std::vector<std::string>({"two"}));
603 577  
604   - app.reset();
605 578 args = {"one", "-s", "two"};
606 579  
607 580 run();
... ... @@ -635,7 +608,6 @@ TEST_F(TApp, RequireOptPriority) {
635 608 EXPECT_EQ(strs, std::vector<std::string>({"one"}));
636 609 EXPECT_EQ(remain, std::vector<std::string>({"two", "three"}));
637 610  
638   - app.reset();
639 611 args = {"two", "three", "--str", "one", "four"};
640 612 run();
641 613  
... ... @@ -656,7 +628,6 @@ TEST_F(TApp, RequireOptPriorityShort) {
656 628 EXPECT_EQ(strs, std::vector<std::string>({"one"}));
657 629 EXPECT_EQ(remain, std::vector<std::string>({"two", "three"}));
658 630  
659   - app.reset();
660 631 args = {"two", "three", "-s", "one", "four"};
661 632 run();
662 633  
... ... @@ -689,17 +660,16 @@ TEST_F(TApp, RequiredFlags) {
689 660 app.add_flag("-b")->mandatory(); // Alternate term
690 661  
691 662 EXPECT_THROW(run(), CLI::RequiredError);
692   -
693   - app.reset();
  663 + app.clear();
694 664  
695 665 args = {"-a"};
696 666 EXPECT_THROW(run(), CLI::RequiredError);
  667 + app.clear();
697 668  
698   - app.reset();
699 669 args = {"-b"};
700 670 EXPECT_THROW(run(), CLI::RequiredError);
  671 + app.clear();
701 672  
702   - app.reset();
703 673 args = {"-a", "-b"};
704 674 run();
705 675 }
... ... @@ -715,12 +685,10 @@ TEST_F(TApp, CallbackFlags) {
715 685 run();
716 686 EXPECT_EQ(value, (size_t)0);
717 687  
718   - app.reset();
719 688 args = {"-v"};
720 689 run();
721 690 EXPECT_EQ(value, (size_t)1);
722 691  
723   - app.reset();
724 692 args = {"-vv"};
725 693 run();
726 694 EXPECT_EQ(value, (size_t)2);
... ... @@ -740,12 +708,10 @@ TEST_F(TApp, CallbackFlagsAuto) {
740 708 run();
741 709 EXPECT_EQ(value, (size_t)0);
742 710  
743   - app.reset();
744 711 args = {"-v"};
745 712 run();
746 713 EXPECT_EQ(value, (size_t)1);
747 714  
748   - app.reset();
749 715 args = {"-vv"};
750 716 run();
751 717 EXPECT_EQ(value, (size_t)2);
... ... @@ -782,8 +748,6 @@ TEST_F(TApp, ForcedPositional) {
782 748 EXPECT_TRUE(one->count());
783 749 EXPECT_EQ(answers1, posit);
784 750  
785   - app.reset();
786   -
787 751 args = {"--", "--one", "two", "three"};
788 752 std::vector<std::string> answers2 = {"--one", "two", "three"};
789 753 run();
... ... @@ -818,8 +782,6 @@ TEST_F(TApp, BigPositional) {
818 782 run();
819 783 EXPECT_EQ(args, vec);
820 784  
821   - app.reset();
822   -
823 785 args = {"one", "two"};
824 786 run();
825 787  
... ... @@ -840,7 +802,7 @@ TEST_F(TApp, Reset) {
840 802 EXPECT_EQ((size_t)1, app.count("-d"));
841 803 EXPECT_DOUBLE_EQ(1.2, doub);
842 804  
843   - app.reset();
  805 + app.clear();
844 806  
845 807 EXPECT_EQ((size_t)0, app.count("--simple"));
846 808 EXPECT_EQ((size_t)0, app.count("-d"));
... ... @@ -866,7 +828,7 @@ TEST_F(TApp, RemoveOption) {
866 828  
867 829 TEST_F(TApp, FileNotExists) {
868 830 std::string myfile{"TestNonFileNotUsed.txt"};
869   - EXPECT_NO_THROW(CLI::NonexistentPath(myfile));
  831 + ASSERT_NO_THROW(CLI::NonexistentPath(myfile));
870 832  
871 833 std::string filename;
872 834 app.add_option("--file", filename)->check(CLI::NonexistentPath);
... ... @@ -875,8 +837,6 @@ TEST_F(TApp, FileNotExists) {
875 837 run();
876 838 EXPECT_EQ(myfile, filename);
877 839  
878   - app.reset();
879   -
880 840 bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
881 841 EXPECT_TRUE(ok);
882 842 EXPECT_THROW(run(), CLI::ValidationError);
... ... @@ -894,8 +854,7 @@ TEST_F(TApp, FileExists) {
894 854 args = {"--file", myfile};
895 855  
896 856 EXPECT_THROW(run(), CLI::ValidationError);
897   -
898   - app.reset();
  857 + app.clear();
899 858  
900 859 bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
901 860 EXPECT_TRUE(ok);
... ... @@ -916,8 +875,6 @@ TEST_F(TApp, InSet) {
916 875 run();
917 876 EXPECT_EQ("two", choice);
918 877  
919   - app.reset();
920   -
921 878 args = {"--quick", "four"};
922 879 EXPECT_THROW(run(), CLI::ConversionError);
923 880 }
... ... @@ -929,15 +886,12 @@ TEST_F(TApp, InSetWithDefault) {
929 886  
930 887 run();
931 888 EXPECT_EQ("one", choice);
932   - app.reset();
933 889  
934 890 args = {"--quick", "two"};
935 891  
936 892 run();
937 893 EXPECT_EQ("two", choice);
938 894  
939   - app.reset();
940   -
941 895 args = {"--quick", "four"};
942 896 EXPECT_THROW(run(), CLI::ConversionError);
943 897 }
... ... @@ -949,15 +903,12 @@ TEST_F(TApp, InCaselessSetWithDefault) {
949 903  
950 904 run();
951 905 EXPECT_EQ("one", choice);
952   - app.reset();
953 906  
954 907 args = {"--quick", "tWo"};
955 908  
956 909 run();
957 910 EXPECT_EQ("two", choice);
958 911  
959   - app.reset();
960   -
961 912 args = {"--quick", "four"};
962 913 EXPECT_THROW(run(), CLI::ConversionError);
963 914 }
... ... @@ -972,8 +923,6 @@ TEST_F(TApp, InIntSet) {
972 923 run();
973 924 EXPECT_EQ(2, choice);
974 925  
975   - app.reset();
976   -
977 926 args = {"--quick", "4"};
978 927 EXPECT_THROW(run(), CLI::ConversionError);
979 928 }
... ... @@ -985,8 +934,7 @@ TEST_F(TApp, FailSet) {
985 934  
986 935 args = {"--quick", "3", "--quick=2"};
987 936 EXPECT_THROW(run(), CLI::ArgumentMismatch);
988   -
989   - app.reset();
  937 + app.clear();
990 938  
991 939 args = {"--quick=hello"};
992 940 EXPECT_THROW(run(), CLI::ConversionError);
... ... @@ -1001,8 +949,8 @@ TEST_F(TApp, FailLValueSet) {
1001 949  
1002 950 args = {"--quick=hello"};
1003 951 EXPECT_THROW(run(), CLI::ConversionError);
  952 + app.clear();
1004 953  
1005   - app.reset();
1006 954 args = {"--slow=hello"};
1007 955 EXPECT_THROW(run(), CLI::ConversionError);
1008 956 }
... ... @@ -1016,21 +964,18 @@ TEST_F(TApp, InSetIgnoreCase) {
1016 964 run();
1017 965 EXPECT_EQ("one", choice);
1018 966  
1019   - app.reset();
1020 967 args = {"--quick", "two"};
1021 968 run();
1022 969 EXPECT_EQ("Two", choice); // Keeps caps from set
1023 970  
1024   - app.reset();
1025 971 args = {"--quick", "ThrEE"};
1026 972 run();
1027 973 EXPECT_EQ("THREE", choice); // Keeps caps from set
1028 974  
1029   - app.reset();
1030 975 args = {"--quick", "four"};
1031 976 EXPECT_THROW(run(), CLI::ConversionError);
  977 + app.clear();
1032 978  
1033   - app.reset();
1034 979 args = {"--quick=one", "--quick=two"};
1035 980 EXPECT_THROW(run(), CLI::ArgumentMismatch);
1036 981 }
... ... @@ -1073,7 +1018,6 @@ TEST_F(TApp, VectorUnlimString) {
1073 1018 EXPECT_EQ((size_t)3, app.count("--string"));
1074 1019 EXPECT_EQ(answer, strvec);
1075 1020  
1076   - app.reset();
1077 1021 args = {"-s", "mystring", "mystring2", "mystring3"};
1078 1022 run();
1079 1023 EXPECT_EQ((size_t)3, app.count("--string"));
... ... @@ -1092,11 +1036,10 @@ TEST_F(TApp, VectorFancyOpts) {
1092 1036 EXPECT_EQ((size_t)3, app.count("--string"));
1093 1037 EXPECT_EQ(answer, strvec);
1094 1038  
1095   - app.reset();
1096 1039 args = {"one", "two"};
1097 1040 EXPECT_THROW(run(), CLI::RequiredError);
  1041 + app.clear();
1098 1042  
1099   - app.reset();
1100 1043 EXPECT_THROW(run(), CLI::ParseError);
1101 1044 }
1102 1045  
... ... @@ -1122,15 +1065,12 @@ TEST_F(TApp, NeedsFlags) {
1122 1065  
1123 1066 run();
1124 1067  
1125   - app.reset();
1126 1068 args = {"-s"};
1127 1069 run();
1128 1070  
1129   - app.reset();
1130 1071 args = {"-s", "--both"};
1131 1072 run();
1132 1073  
1133   - app.reset();
1134 1074 args = {"--both"};
1135 1075 EXPECT_THROW(run(), CLI::RequiresError);
1136 1076 }
... ... @@ -1141,19 +1081,16 @@ TEST_F(TApp, ExcludesFlags) {
1141 1081  
1142 1082 run();
1143 1083  
1144   - app.reset();
1145 1084 args = {"-s"};
1146 1085 run();
1147 1086  
1148   - app.reset();
1149 1087 args = {"--nostr"};
1150 1088 run();
1151 1089  
1152   - app.reset();
1153 1090 args = {"--nostr", "-s"};
1154 1091 EXPECT_THROW(run(), CLI::ExcludesError);
  1092 + app.clear();
1155 1093  
1156   - app.reset();
1157 1094 args = {"--string", "--nostr"};
1158 1095 EXPECT_THROW(run(), CLI::ExcludesError);
1159 1096 }
... ... @@ -1166,19 +1103,16 @@ TEST_F(TApp, ExcludesMixedFlags) {
1166 1103  
1167 1104 run();
1168 1105  
1169   - app.reset();
1170 1106 args = {"--no"};
1171 1107 run();
1172 1108  
1173   - app.reset();
1174 1109 args = {"--opt2"};
1175 1110 run();
1176 1111  
1177   - app.reset();
1178 1112 args = {"--no", "--opt1"};
1179 1113 EXPECT_THROW(run(), CLI::ExcludesError);
  1114 + app.clear();
1180 1115  
1181   - app.reset();
1182 1116 args = {"--no", "--opt2"};
1183 1117 EXPECT_THROW(run(), CLI::ExcludesError);
1184 1118 }
... ... @@ -1191,27 +1125,24 @@ TEST_F(TApp, NeedsMultiFlags) {
1191 1125  
1192 1126 run();
1193 1127  
1194   - app.reset();
1195 1128 args = {"--opt1"};
1196 1129 run();
1197 1130  
1198   - app.reset();
1199 1131 args = {"--opt2"};
1200 1132 run();
1201 1133  
1202   - app.reset();
1203 1134 args = {"--optall"};
1204 1135 EXPECT_THROW(run(), CLI::RequiresError);
  1136 + app.clear();
1205 1137  
1206   - app.reset();
1207 1138 args = {"--optall", "--opt1"};
1208 1139 EXPECT_THROW(run(), CLI::RequiresError);
  1140 + app.clear();
1209 1141  
1210   - app.reset();
1211 1142 args = {"--optall", "--opt2", "--opt1"};
1212 1143 EXPECT_THROW(run(), CLI::RequiresError);
  1144 + app.clear();
1213 1145  
1214   - app.reset();
1215 1146 args = {"--optall", "--opt1", "--opt2", "--opt3"};
1216 1147 run();
1217 1148 }
... ... @@ -1224,27 +1155,24 @@ TEST_F(TApp, NeedsMixedFlags) {
1224 1155  
1225 1156 run();
1226 1157  
1227   - app.reset();
1228 1158 args = {"--opt1"};
1229 1159 run();
1230 1160  
1231   - app.reset();
1232 1161 args = {"--opt2"};
1233 1162 run();
1234 1163  
1235   - app.reset();
1236 1164 args = {"--optall"};
1237 1165 EXPECT_THROW(run(), CLI::RequiresError);
  1166 + app.clear();
1238 1167  
1239   - app.reset();
1240 1168 args = {"--optall", "--opt1"};
1241 1169 EXPECT_THROW(run(), CLI::RequiresError);
  1170 + app.clear();
1242 1171  
1243   - app.reset();
1244 1172 args = {"--optall", "--opt2", "--opt1"};
1245 1173 EXPECT_THROW(run(), CLI::RequiresError);
  1174 + app.clear();
1246 1175  
1247   - app.reset();
1248 1176 args = {"--optall", "--opt1", "--opt2", "--opt3"};
1249 1177 run();
1250 1178 }
... ... @@ -1256,31 +1184,28 @@ TEST_F(TApp, NeedsChainedFlags) {
1256 1184  
1257 1185 run();
1258 1186  
1259   - app.reset();
1260 1187 args = {"--opt1"};
1261 1188 run();
1262 1189  
1263   - app.reset();
1264 1190 args = {"--opt2"};
1265 1191 EXPECT_THROW(run(), CLI::RequiresError);
  1192 + app.clear();
1266 1193  
1267   - app.reset();
1268 1194 args = {"--opt3"};
1269 1195 EXPECT_THROW(run(), CLI::RequiresError);
  1196 + app.clear();
1270 1197  
1271   - app.reset();
1272 1198 args = {"--opt3", "--opt2"};
1273 1199 EXPECT_THROW(run(), CLI::RequiresError);
  1200 + app.clear();
1274 1201  
1275   - app.reset();
1276 1202 args = {"--opt3", "--opt1"};
1277 1203 EXPECT_THROW(run(), CLI::RequiresError);
  1204 + app.clear();
1278 1205  
1279   - app.reset();
1280 1206 args = {"--opt2", "--opt1"};
1281 1207 run();
1282 1208  
1283   - app.reset();
1284 1209 args = {"--opt1", "--opt2", "--opt3"};
1285 1210 run();
1286 1211 }
... ... @@ -1297,11 +1222,9 @@ TEST_F(TApp, Env) {
1297 1222 EXPECT_EQ(2, val);
1298 1223 EXPECT_EQ((size_t)1, vopt->count());
1299 1224  
1300   - app.reset();
1301 1225 vopt->required();
1302 1226 run();
1303 1227  
1304   - app.reset();
1305 1228 unset_env("CLI11_TEST_ENV_TMP");
1306 1229 EXPECT_THROW(run(), CLI::RequiredError);
1307 1230 }
... ... @@ -1312,20 +1235,18 @@ TEST_F(TApp, RangeInt) {
1312 1235  
1313 1236 args = {"--one=1"};
1314 1237 EXPECT_THROW(run(), CLI::ValidationError);
  1238 + app.clear();
1315 1239  
1316   - app.reset();
1317 1240 args = {"--one=7"};
1318 1241 EXPECT_THROW(run(), CLI::ValidationError);
  1242 + app.clear();
1319 1243  
1320   - app.reset();
1321 1244 args = {"--one=3"};
1322 1245 run();
1323 1246  
1324   - app.reset();
1325 1247 args = {"--one=5"};
1326 1248 run();
1327 1249  
1328   - app.reset();
1329 1250 args = {"--one=6"};
1330 1251 run();
1331 1252 }
... ... @@ -1338,20 +1259,18 @@ TEST_F(TApp, RangeDouble) {
1338 1259  
1339 1260 args = {"--one=1"};
1340 1261 EXPECT_THROW(run(), CLI::ValidationError);
  1262 + app.clear();
1341 1263  
1342   - app.reset();
1343 1264 args = {"--one=7"};
1344 1265 EXPECT_THROW(run(), CLI::ValidationError);
  1266 + app.clear();
1345 1267  
1346   - app.reset();
1347 1268 args = {"--one=3"};
1348 1269 run();
1349 1270  
1350   - app.reset();
1351 1271 args = {"--one=5"};
1352 1272 run();
1353 1273  
1354   - app.reset();
1355 1274 args = {"--one=6"};
1356 1275 run();
1357 1276 }
... ... @@ -1367,7 +1286,7 @@ TEST_F(TApp, AllowExtras) {
1367 1286  
1368 1287 args = {"-x", "-f"};
1369 1288  
1370   - EXPECT_NO_THROW(run());
  1289 + ASSERT_NO_THROW(run());
1371 1290 EXPECT_TRUE(val);
1372 1291 EXPECT_EQ(app.remaining(), std::vector<std::string>({"-x"}));
1373 1292 }
... ... @@ -1377,9 +1296,8 @@ TEST_F(TApp, AllowExtrasOrder) {
1377 1296 app.allow_extras();
1378 1297  
1379 1298 args = {"-x", "-f"};
1380   - EXPECT_NO_THROW(run());
  1299 + ASSERT_NO_THROW(run());
1381 1300 EXPECT_EQ(app.remaining(), std::vector<std::string>({"-x", "-f"}));
1382   - app.reset();
1383 1301  
1384 1302 std::vector<std::string> left_over = app.remaining();
1385 1303 app.parse(left_over);
... ... @@ -1462,14 +1380,12 @@ TEST_F(TApp, ThrowingTransform) {
1462 1380 auto m = app.add_option("-m,--mess", val);
1463 1381 m->transform([](std::string) -> std::string { throw CLI::ValidationError("My Message"); });
1464 1382  
1465   - EXPECT_NO_THROW(run());
1466   - app.reset();
  1383 + ASSERT_NO_THROW(run());
1467 1384  
1468 1385 args = {"-mone"};
1469 1386  
1470 1387 ASSERT_THROW(run(), CLI::ValidationError);
1471   -
1472   - app.reset();
  1388 + app.clear();
1473 1389  
1474 1390 try {
1475 1391 run();
... ... @@ -1533,17 +1449,15 @@ TEST_F(TApp, AddRemoveSetItems) {
1533 1449 items.erase("TYPE1");
1534 1450 items.erase("TYPE2");
1535 1451  
1536   - app.reset();
1537 1452 args = {"--type1", "TYPE6", "--type2", "TYPE7"};
1538 1453 run();
1539 1454 EXPECT_EQ(type1, "TYPE6");
1540 1455 EXPECT_EQ(type2, "TYPE7");
1541 1456  
1542   - app.reset();
1543 1457 args = {"--type1", "TYPE1"};
1544 1458 EXPECT_THROW(run(), CLI::ConversionError);
  1459 + app.clear();
1545 1460  
1546   - app.reset();
1547 1461 args = {"--type2", "TYPE2"};
1548 1462 EXPECT_THROW(run(), CLI::ConversionError);
1549 1463 }
... ... @@ -1567,17 +1481,15 @@ TEST_F(TApp, AddRemoveSetItemsNoCase) {
1567 1481 items.erase("TYPE1");
1568 1482 items.erase("TYPE2");
1569 1483  
1570   - app.reset();
1571 1484 args = {"--type1", "TyPE6", "--type2", "tYPE7"};
1572 1485 run();
1573 1486 EXPECT_EQ(type1, "TYPE6");
1574 1487 EXPECT_EQ(type2, "TYPE7");
1575 1488  
1576   - app.reset();
1577 1489 args = {"--type1", "TYPe1"};
1578 1490 EXPECT_THROW(run(), CLI::ConversionError);
  1491 + app.clear();
1579 1492  
1580   - app.reset();
1581 1493 args = {"--type2", "TYpE2"};
1582 1494 EXPECT_THROW(run(), CLI::ConversionError);
1583 1495 }
... ... @@ -1588,10 +1500,9 @@ TEST_F(TApp, RepeatingMultiArgumentOptions) {
1588 1500 app.add_option("--entry", entries, "set a key and value")->type_name("KEY VALUE")->type_size(-2);
1589 1501  
1590 1502 args = {"--entry", "key1", "value1", "--entry", "key2", "value2"};
1591   - EXPECT_NO_THROW(run());
  1503 + ASSERT_NO_THROW(run());
1592 1504 EXPECT_EQ(entries, std::vector<std::string>({"key1", "value1", "key2", "value2"}));
1593 1505  
1594   - app.reset();
1595 1506 args.pop_back();
1596 1507 ASSERT_THROW(run(), CLI::ArgumentMismatch);
1597 1508 }
... ...
tests/HelpTest.cpp
... ... @@ -326,14 +326,14 @@ 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();
329 330  
330   - app.reset();
331 331 std::vector<std::string> input2{"--yelp"};
332 332 EXPECT_THROW(app.parse(input2), CLI::CallForAllHelp);
  333 + app.clear();
333 334  
334 335 // Remove the flag
335 336 app.set_help_all_flag();
336   - app.reset();
337 337 std::vector<std::string> input3{"--yelp"};
338 338 EXPECT_THROW(app.parse(input3), CLI::ExtrasError);
339 339 }
... ...
tests/IniTest.cpp
... ... @@ -193,7 +193,6 @@ TEST_F(TApp, IniNotRequired) {
193 193 EXPECT_EQ(99, two);
194 194 EXPECT_EQ(3, three);
195 195  
196   - app.reset();
197 196 one = two = three = 0;
198 197 args = {"--one=1", "--two=2"};
199 198  
... ... @@ -238,7 +237,7 @@ TEST_F(TApp, IniGetRemainingOption) {
238 237  
239 238 int two = 0;
240 239 app.add_option("--two", two);
241   - EXPECT_NO_THROW(run());
  240 + ASSERT_NO_THROW(run());
242 241 std::vector<std::string> ExpectedRemaining = {ExtraOption};
243 242 EXPECT_EQ(app.remaining(), ExpectedRemaining);
244 243 }
... ... @@ -256,7 +255,7 @@ TEST_F(TApp, IniGetNoRemaining) {
256 255  
257 256 int two = 0;
258 257 app.add_option("--two", two);
259   - EXPECT_NO_THROW(run());
  258 + ASSERT_NO_THROW(run());
260 259 EXPECT_EQ(app.remaining().size(), (size_t)0);
261 260 }
262 261  
... ... @@ -291,7 +290,6 @@ TEST_F(TApp, IniNotRequiredNotDefault) {
291 290 EXPECT_EQ(99, two);
292 291 EXPECT_EQ(3, three);
293 292  
294   - app.reset();
295 293 args = {"--config", tmpini2};
296 294 run();
297 295  
... ... @@ -360,18 +358,16 @@ TEST_F(TApp, IniRequired) {
360 358  
361 359 run();
362 360  
363   - app.reset();
364 361 one = two = three = 0;
365 362 args = {"--one=1", "--two=2"};
366 363  
367 364 run();
368 365  
369   - app.reset();
370 366 args = {};
371 367  
372 368 EXPECT_THROW(run(), CLI::RequiredError);
  369 + app.clear();
373 370  
374   - app.reset();
375 371 args = {"--two=2"};
376 372  
377 373 EXPECT_THROW(run(), CLI::RequiredError);
... ... @@ -458,7 +454,7 @@ TEST_F(TApp, IniConfigurable) {
458 454 out << "val=1" << std::endl;
459 455 }
460 456  
461   - EXPECT_NO_THROW(run());
  457 + ASSERT_NO_THROW(run());
462 458 EXPECT_TRUE(value);
463 459 }
464 460  
... ... @@ -538,7 +534,7 @@ TEST_F(TApp, IniFlagNumbers) {
538 534 out << "flag=3" << std::endl;
539 535 }
540 536  
541   - EXPECT_NO_THROW(run());
  537 + ASSERT_NO_THROW(run());
542 538 EXPECT_TRUE(boo);
543 539 }
544 540  
... ...
tests/OptionalTest.cpp
... ... @@ -11,13 +11,11 @@ TEST_F(TApp, StdOptionalTest) {
11 11 run();
12 12 EXPECT_FALSE(opt);
13 13  
14   - app.reset();
15 14 args = {"-c", "1"};
16 15 run();
17 16 EXPECT_TRUE(opt);
18 17 EXPECT_EQ(*opt, 1);
19 18  
20   - app.reset();
21 19 args = {"--count", "3"};
22 20 run();
23 21 EXPECT_TRUE(opt);
... ... @@ -33,13 +31,11 @@ TEST_F(TApp, ExperimentalOptionalTest) {
33 31 run();
34 32 EXPECT_FALSE(opt);
35 33  
36   - app.reset();
37 34 args = {"-c", "1"};
38 35 run();
39 36 EXPECT_TRUE(opt);
40 37 EXPECT_EQ(*opt, 1);
41 38  
42   - app.reset();
43 39 args = {"--count", "3"};
44 40 run();
45 41 EXPECT_TRUE(opt);
... ... @@ -55,13 +51,11 @@ TEST_F(TApp, BoostOptionalTest) {
55 51 run();
56 52 EXPECT_FALSE(opt);
57 53  
58   - app.reset();
59 54 args = {"-c", "1"};
60 55 run();
61 56 EXPECT_TRUE(opt);
62 57 EXPECT_EQ(*opt, 1);
63 58  
64   - app.reset();
65 59 args = {"--count", "3"};
66 60 run();
67 61 EXPECT_TRUE(opt);
... ...
tests/SubcommandTest.cpp
... ... @@ -21,12 +21,12 @@ TEST_F(TApp, BasicSubcommands) {
21 21 run();
22 22 EXPECT_EQ((size_t)0, app.get_subcommands().size());
23 23  
24   - app.reset();
25 24 args = {"sub1"};
26 25 run();
27 26 EXPECT_EQ(sub1, app.get_subcommands().at(0));
  27 + EXPECT_EQ((size_t)1, app.get_subcommands().size());
28 28  
29   - app.reset();
  29 + app.clear();
30 30 EXPECT_EQ((size_t)0, app.get_subcommands().size());
31 31  
32 32 args = {"sub2"};
... ... @@ -34,19 +34,18 @@ TEST_F(TApp, BasicSubcommands) {
34 34 EXPECT_EQ((size_t)1, app.get_subcommands().size());
35 35 EXPECT_EQ(sub2, app.get_subcommands().at(0));
36 36  
37   - app.reset();
38 37 args = {"SUb2"};
39 38 EXPECT_THROW(run(), CLI::ExtrasError);
  39 + app.clear();
40 40  
41   - app.reset();
42 41 args = {"SUb2"};
43 42 try {
44 43 run();
45 44 } catch(const CLI::ExtrasError &e) {
46 45 EXPECT_THAT(e.what(), HasSubstr("SUb2"));
47 46 }
  47 + app.clear();
48 48  
49   - app.reset();
50 49 args = {"sub1", "extra"};
51 50 try {
52 51 run();
... ... @@ -72,22 +71,19 @@ TEST_F(TApp, MultiSubFallthrough) {
72 71 EXPECT_TRUE(app.got_subcommand(sub2));
73 72 EXPECT_TRUE(*sub2);
74 73  
75   - app.reset();
76 74 app.require_subcommand();
77 75  
78 76 run();
79 77  
80   - app.reset();
81 78 app.require_subcommand(2);
82 79  
83 80 run();
84 81  
85   - app.reset();
86 82 app.require_subcommand(1);
87 83  
88 84 EXPECT_THROW(run(), CLI::ExtrasError);
  85 + app.clear();
89 86  
90   - app.reset();
91 87 args = {"sub1"};
92 88 run();
93 89  
... ... @@ -109,24 +105,21 @@ TEST_F(TApp, RequiredAndSubcoms) { // #23
109 105 auto bar = app.add_subcommand("bar");
110 106  
111 107 args = {"bar", "foo"};
112   - EXPECT_NO_THROW(run());
  108 + ASSERT_NO_THROW(run());
113 109 EXPECT_TRUE(*foo);
114 110 EXPECT_FALSE(*bar);
115 111 EXPECT_EQ(baz, "bar");
116 112  
117   - app.reset();
118 113 args = {"foo"};
119   - EXPECT_NO_THROW(run());
  114 + ASSERT_NO_THROW(run());
120 115 EXPECT_FALSE(*foo);
121 116 EXPECT_EQ(baz, "foo");
122 117  
123   - app.reset();
124 118 args = {"foo", "foo"};
125   - EXPECT_NO_THROW(run());
  119 + ASSERT_NO_THROW(run());
126 120 EXPECT_TRUE(*foo);
127 121 EXPECT_EQ(baz, "foo");
128 122  
129   - app.reset();
130 123 args = {"foo", "other"};
131 124 EXPECT_THROW(run(), CLI::ExtrasError);
132 125 }
... ... @@ -144,7 +137,6 @@ TEST_F(TApp, RequiredAndSubcomFallthrough) {
144 137 EXPECT_TRUE(bar);
145 138 EXPECT_EQ(baz, "other");
146 139  
147   - app.reset();
148 140 args = {"bar", "other2"};
149 141 EXPECT_THROW(run(), CLI::ExtrasError);
150 142 }
... ... @@ -164,7 +156,6 @@ TEST_F(TApp, FooFooProblem) {
164 156 EXPECT_EQ(baz_str, "");
165 157 EXPECT_EQ(other_str, "foo");
166 158  
167   - app.reset();
168 159 baz_str = "";
169 160 other_str = "";
170 161 baz->required();
... ... @@ -198,19 +189,18 @@ TEST_F(TApp, RuntimeErrorInCallback) {
198 189 args = {"sub1"};
199 190 EXPECT_THROW(run(), CLI::RuntimeError);
200 191  
201   - app.reset();
202 192 args = {"sub1"};
203 193 try {
204 194 run();
205 195 } catch(const CLI::RuntimeError &e) {
206 196 EXPECT_EQ(1, e.get_exit_code());
207 197 }
  198 + app.clear();
208 199  
209   - app.reset();
210 200 args = {"sub2"};
211 201 EXPECT_THROW(run(), CLI::RuntimeError);
  202 + app.clear();
212 203  
213   - app.reset();
214 204 args = {"sub2"};
215 205 try {
216 206 run();
... ... @@ -316,7 +306,6 @@ TEST_F(TApp, CallbackOrdering) {
316 306 EXPECT_EQ(2, val);
317 307 EXPECT_EQ(2, sub_val);
318 308  
319   - app.reset();
320 309 args = {"--val=2", "sub"};
321 310 run();
322 311 EXPECT_EQ(2, val);
... ... @@ -330,11 +319,9 @@ TEST_F(TApp, RequiredSubCom) {
330 319 app.require_subcommand();
331 320  
332 321 EXPECT_THROW(run(), CLI::RequiredError);
333   -
334   - app.reset();
  322 + app.clear();
335 323  
336 324 args = {"sub1"};
337   -
338 325 run();
339 326 }
340 327  
... ... @@ -347,22 +334,16 @@ TEST_F(TApp, SubComExtras) {
347 334 EXPECT_EQ(app.remaining(), std::vector<std::string>({"extra"}));
348 335 EXPECT_EQ(sub->remaining(), std::vector<std::string>());
349 336  
350   - app.reset();
351   -
352 337 args = {"extra1", "extra2", "sub"};
353 338 run();
354 339 EXPECT_EQ(app.remaining(), std::vector<std::string>({"extra1", "extra2"}));
355 340 EXPECT_EQ(sub->remaining(), std::vector<std::string>());
356 341  
357   - app.reset();
358   -
359 342 args = {"sub", "extra1", "extra2"};
360 343 run();
361 344 EXPECT_EQ(app.remaining(), std::vector<std::string>());
362 345 EXPECT_EQ(sub->remaining(), std::vector<std::string>({"extra1", "extra2"}));
363 346  
364   - app.reset();
365   -
366 347 args = {"extra1", "extra2", "sub", "extra3", "extra4"};
367 348 run();
368 349 EXPECT_EQ(app.remaining(), std::vector<std::string>({"extra1", "extra2"}));
... ... @@ -377,12 +358,11 @@ TEST_F(TApp, Required1SubCom) {
377 358 app.add_subcommand("sub3");
378 359  
379 360 EXPECT_THROW(run(), CLI::RequiredError);
  361 + app.clear();
380 362  
381   - app.reset();
382 363 args = {"sub1"};
383 364 run();
384 365  
385   - app.reset();
386 366 args = {"sub1", "sub2"};
387 367 EXPECT_THROW(run(), CLI::ExtrasError);
388 368 }
... ... @@ -522,16 +502,14 @@ TEST_F(SubcommandProgram, MultipleArgs) {
522 502 TEST_F(SubcommandProgram, CaseCheck) {
523 503 args = {"Start"};
524 504 EXPECT_THROW(run(), CLI::ExtrasError);
  505 + app.clear();
525 506  
526   - app.reset();
527 507 args = {"start"};
528 508 run();
529 509  
530   - app.reset();
531 510 start->ignore_case();
532 511 run();
533 512  
534   - app.reset();
535 513 args = {"Start"};
536 514 run();
537 515 }
... ... @@ -546,12 +524,12 @@ TEST_F(TApp, SubcomInheritCaseCheck) {
546 524 EXPECT_EQ((size_t)2, app.get_subcommands({}).size());
547 525 EXPECT_EQ((size_t)1, app.get_subcommands([](const CLI::App *s) { return s->get_name() == "sub1"; }).size());
548 526  
549   - app.reset();
550 527 args = {"SuB1"};
551 528 run();
552 529 EXPECT_EQ(sub1, app.get_subcommands().at(0));
  530 + EXPECT_EQ((size_t)1, app.get_subcommands().size());
553 531  
554   - app.reset();
  532 + app.clear();
555 533 EXPECT_EQ((size_t)0, app.get_subcommands().size());
556 534  
557 535 args = {"sUb2"};
... ... @@ -577,8 +555,6 @@ TEST_F(SubcommandProgram, Callbacks) {
577 555  
578 556 run();
579 557  
580   - app.reset();
581   -
582 558 args = {"start"};
583 559  
584 560 EXPECT_THROW(run(), CLI::Success);
... ... @@ -606,15 +582,15 @@ TEST_F(SubcommandProgram, ExtrasErrors) {
606 582  
607 583 args = {"one", "two", "start", "three", "four"};
608 584 EXPECT_THROW(run(), CLI::ExtrasError);
609   - app.reset();
  585 + app.clear();
610 586  
611 587 args = {"start", "three", "four"};
612 588 EXPECT_THROW(run(), CLI::ExtrasError);
613   - app.reset();
  589 + app.clear();
614 590  
615 591 args = {"one", "two"};
616 592 EXPECT_THROW(run(), CLI::ExtrasError);
617   - app.reset();
  593 + app.clear();
618 594 }
619 595  
620 596 TEST_F(SubcommandProgram, OrderedExtras) {
... ... @@ -622,7 +598,7 @@ TEST_F(SubcommandProgram, OrderedExtras) {
622 598 app.allow_extras();
623 599 args = {"one", "two", "start", "three", "four"};
624 600 EXPECT_THROW(run(), CLI::ExtrasError);
625   - app.reset();
  601 + app.clear();
626 602  
627 603 start->allow_extras();
628 604  
... ... @@ -632,7 +608,6 @@ TEST_F(SubcommandProgram, OrderedExtras) {
632 608 EXPECT_EQ(start->remaining(), std::vector<std::string>({"three", "four"}));
633 609 EXPECT_EQ(app.remaining(true), std::vector<std::string>({"one", "two", "three", "four"}));
634 610  
635   - app.reset();
636 611 args = {"one", "two", "start", "three", "--", "four"};
637 612  
638 613 run();
... ... @@ -656,7 +631,6 @@ TEST_F(SubcommandProgram, MixedOrderExtras) {
656 631 EXPECT_EQ(stop->remaining(), std::vector<std::string>({"five", "six"}));
657 632 EXPECT_EQ(app.remaining(true), std::vector<std::string>({"one", "two", "three", "four", "five", "six"}));
658 633  
659   - app.reset();
660 634 args = {"one", "two", "stop", "three", "four", "start", "five", "six"};
661 635 run();
662 636  
... ... @@ -675,7 +649,6 @@ TEST_F(SubcommandProgram, CallbackOrder) {
675 649 run();
676 650 EXPECT_EQ(callback_order, std::vector<int>({1, 2}));
677 651  
678   - app.reset();
679 652 callback_order.clear();
680 653  
681 654 args = {"stop", "start"};
... ... @@ -728,7 +701,6 @@ TEST_F(ManySubcommands, Required1Fuzzy) {
728 701 run();
729 702 EXPECT_EQ(sub1->remaining(), vs_t({"sub2", "sub3"}));
730 703  
731   - app.reset();
732 704 app.require_subcommand(-1);
733 705  
734 706 run();
... ... @@ -742,7 +714,6 @@ TEST_F(ManySubcommands, Required2Fuzzy) {
742 714 EXPECT_EQ(sub2->remaining(), vs_t({"sub3"}));
743 715 EXPECT_EQ(app.remaining(true), vs_t({"sub3"}));
744 716  
745   - app.reset();
746 717 app.require_subcommand(-2);
747 718  
748 719 run();
... ... @@ -753,13 +724,11 @@ TEST_F(ManySubcommands, Unlimited) {
753 724 run();
754 725 EXPECT_EQ(app.remaining(true), vs_t());
755 726  
756   - app.reset();
757 727 app.require_subcommand();
758 728  
759 729 run();
760 730 EXPECT_EQ(app.remaining(true), vs_t());
761 731  
762   - app.reset();
763 732 app.require_subcommand(2, 0); // 2 or more
764 733  
765 734 run();
... ...