Skip to content

Commit

Permalink
Implemented testing of how valued command line options are parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmux committed May 11, 2023
1 parent f33626c commit 64dc082
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion test/command_line/arguments.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ TEST_CASE("parse command line argument choice", "[command_line::parseArguments]"
REQUIRE(resultC == std::nullopt);
}

TEST_CASE("parse command line argument flag", "[command_line::parseArguments]")
TEST_CASE("parse command line argument simple flag", "[command_line::parseArguments]")
{
constexpr static auto programOptions
{
Expand Down Expand Up @@ -195,3 +195,34 @@ TEST_CASE("parse command line argument flag", "[command_line::parseArguments]")
REQUIRE(version.name() == "--version"sv);
REQUIRE(!version.value().has_value());
}

TEST_CASE("parse command line argument flags", "[command_line::parseArguments]")
{
constexpr static auto programOptions
{
options
(
option_t{optionFlagPair_t{"-h"sv, "--help"sv}, "Display this help message and exit"sv},
option_t{optionFlagPair_t{"-v"sv, "--verbosity"sv}, "Set the log output verbosity"sv}
.takesParameter(optionValueType_t::unsignedInt).valueRange(0U, 63U),
option_t{optionValue_t{}, "Working directory"sv}.valueType(optionValueType_t::path),
option_t{"--option", "Operation-specific options"sv}.takesParameter().repeatable()
)
};

// Check that valued options work as intended
constexpr static auto argsValues
{
substrate::make_array<const char *>
({
"program",
"-v", "10",
"--option=A",
"/some/path",
"--option", "B",
nullptr,
})
};
const auto resultValues{parseArguments(argsValues.size(), argsValues.data(), programOptions)};
const auto &args{checkResult(resultValues, 4U)};
}

0 comments on commit 64dc082

Please sign in to comment.