summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-07-26 13:27:37 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-07-26 13:27:44 (GMT)
commit5fc4e121a18d9e403f1541348c2889e9bc153791 (patch)
tree4d65e0235cd279b7bf85417e37c9783901ec098c /Tests
parentd8561df561bba6b361e3b5621ebfc5739e74b516 (diff)
parent2eba10c5ee0e20cee5bbcc43fbb29eee0529e8e9 (diff)
downloadCMake-5fc4e121a18d9e403f1541348c2889e9bc153791.zip
CMake-5fc4e121a18d9e403f1541348c2889e9bc153791.tar.gz
CMake-5fc4e121a18d9e403f1541348c2889e9bc153791.tar.bz2
Merge topic 'command-arg-parser'
2eba10c5ee cmArgumentParser: Drop unused parsedKeywords argument to Parse() 98cf623821 cmCTestHandlerCommand: Capture list of parsed keywords via binding 6ecd741b5f cmFileCommand: Capture list of parsed keywords via binding f7e81802f2 cmArgumentParser: Offer binding for list of parsed keywords f95a5832c7 cmArgumentParser: Drop unused keywordsMissingValue argument to Parse() 9a7efb6813 cmArgumentParser: Offer private binding to cmParseArgumentsCommand Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7508
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CMakeLib/testArgumentParser.cxx47
1 files changed, 30 insertions, 17 deletions
diff --git a/Tests/CMakeLib/testArgumentParser.cxx b/Tests/CMakeLib/testArgumentParser.cxx
index f0ace50..5460356 100644
--- a/Tests/CMakeLib/testArgumentParser.cxx
+++ b/Tests/CMakeLib/testArgumentParser.cxx
@@ -38,6 +38,8 @@ struct Result : public ArgumentParser::ParseResult
std::vector<std::vector<std::string>> Multi2;
cm::optional<std::vector<std::vector<std::string>>> Multi3;
cm::optional<std::vector<std::vector<std::string>>> Multi4;
+
+ std::vector<cm::string_view> ParsedKeywords;
};
std::initializer_list<cm::string_view> const args = {
@@ -63,14 +65,27 @@ std::initializer_list<cm::string_view> const args = {
};
bool verifyResult(Result const& result,
- std::vector<std::string> const& unparsedArguments,
- std::vector<cm::string_view> const& keywordsMissingValue)
+ std::vector<std::string> const& unparsedArguments)
{
static std::vector<std::string> const foobar = { "foo", "bar" };
static std::vector<std::string> const barfoo = { "bar", "foo" };
- static std::vector<cm::string_view> const missing = { "STRING_1"_s,
- "LIST_1"_s,
- "LIST_4"_s };
+ static std::vector<cm::string_view> const parsedKeywords = {
+ /* clang-format off */
+ "OPTION_1",
+ "STRING_1",
+ "STRING_2",
+ "STRING_4",
+ "LIST_1",
+ "LIST_2",
+ "LIST_3",
+ "LIST_3",
+ "LIST_4",
+ "LIST_6",
+ "MULTI_2",
+ "MULTI_3",
+ "MULTI_3",
+ /* clang-format on */
+ };
static std::map<cm::string_view, std::string> const keywordErrors = {
{ "STRING_1"_s, " missing required value\n" },
{ "LIST_1"_s, " missing required value\n" },
@@ -117,7 +132,8 @@ bool verifyResult(Result const& result,
ASSERT_TRUE(unparsedArguments.size() == 1);
ASSERT_TRUE(unparsedArguments[0] == "bar");
- ASSERT_TRUE(keywordsMissingValue == missing);
+
+ ASSERT_TRUE(result.ParsedKeywords == parsedKeywords);
ASSERT_TRUE(result.GetKeywordErrors().size() == keywordErrors.size());
for (auto const& ke : result.GetKeywordErrors()) {
@@ -133,7 +149,6 @@ bool testArgumentParserDynamic()
{
Result result;
std::vector<std::string> unparsedArguments;
- std::vector<cm::string_view> keywordsMissingValue;
static_cast<ArgumentParser::ParseResult&>(result) =
cmArgumentParser<void>{}
@@ -153,9 +168,10 @@ bool testArgumentParserDynamic()
.Bind("MULTI_2"_s, result.Multi2)
.Bind("MULTI_3"_s, result.Multi3)
.Bind("MULTI_4"_s, result.Multi4)
- .Parse(args, &unparsedArguments, &keywordsMissingValue);
+ .BindParsedKeywords(result.ParsedKeywords)
+ .Parse(args, &unparsedArguments);
- return verifyResult(result, unparsedArguments, keywordsMissingValue);
+ return verifyResult(result, unparsedArguments);
}
static auto const parserStatic = //
@@ -176,25 +192,22 @@ static auto const parserStatic = //
.Bind("MULTI_2"_s, &Result::Multi2)
.Bind("MULTI_3"_s, &Result::Multi3)
.Bind("MULTI_4"_s, &Result::Multi4)
+ .BindParsedKeywords(&Result::ParsedKeywords)
/* keep semicolon on own line */;
bool testArgumentParserStatic()
{
std::vector<std::string> unparsedArguments;
- std::vector<cm::string_view> keywordsMissingValue;
- Result const result =
- parserStatic.Parse(args, &unparsedArguments, &keywordsMissingValue);
- return verifyResult(result, unparsedArguments, keywordsMissingValue);
+ Result const result = parserStatic.Parse(args, &unparsedArguments);
+ return verifyResult(result, unparsedArguments);
}
bool testArgumentParserStaticBool()
{
std::vector<std::string> unparsedArguments;
- std::vector<cm::string_view> keywordsMissingValue;
Result result;
- ASSERT_TRUE(parserStatic.Parse(result, args, &unparsedArguments,
- &keywordsMissingValue) == false);
- return verifyResult(result, unparsedArguments, keywordsMissingValue);
+ ASSERT_TRUE(parserStatic.Parse(result, args, &unparsedArguments) == false);
+ return verifyResult(result, unparsedArguments);
}
} // namespace