From cd98e70c9e943b2609b47bf0e29d07f3e71a331c Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Sun, 23 Apr 2017 14:06:58 -0400 Subject: [PATCH] Adding one more test --- include/CLI/App.hpp | 10 +--------- tests/SubcommandTest.cpp | 4 ++++ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 622b3f26..109923f1 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -484,21 +484,13 @@ public: } /// Check to see if a subcommand is part of this command (text version) - App* get_subcommand(std::string subcom) { - for(const App_p &subcomptr : subcommands_) - if(subcomptr->check_name(subcom)) - return subcomptr.get(); - throw CLI::OptionNotFound(subcom); - } - - /// Check to see if a subcommand is part of this command (text version, const) App* get_subcommand(std::string subcom) const { for(const App_p &subcomptr : subcommands_) if(subcomptr->check_name(subcom)) return subcomptr.get(); throw CLI::OptionNotFound(subcom); } - + ///@} /// @name Extras for subclassing ///@{ diff --git a/tests/SubcommandTest.cpp b/tests/SubcommandTest.cpp index 3e77e8c8..f53721eb 100644 --- a/tests/SubcommandTest.cpp +++ b/tests/SubcommandTest.cpp @@ -4,6 +4,10 @@ TEST_F(TApp, BasicSubcommands) { auto sub1 = app.add_subcommand("sub1"); auto sub2 = app.add_subcommand("sub2"); + EXPECT_EQ(sub1, app.get_subcommand(sub1)); + EXPECT_EQ(sub1, app.get_subcommand("sub1")); + EXPECT_THROW(app.get_subcommand("sub3"), CLI::OptionNotFound); + run(); EXPECT_EQ((size_t) 0, app.get_subcommands().size());