diff options
author | Reid Kleckner <reid@kleckner.net> | 2013-07-19 18:05:13 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2013-07-19 18:05:13 +0000 |
commit | 75b1783b2bf18572e9c286eaaa7f95ee82e7c514 (patch) | |
tree | 87389cd8b51307695ba59bab8b829b641447673d /unittests | |
parent | a2549d382789fa33b5541708b2e4cf39e8bf56c9 (diff) | |
download | external_llvm-75b1783b2bf18572e9c286eaaa7f95ee82e7c514.zip external_llvm-75b1783b2bf18572e9c286eaaa7f95ee82e7c514.tar.gz external_llvm-75b1783b2bf18572e9c286eaaa7f95ee82e7c514.tar.bz2 |
Add some flag exclusion tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186704 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Option/OptionParsingTest.cpp | 46 | ||||
-rw-r--r-- | unittests/Option/Opts.td | 15 |
2 files changed, 49 insertions, 12 deletions
diff --git a/unittests/Option/OptionParsingTest.cpp b/unittests/Option/OptionParsingTest.cpp index 30944d9..8bfa99b 100644 --- a/unittests/Option/OptionParsingTest.cpp +++ b/unittests/Option/OptionParsingTest.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/Option.h" @@ -29,6 +30,12 @@ enum ID { #include "Opts.inc" #undef PREFIX +enum OptionFlags { + OptFlag1 = (1 << 4), + OptFlag2 = (1 << 5), + OptFlag3 = (1 << 6) +}; + static const OptTable::Info InfoTable[] = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \ HELPTEXT, METAVAR) \ @@ -42,7 +49,7 @@ namespace { class TestOptTable : public OptTable { public: TestOptTable() - : OptTable(InfoTable, sizeof(InfoTable) / sizeof(InfoTable[0])) {} + : OptTable(InfoTable, array_lengthof(InfoTable)) {} }; } @@ -58,14 +65,10 @@ const char *Args[] = { "-Gchuu", "2" }; -TEST(Support, OptionParsing) { +TEST(Option, OptionParsing) { TestOptTable T; unsigned MAI, MAC; - OwningPtr<InputArgList> - AL(T.ParseArgs(Args, - Args + (sizeof(Args) / sizeof(Args[0])), - MAI, - MAC)); + OwningPtr<InputArgList> AL(T.ParseArgs(Args, array_endof(Args), MAI, MAC)); // Check they all exist. EXPECT_TRUE(AL->hasArg(OPT_A)); @@ -104,3 +107,32 @@ TEST(Support, OptionParsing) { EXPECT_EQ(StringRef(ASL[0]), "-C"); EXPECT_EQ(StringRef(ASL[1]), "desu"); } + +TEST(Option, ParseWithFlagExclusions) { + TestOptTable T; + unsigned MAI, MAC; + OwningPtr<InputArgList> AL; + + // Exclude flag3 to avoid parsing as OPT_SLASH_C. + AL.reset(T.ParseArgs(Args, array_endof(Args), MAI, MAC, + /*FlagsToInclude=*/0, + /*FlagsToExclude=*/OptFlag3)); + EXPECT_TRUE(AL->hasArg(OPT_A)); + EXPECT_TRUE(AL->hasArg(OPT_C)); + EXPECT_FALSE(AL->hasArg(OPT_SLASH_C)); + + // Exclude flag1 to avoid parsing as OPT_C. + AL.reset(T.ParseArgs(Args, array_endof(Args), MAI, MAC, + /*FlagsToInclude=*/0, + /*FlagsToExclude=*/OptFlag1)); + EXPECT_TRUE(AL->hasArg(OPT_B)); + EXPECT_FALSE(AL->hasArg(OPT_C)); + EXPECT_TRUE(AL->hasArg(OPT_SLASH_C)); + + const char *NewArgs[] = { "/C", "foo", "--C=bar" }; + AL.reset(T.ParseArgs(NewArgs, array_endof(NewArgs), MAI, MAC)); + EXPECT_TRUE(AL->hasArg(OPT_SLASH_C)); + EXPECT_TRUE(AL->hasArg(OPT_C)); + EXPECT_EQ(AL->getLastArgValue(OPT_SLASH_C), "foo"); + EXPECT_EQ(AL->getLastArgValue(OPT_C), "bar"); +} diff --git a/unittests/Option/Opts.td b/unittests/Option/Opts.td index 3d6242f..ccb377f 100644 --- a/unittests/Option/Opts.td +++ b/unittests/Option/Opts.td @@ -1,13 +1,18 @@ include "llvm/Option/OptParser.td" -def A : Flag<["-"], "A">, HelpText<"The A option">; -def B : Joined<["-"], "B">, HelpText<"The B option">, MetaVarName<"B">; -def C : Separate<["-"], "C">, HelpText<"The C option">, MetaVarName<"C">; +def OptFlag1 : OptionFlag; +def OptFlag2 : OptionFlag; +def OptFlag3 : OptionFlag; + +def A : Flag<["-"], "A">, HelpText<"The A option">, Flags<[OptFlag1]>; +def B : Joined<["-"], "B">, HelpText<"The B option">, MetaVarName<"B">, Flags<[OptFlag2]>; +def C : Separate<["-"], "C">, HelpText<"The C option">, MetaVarName<"C">, Flags<[OptFlag1]>; +def SLASH_C : Separate<["/", "-"], "C">, HelpText<"The C option">, MetaVarName<"C">, Flags<[OptFlag3]>; def D : CommaJoined<["-"], "D">, HelpText<"The D option">, MetaVarName<"D">; -def E : MultiArg<["-"], "E", 2>; +def E : MultiArg<["-"], "E", 2>, Flags<[OptFlag1, OptFlag2]>; def F : JoinedOrSeparate<["-"], "F">, HelpText<"The F option">, MetaVarName<"F">; def G : JoinedAndSeparate<["-"], "G">, HelpText<"The G option">, MetaVarName<"G">; -def Ceq : Joined<["-", "--"], "C=">, Alias<C>; +def Ceq : Joined<["-", "--"], "C=">, Alias<C>, Flags<[OptFlag1]>; def H : Flag<["-"], "H">, Flags<[HelpHidden]>; |