llvm.org GIT mirror llvm / eb132e0
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359522 91177308-0d34-0410-b5e6-96231b3b80d8 Don Hinton 1 year, 6 months ago
2 changed file(s) with 24 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
14241424 public:
14251425 list_storage() = default;
14261426
1427 void clear() {}
1428
14271429 bool setLocation(Option &O, StorageClass &L) {
14281430 if (Location)
14291431 return O.error("cl::location(x) specified more than once!");
14741476
14751477 reference operator[](size_type pos) { return Storage[pos]; }
14761478 const_reference operator[](size_type pos) const { return Storage[pos]; }
1479
1480 void clear() {
1481 Storage.clear();
1482 }
14771483
14781484 iterator erase(const_iterator pos) { return Storage.erase(pos); }
14791485 iterator erase(const_iterator first, const_iterator last) {
15521558 void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const override {
15531559 }
15541560
1555 void setDefault() override {}
1561 void setDefault() override {
1562 Positions.clear();
1563 list_storage::clear();
1564 }
15561565
15571566 void done() {
15581567 addArgument();
943943 }
944944
945945 TEST(CommandLineTest, PositionalEatArgsError) {
946 cl::ResetCommandLineParser();
947
946948 StackOption> PosEatArgs(
947949 "positional-eat-args", cl::Positional, cl::desc("..."),
948950 cl::ZeroOrMore, cl::PositionalEatsArgs);
951 StackOption> PosEatArgs2(
952 "positional-eat-args2", cl::Positional, cl::desc("Some strings"),
953 cl::ZeroOrMore, cl::PositionalEatsArgs);
949954
950955 const char *args[] = {"prog", "-positional-eat-args=XXXX"};
951956 const char *args2[] = {"prog", "-positional-eat-args=XXXX", "-foo"};
952957 const char *args3[] = {"prog", "-positional-eat-args", "-foo"};
958 const char *args4[] = {"prog", "-positional-eat-args",
959 "-foo", "-positional-eat-args2",
960 "-bar", "foo"};
953961
954962 std::string Errs;
955963 raw_string_ostream OS(Errs);
958966 EXPECT_FALSE(cl::ParseCommandLineOptions(3, args2, StringRef(), &OS)); OS.flush();
959967 EXPECT_FALSE(Errs.empty()); Errs.clear();
960968 EXPECT_TRUE(cl::ParseCommandLineOptions(3, args3, StringRef(), &OS)); OS.flush();
969 EXPECT_TRUE(Errs.empty()); Errs.clear();
970
971 cl::ResetAllOptionOccurrences();
972 EXPECT_TRUE(cl::ParseCommandLineOptions(6, args4, StringRef(), &OS)); OS.flush();
973 EXPECT_TRUE(PosEatArgs.size() == 1);
974 EXPECT_TRUE(PosEatArgs2.size() == 2);
961975 EXPECT_TRUE(Errs.empty());
962976 }
963977