From 33f4c5783a42d0c84bc992a887ca311a80a70de2 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Wed, 8 Mar 2017 10:28:42 -0500 Subject: [PATCH] Adding test for horrible error --- include/CLI/App.hpp | 21 +++++++++++++++++++++ tests/AppTest.cpp | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 394d21ef..6bad4201 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -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_p; /// Creates a command line program, with very few defaults. @@ -39,6 +41,7 @@ typedef std::unique_ptr 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 &args) { + return app->_parse_short(args); + } + + /// Wrap _parse_long + static void parse_long(App* app, std::vector &args) { + return app->_parse_long(args); + } + + +}; +} } + diff --git a/tests/AppTest.cpp b/tests/AppTest.cpp index a7017215..47b1198e 100644 --- a/tests/AppTest.cpp +++ b/tests/AppTest.cpp @@ -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); +}