[PATCH] D61234: [CommandLine} Wire-up cl::list::setDefault() so it will work correctly with cl::ResetAllOptionOccurrences() in unittests. Part 2 of 5
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 29 17:07:34 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL359522: [CommandLine} Wire-up cl::list::setDefault() so it will work correctly with cl… (authored by dhinton, committed by ).
Herald added a subscriber: kristina.
Changed prior to commit:
https://reviews.llvm.org/D61234?vs=196991&id=197226#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61234/new/
https://reviews.llvm.org/D61234
Files:
llvm/trunk/include/llvm/Support/CommandLine.h
llvm/trunk/unittests/Support/CommandLineTest.cpp
Index: llvm/trunk/unittests/Support/CommandLineTest.cpp
===================================================================
--- llvm/trunk/unittests/Support/CommandLineTest.cpp
+++ llvm/trunk/unittests/Support/CommandLineTest.cpp
@@ -944,13 +944,21 @@
}
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 @@
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());
}
Index: llvm/trunk/include/llvm/Support/CommandLine.h
===================================================================
--- llvm/trunk/include/llvm/Support/CommandLine.h
+++ llvm/trunk/include/llvm/Support/CommandLine.h
@@ -1425,6 +1425,8 @@
public:
list_storage() = default;
+ void clear() {}
+
bool setLocation(Option &O, StorageClass &L) {
if (Location)
return O.error("cl::location(x) specified more than once!");
@@ -1476,6 +1478,10 @@
reference operator[](size_type pos) { return Storage[pos]; }
const_reference operator[](size_type pos) const { return Storage[pos]; }
+ void clear() {
+ Storage.clear();
+ }
+
iterator erase(const_iterator pos) { return Storage.erase(pos); }
iterator erase(const_iterator first, const_iterator last) {
return Storage.erase(first, last);
@@ -1553,7 +1559,10 @@
void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const override {
}
- void setDefault() override {}
+ void setDefault() override {
+ Positions.clear();
+ list_storage<DataType, StorageClass>::clear();
+ }
void done() {
addArgument();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61234.197226.patch
Type: text/x-patch
Size: 2771 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190430/42b5fbd0/attachment.bin>
More information about the llvm-commits
mailing list