Skip to content

Commit

Permalink
Added testing for various kinds of invalid option arrangements
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmux committed May 12, 2023
1 parent 95199e8 commit b613881
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/command_line/arguments.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,75 @@ TEST_CASE("parse command line argument flags", "[command_line::parseArguments]")
const auto resultBad{parseArguments(argsBad.size(), argsBad.data(), programOptions)};
REQUIRE(resultBad == std::nullopt);
}

TEST_CASE("parse bad command line argument flags", "[command_line::parseArguments]")
{
console = {stdout, stderr};
constexpr static auto choiceAOptions{options(option_t{"--test"sv, "Run action in test mode"sv})};

constexpr static auto actions
{
optionAlternations
({
{
"choiceA"sv,
"First action choice"sv,
choiceAOptions,
},
{
"choiceB"sv,
"Second action choice"sv,
},
})
};

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{"--option", "Operation-specific options"sv}.takesParameter().repeatable(),
optionSet_t{actions}
)
};

constexpr static auto argsInvalidA
{
substrate::make_array<const char *>
({
"program",
"--test=value",
nullptr,
})
};
const auto resultInvalidA{parseArguments(argsInvalidA.size(), argsInvalidA.data(), programOptions)};
REQUIRE(resultInvalidA == std::nullopt);

constexpr static auto argsInvalidB
{
substrate::make_array<const char *>
({
"program",
"--test=",
"--option=A",
nullptr,
})
};
const auto resultInvalidB{parseArguments(argsInvalidB.size(), argsInvalidB.data(), programOptions)};
REQUIRE(resultInvalidB == std::nullopt);

constexpr static auto argsInvalidC
{
substrate::make_array<const char *>
({
"program",
"choiceA",
"--param",
nullptr,
})
};
const auto resultInvalidC{parseArguments(argsInvalidC.size(), argsInvalidC.data(), programOptions)};
REQUIRE(resultInvalidC == std::nullopt);
}

0 comments on commit b613881

Please sign in to comment.