summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-07-18 16:54:13 -0400
committerBrad King <brad.king@kitware.com>2022-07-22 10:32:24 -0400
commitb7c82b26b03349d1201a24acbe198ee1bd00ee3e (patch)
tree6577eb58da3df4768de67e08cdd994ea29bcfca3 /Tests
parent50876f6b9afbf638fcc86ebfa83de7cc17a5a7e1 (diff)
downloadcmake-b7c82b26b03349d1201a24acbe198ee1bd00ee3e.tar.gz
cmArgumentParser: Capture keyword errors in parse results
Since commit f46b2e9142 (cmArgumentParser: Model maybe-missing string with wrapper type, 2022-07-06) we know during parsing whether or not it is an error for a keyword to be missing a value. Record such errors in the parse results structure. Offer clients a helper method to report them. This provides clients with an alternative to manually checking `keywordsMissingValue` and generating their own error message.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CMakeLib/testArgumentParser.cxx18
1 files changed, 16 insertions, 2 deletions
diff --git a/Tests/CMakeLib/testArgumentParser.cxx b/Tests/CMakeLib/testArgumentParser.cxx
index 054cfd5b12..f0ace50e1b 100644
--- a/Tests/CMakeLib/testArgumentParser.cxx
+++ b/Tests/CMakeLib/testArgumentParser.cxx
@@ -3,7 +3,9 @@
#include <initializer_list>
#include <iostream>
+#include <map>
#include <string>
+#include <utility>
#include <vector>
#include <cm/optional>
@@ -69,6 +71,11 @@ bool verifyResult(Result const& result,
static std::vector<cm::string_view> const missing = { "STRING_1"_s,
"LIST_1"_s,
"LIST_4"_s };
+ static std::map<cm::string_view, std::string> const keywordErrors = {
+ { "STRING_1"_s, " missing required value\n" },
+ { "LIST_1"_s, " missing required value\n" },
+ { "LIST_4"_s, " missing required value\n" }
+ };
#define ASSERT_TRUE(x) \
do { \
@@ -78,7 +85,7 @@ bool verifyResult(Result const& result,
} \
} while (false)
- ASSERT_TRUE(result);
+ ASSERT_TRUE(!result);
ASSERT_TRUE(result.Option1);
ASSERT_TRUE(!result.Option2);
@@ -112,6 +119,13 @@ bool verifyResult(Result const& result,
ASSERT_TRUE(unparsedArguments[0] == "bar");
ASSERT_TRUE(keywordsMissingValue == missing);
+ ASSERT_TRUE(result.GetKeywordErrors().size() == keywordErrors.size());
+ for (auto const& ke : result.GetKeywordErrors()) {
+ auto const ki = keywordErrors.find(ke.first);
+ ASSERT_TRUE(ki != keywordErrors.end());
+ ASSERT_TRUE(ke.second == ki->second);
+ }
+
return true;
}
@@ -179,7 +193,7 @@ bool testArgumentParserStaticBool()
std::vector<cm::string_view> keywordsMissingValue;
Result result;
ASSERT_TRUE(parserStatic.Parse(result, args, &unparsedArguments,
- &keywordsMissingValue) == true);
+ &keywordsMissingValue) == false);
return verifyResult(result, unparsedArguments, keywordsMissingValue);
}