Options: Add new option kind that consumes remaining arguments
This adds KIND_REMAINING_ARGS, a class of options that consume
all remaining arguments on the command line.
This will be used to support /link in clang-cl, which is used
to forward all remaining arguments to the linker.
It also allows us to remove the hard-coded handling of "--",
allowing clients (clang and lld) to implement that functionality
themselves with this new option class.
Differential Revision: http://llvm-reviews.chandlerc.com/D1387
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188314 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Option/OptionParsingTest.cpp b/unittests/Option/OptionParsingTest.cpp
index 5a76d65..4a7b7b1 100644
--- a/unittests/Option/OptionParsingTest.cpp
+++ b/unittests/Option/OptionParsingTest.cpp
@@ -169,3 +169,30 @@
EXPECT_EQ(AL->getAllArgValues(OPT_INPUT)[0], "-B");
EXPECT_EQ(AL->getAllArgValues(OPT_INPUT)[1], "--");
}
+
+TEST(Option, SlurpEmpty) {
+ TestOptTable T;
+ unsigned MAI, MAC;
+
+ const char *MyArgs[] = { "-A", "-slurp" };
+ OwningPtr<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
+ EXPECT_TRUE(AL->hasArg(OPT_A));
+ EXPECT_TRUE(AL->hasArg(OPT_Slurp));
+ EXPECT_EQ(AL->getAllArgValues(OPT_Slurp).size(), 0);
+}
+
+TEST(Option, Slurp) {
+ TestOptTable T;
+ unsigned MAI, MAC;
+
+ const char *MyArgs[] = { "-A", "-slurp", "-B", "--", "foo" };
+ OwningPtr<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
+ EXPECT_EQ(AL->size(), 2U);
+ EXPECT_TRUE(AL->hasArg(OPT_A));
+ EXPECT_FALSE(AL->hasArg(OPT_B));
+ EXPECT_TRUE(AL->hasArg(OPT_Slurp));
+ EXPECT_EQ(AL->getAllArgValues(OPT_Slurp).size(), 3U);
+ EXPECT_EQ(AL->getAllArgValues(OPT_Slurp)[0], "-B");
+ EXPECT_EQ(AL->getAllArgValues(OPT_Slurp)[1], "--");
+ EXPECT_EQ(AL->getAllArgValues(OPT_Slurp)[2], "foo");
+}
diff --git a/unittests/Option/Opts.td b/unittests/Option/Opts.td
index 986b312..aaed6b2 100644
--- a/unittests/Option/Opts.td
+++ b/unittests/Option/Opts.td
@@ -22,3 +22,5 @@
def J : Flag<["-"], "J">, Alias<B>, AliasArgs<["foo"]>;
def Joo : Flag<["-"], "Joo">, Alias<B>, AliasArgs<["bar"]>;
+
+def Slurp : Option<["-"], "slurp", KIND_REMAINING_ARGS>;