aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index b6fc699..a6b26b3 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -1793,4 +1793,49 @@ static cl::bits<Enum> ExampleBits(
clEnumValN(Val1, "bits-val1", "The Val1 value"),
clEnumValN(Val1, "bits-val2", "The Val2 value")));
+TEST(CommandLineTest, ConsumeAfterOnePositional) {
+ cl::ResetCommandLineParser();
+
+ // input [args]
+ StackOption<std::string, cl::opt<std::string>> Input(cl::Positional,
+ cl::Required);
+ StackOption<std::string, cl::list<std::string>> ExtraArgs(cl::ConsumeAfter);
+
+ const char *Args[] = {"prog", "input", "arg1", "arg2"};
+
+ std::string Errs;
+ raw_string_ostream OS(Errs);
+ EXPECT_TRUE(cl::ParseCommandLineOptions(4, Args, StringRef(), &OS));
+ OS.flush();
+ EXPECT_EQ("input", Input);
+ EXPECT_TRUE(ExtraArgs.size() == 2);
+ EXPECT_TRUE(ExtraArgs[0] == "arg1");
+ EXPECT_TRUE(ExtraArgs[1] == "arg2");
+ EXPECT_TRUE(Errs.empty());
+}
+
+TEST(CommandLineTest, ConsumeAfterTwoPositionals) {
+ cl::ResetCommandLineParser();
+
+ // input1 input2 [args]
+ StackOption<std::string, cl::opt<std::string>> Input1(cl::Positional,
+ cl::Required);
+ StackOption<std::string, cl::opt<std::string>> Input2(cl::Positional,
+ cl::Required);
+ StackOption<std::string, cl::list<std::string>> ExtraArgs(cl::ConsumeAfter);
+
+ const char *Args[] = {"prog", "input1", "input2", "arg1", "arg2"};
+
+ std::string Errs;
+ raw_string_ostream OS(Errs);
+ EXPECT_TRUE(cl::ParseCommandLineOptions(5, Args, StringRef(), &OS));
+ OS.flush();
+ EXPECT_EQ("input1", Input1);
+ EXPECT_EQ("input2", Input2);
+ EXPECT_TRUE(ExtraArgs.size() == 2);
+ EXPECT_TRUE(ExtraArgs[0] == "arg1");
+ EXPECT_TRUE(ExtraArgs[1] == "arg2");
+ EXPECT_TRUE(Errs.empty());
+}
+
} // anonymous namespace