From: Reid Kleckner Date: Fri, 19 Jul 2013 18:05:13 +0000 (+0000) Subject: Add some flag exclusion tests. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=75b1783b2bf18572e9c286eaaa7f95ee82e7c514;p=oota-llvm.git Add some flag exclusion tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186704 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/unittests/Option/OptionParsingTest.cpp b/unittests/Option/OptionParsingTest.cpp index 30944d9be79..8bfa99b5de4 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 - AL(T.ParseArgs(Args, - Args + (sizeof(Args) / sizeof(Args[0])), - MAI, - MAC)); + OwningPtr 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 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 3d6242f5185..ccb377fc7e5 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; +def Ceq : Joined<["-", "--"], "C=">, Alias, Flags<[OptFlag1]>; def H : Flag<["-"], "H">, Flags<[HelpHidden]>;