diff options
| author | Justin Bogner <mail@justinbogner.com> | 2014-07-14 20:53:57 +0000 |
|---|---|---|
| committer | Justin Bogner <mail@justinbogner.com> | 2014-07-14 20:53:57 +0000 |
| commit | 759645ea89e1185868034637172a255ca9cf799c (patch) | |
| tree | 5c37b33c5cb8df8b829b0773fd2b7be9e2397bd1 /llvm/unittests/Support/CommandLineTest.cpp | |
| parent | b8f435ca7035b4ac1113457ef47354d69431306d (diff) | |
| download | llvm-759645ea89e1185868034637172a255ca9cf799c.zip llvm-759645ea89e1185868034637172a255ca9cf799c.tar.gz llvm-759645ea89e1185868034637172a255ca9cf799c.tar.bz2 | |
Support: Fix option handling when using cl::Required with aliasopt
Until now, attempting to create an alias of a required option would
complain if the user supplied the alias, because the required option
didn't have a value. Similarly, if you said the alias was required,
then using the base option would complain that the alias wasn't
supplied. Lastly, if you put required on both, *neither* option would
work.
By changning alias to overload addOccurrence and setting cl::Required
on the original option, we can get this to behave in a more useful
way. I've also added a test and updated a user that was getting this
wrong.
llvm-svn: 212986
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
| -rw-r--r-- | llvm/unittests/Support/CommandLineTest.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index b2d71ab..e4a1b67 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -212,4 +212,23 @@ TEST(CommandLineTest, AliasesWithArguments) { } } +void testAliasRequired(int argc, const char *const *argv) { + StackOption<std::string> Option("option", cl::Required); + cl::alias Alias("o", llvm::cl::aliasopt(Option)); + + cl::ParseCommandLineOptions(argc, argv); + EXPECT_EQ("x", Option); + EXPECT_EQ(1, Option.getNumOccurrences()); + + Alias.removeArgument(); +} + +TEST(CommandLineTest, AliasRequired) { + const char *opts1[] = { "-tool", "-option=x" }; + const char *opts2[] = { "-tool", "-o", "x" }; + testAliasRequired(array_lengthof(opts1), opts1); + testAliasRequired(array_lengthof(opts2), opts2); +} + + } // anonymous namespace |
