Skip to content

Commit

Permalink
Turn the code in the detail_print_help_synopsis test into actual tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzlaine committed Sep 13, 2020
1 parent 12355ca commit a0d9710
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
6 changes: 3 additions & 3 deletions include/boost/program_options_2/parse_command_line.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ namespace boost { namespace program_options_2 {
detail::option<T> argument(std::string_view names)
{
// There's something wrong with the argument names in "names". Either
// it contains whitespace, of it contains at least one name that is
// it contains whitespace, or it contains at least one name that is
// not of the form "-<name>" or "--<name>".
BOOST_ASSERT(detail::valid_nonpositional_names(names));
return {names, detail::action_kind::assign, 1};
Expand Down Expand Up @@ -741,7 +741,7 @@ namespace boost { namespace program_options_2 {
...));
#endif
// There's something wrong with the argument names in "names". Either
// it contains whitespace, of it contains at least one name that is
// it contains whitespace, or it contains at least one name that is
// not of the form "-<name>" or "--<name>".
BOOST_ASSERT(detail::valid_nonpositional_names(names));
// An argument with args=0 and no default is a flag. Use flag()
Expand Down Expand Up @@ -894,7 +894,7 @@ namespace boost { namespace program_options_2 {
/** TODO */
template<option_or_group Option, option_or_group... Options>
detail::option_group<false, Option, Options...>
suboptions(std::string_view name, Option opt, Options... opts)
subcommand_options(std::string_view name, Option opt, Options... opts)
{
return {name, {std::move(opt), std::move(opts)...}};
}
Expand Down
27 changes: 21 additions & 6 deletions test/printing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,33 +423,48 @@ TEST(printing, detail_print_help_synopsis)
{
std::ostringstream os;
po2::detail::print_help_synopsis<boost::text::format::utf8>(
std::cout,
os,
sv(exe),
sv("A program that does things."),
po2::positional<int>("foo"));
// EXPECT_EQ(os.str(), " FOO");
EXPECT_EQ(os.str(), R"(usage: foo/bar [-h] FOO
A program that does things.
)");
}

{
std::ostringstream os;
po2::detail::print_help_synopsis<boost::text::format::utf8>(
std::cout,
os,
sv(exe),
sv("A program that does things."),
po2::positional<std::vector<int>>("foo", 30));
// EXPECT_EQ(os.str(), " FOO");
EXPECT_EQ(os.str(), R"(usage: foo/bar [-h]
FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO
A program that does things.
)");
}

{
std::string const long_exe = std::string("foo") + po2::detail::fs_sep +
"barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr";
std::ostringstream os;
po2::detail::print_help_synopsis<boost::text::format::utf8>(
std::cout,
os,
sv(long_exe),
sv("A program that does things."),
po2::positional<std::vector<int>>("foo", 30));
// EXPECT_EQ(os.str(), " FOO");
EXPECT_EQ(
os.str(), R"(usage: foo/barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr [-h]
FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO
A program that does things.
)");
}
}

Expand Down

0 comments on commit a0d9710

Please sign in to comment.