Commit 33f4c5783a42d0c84bc992a887ca311a80a70de2

Authored by Henry Fredrick Schreiner
1 parent 3e8502bf

Adding test for horrible error

include/CLI/App.hpp
... ... @@ -27,10 +27,12 @@ namespace CLI {
27 27  
28 28 namespace detail {
29 29 enum class Classifer {NONE, POSITIONAL_MARK, SHORT, LONG, SUBCOMMAND};
  30 +class AppFriend;
30 31 }
31 32  
32 33 class App;
33 34  
  35 +
34 36 typedef std::unique_ptr<App> App_p;
35 37  
36 38 /// Creates a command line program, with very few defaults.
... ... @@ -39,6 +41,7 @@ typedef std::unique_ptr&lt;App&gt; App_p;
39 41 * program, so that the options can be evaluated and the help option doesn't accidentally run your program. */
40 42 class App {
41 43 friend Option;
  44 + friend detail::AppFriend;
42 45 protected:
43 46  
44 47 // This library follows the Google style guide for member names ending in underscores
... ... @@ -1041,5 +1044,23 @@ protected:
1041 1044  
1042 1045 };
1043 1046  
  1047 +namespace detail {
  1048 +/// This class is simply to allow tests access to App's protected functions
  1049 +struct AppFriend {
  1050 +
  1051 + /// Wrap _parse_short
  1052 + static void parse_short(App* app, std::vector<std::string> &args) {
  1053 + return app->_parse_short(args);
  1054 + }
1044 1055  
  1056 + /// Wrap _parse_long
  1057 + static void parse_long(App* app, std::vector<std::string> &args) {
  1058 + return app->_parse_long(args);
  1059 + }
  1060 +
  1061 +
  1062 +};
1045 1063 }
  1064 +
  1065 +}
  1066 +
... ...
tests/AppTest.cpp
... ... @@ -696,3 +696,17 @@ TEST_F(TApp, AllowExtrasOrder) {
696 696 EXPECT_EQ(left_over, left_over_2);
697 697  
698 698 }
  699 +
  700 +// Test horrible error
  701 +TEST_F(TApp, CheckShortFail) {
  702 + args = {"--two"};
  703 +
  704 + EXPECT_THROW(CLI::detail::AppFriend::parse_short(&app, args), CLI::HorribleError);
  705 +}
  706 +
  707 +// Test horrible error
  708 +TEST_F(TApp, CheckLongFail) {
  709 + args = {"-t"};
  710 +
  711 + EXPECT_THROW(CLI::detail::AppFriend::parse_long(&app, args), CLI::HorribleError);
  712 +}
... ...