From 8ceaf6a515022d4749289ff0a352c679e6612493 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Thu, 15 Feb 2024 13:11:03 +0100 Subject: [PATCH] [MISC] Question: What is allowed when we have subcommands? --- test/unit/detail/format_help_test.cpp | 34 +-------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/test/unit/detail/format_help_test.cpp b/test/unit/detail/format_help_test.cpp index fd822461..c244eaae 100644 --- a/test/unit/detail/format_help_test.cpp +++ b/test/unit/detail/format_help_test.cpp @@ -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); }