Skip to content

Commit

Permalink
[MISC] Question: What is allowed when we have subcommands?
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Feb 15, 2024
1 parent 60447cd commit 8ceaf6a
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions test/unit/detail/format_help_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,40 +628,8 @@ TEST(help_page_printing, copyright)
TEST(parse_test, subcommand_parser)
{
int option_value{};
std::string option_value2{};

char const * argv[]{"./test_parser", "-h"};
sharg::parser top_level_parser{"test_parser", 2, argv, sharg::update_notifications::on, {"sub1", "sub2"}};
sharg::detail::test_accessor::set_terminal_width(top_level_parser, 80);
top_level_parser.info.description.push_back("description");
top_level_parser.add_option(option_value,
sharg::config{.short_id = 'f', .long_id = "foo", .description = "foo bar."});

testing::internal::CaptureStdout();
EXPECT_EXIT(top_level_parser.parse(), ::testing::ExitedWithCode(EXIT_SUCCESS), "");
std::string std_cout = testing::internal::GetCapturedStdout();

std::string expected = "test_parser\n"
"===========\n"
"\n"
"DESCRIPTION\n"
" description\n"
"\n"
"SUBCOMMANDS\n"
" This program must be invoked with one of the following subcommands:\n"
" - sub1\n"
" - sub2\n"
" See the respective help page for further details (e.g. by calling\n"
" test_parser sub1 -h).\n"
"\n"
" The following options below belong to the top-level parser and need to be\n"
" specified before the subcommand key word. Every argument after the\n"
" subcommand key word is passed on to the corresponding sub-parser.\n"
"\nOPTIONS\n"
" -f, --foo (signed 32 bit integer)\n"
" foo bar. Default: 0\n"
"\n"
+ basic_options_str + "\n" + basic_version_str;

EXPECT_EQ(std_cout, expected);
EXPECT_THROW(top_level_parser.add_option(option_value, sharg::config{.long_id = "foo"}), sharg::design_error);
}

0 comments on commit 8ceaf6a

Please sign in to comment.