1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-01 21:23:52 +00:00

Adding test for horrible error

This commit is contained in:
Henry Fredrick Schreiner 2017-03-08 10:28:42 -05:00
parent 3e8502bf43
commit 33f4c5783a
2 changed files with 35 additions and 0 deletions

View File

@ -27,10 +27,12 @@ namespace CLI {
namespace detail {
enum class Classifer {NONE, POSITIONAL_MARK, SHORT, LONG, SUBCOMMAND};
class AppFriend;
}
class App;
typedef std::unique_ptr<App> App_p;
/// Creates a command line program, with very few defaults.
@ -39,6 +41,7 @@ typedef std::unique_ptr<App> App_p;
* program, so that the options can be evaluated and the help option doesn't accidentally run your program. */
class App {
friend Option;
friend detail::AppFriend;
protected:
// This library follows the Google style guide for member names ending in underscores
@ -1041,5 +1044,23 @@ protected:
};
namespace detail {
/// This class is simply to allow tests access to App's protected functions
struct AppFriend {
/// Wrap _parse_short
static void parse_short(App* app, std::vector<std::string> &args) {
return app->_parse_short(args);
}
/// Wrap _parse_long
static void parse_long(App* app, std::vector<std::string> &args) {
return app->_parse_long(args);
}
};
}
}

View File

@ -696,3 +696,17 @@ TEST_F(TApp, AllowExtrasOrder) {
EXPECT_EQ(left_over, left_over_2);
}
// Test horrible error
TEST_F(TApp, CheckShortFail) {
args = {"--two"};
EXPECT_THROW(CLI::detail::AppFriend::parse_short(&app, args), CLI::HorribleError);
}
// Test horrible error
TEST_F(TApp, CheckLongFail) {
args = {"-t"};
EXPECT_THROW(CLI::detail::AppFriend::parse_long(&app, args), CLI::HorribleError);
}