Commit cd98e70c9e943b2609b47bf0e29d07f3e71a331c

Authored by Henry Fredrick Schreiner
1 parent 239d3b1c

Adding one more test

include/CLI/App.hpp
... ... @@ -484,21 +484,13 @@ public:
484 484 }
485 485  
486 486 /// Check to see if a subcommand is part of this command (text version)
487   - App* get_subcommand(std::string subcom) {
488   - for(const App_p &subcomptr : subcommands_)
489   - if(subcomptr->check_name(subcom))
490   - return subcomptr.get();
491   - throw CLI::OptionNotFound(subcom);
492   - }
493   -
494   - /// Check to see if a subcommand is part of this command (text version, const)
495 487 App* get_subcommand(std::string subcom) const {
496 488 for(const App_p &subcomptr : subcommands_)
497 489 if(subcomptr->check_name(subcom))
498 490 return subcomptr.get();
499 491 throw CLI::OptionNotFound(subcom);
500 492 }
501   -
  493 +
502 494 ///@}
503 495 /// @name Extras for subclassing
504 496 ///@{
... ...
tests/SubcommandTest.cpp
... ... @@ -4,6 +4,10 @@ TEST_F(TApp, BasicSubcommands) {
4 4 auto sub1 = app.add_subcommand("sub1");
5 5 auto sub2 = app.add_subcommand("sub2");
6 6  
  7 + EXPECT_EQ(sub1, app.get_subcommand(sub1));
  8 + EXPECT_EQ(sub1, app.get_subcommand("sub1"));
  9 + EXPECT_THROW(app.get_subcommand("sub3"), CLI::OptionNotFound);
  10 +
7 11 run();
8 12 EXPECT_EQ((size_t) 0, app.get_subcommands().size());
9 13  
... ...