aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
authorDon Hinton <hintonda@gmail.com>2019-04-30 00:09:49 +0000
committerDon Hinton <hintonda@gmail.com>2019-04-30 00:09:49 +0000
commitcabf1e22992655e0296f033f63191935954a85fa (patch)
treefb78b32ca1057cfe4d90d7c15c94d11e121dc80a /llvm/unittests/Support/CommandLineTest.cpp
parentb12867230cd84a3cf9d451a8b25f55789cc59bb3 (diff)
downloadllvm-cabf1e22992655e0296f033f63191935954a85fa.zip
llvm-cabf1e22992655e0296f033f63191935954a85fa.tar.gz
llvm-cabf1e22992655e0296f033f63191935954a85fa.tar.bz2
[CommandLine} Wire-up cl::list::setDefault() so it will work correctly with cl::ResetAllOptionOccurrences() in unittests. Part 2 of 5
Summary: With this change, cl::ResetAllOptionOccurrences() clears cl::list just like cl::opt, allowing users to call cl::ParseCommandLineOptions() multiple times without interference from previous calls. Reviewers: rnk Reviewed By: rnk Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61234 llvm-svn: 359522
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index b648600..5ce6541 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -944,13 +944,21 @@ TEST(CommandLineTest, ReadConfigFile) {
}
TEST(CommandLineTest, PositionalEatArgsError) {
+ cl::ResetCommandLineParser();
+
StackOption<std::string, cl::list<std::string>> PosEatArgs(
"positional-eat-args", cl::Positional, cl::desc("<arguments>..."),
cl::ZeroOrMore, cl::PositionalEatsArgs);
+ StackOption<std::string, cl::list<std::string>> PosEatArgs2(
+ "positional-eat-args2", cl::Positional, cl::desc("Some strings"),
+ cl::ZeroOrMore, cl::PositionalEatsArgs);
const char *args[] = {"prog", "-positional-eat-args=XXXX"};
const char *args2[] = {"prog", "-positional-eat-args=XXXX", "-foo"};
const char *args3[] = {"prog", "-positional-eat-args", "-foo"};
+ const char *args4[] = {"prog", "-positional-eat-args",
+ "-foo", "-positional-eat-args2",
+ "-bar", "foo"};
std::string Errs;
raw_string_ostream OS(Errs);
@@ -959,6 +967,12 @@ TEST(CommandLineTest, PositionalEatArgsError) {
EXPECT_FALSE(cl::ParseCommandLineOptions(3, args2, StringRef(), &OS)); OS.flush();
EXPECT_FALSE(Errs.empty()); Errs.clear();
EXPECT_TRUE(cl::ParseCommandLineOptions(3, args3, StringRef(), &OS)); OS.flush();
+ EXPECT_TRUE(Errs.empty()); Errs.clear();
+
+ cl::ResetAllOptionOccurrences();
+ EXPECT_TRUE(cl::ParseCommandLineOptions(6, args4, StringRef(), &OS)); OS.flush();
+ EXPECT_TRUE(PosEatArgs.size() == 1);
+ EXPECT_TRUE(PosEatArgs2.size() == 2);
EXPECT_TRUE(Errs.empty());
}