llvm.org GIT mirror llvm / 75b1783
Add some flag exclusion tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186704 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 6 years ago
2 changed file(s) with 49 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/ADT/OwningPtr.h"
10 #include "llvm/ADT/STLExtras.h"
1011 #include "llvm/Option/Arg.h"
1112 #include "llvm/Option/ArgList.h"
1213 #include "llvm/Option/Option.h"
2829 #include "Opts.inc"
2930 #undef PREFIX
3031
32 enum OptionFlags {
33 OptFlag1 = (1 << 4),
34 OptFlag2 = (1 << 5),
35 OptFlag3 = (1 << 6)
36 };
37
3138 static const OptTable::Info InfoTable[] = {
3239 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \
3340 HELPTEXT, METAVAR) \
4148 class TestOptTable : public OptTable {
4249 public:
4350 TestOptTable()
44 : OptTable(InfoTable, sizeof(InfoTable) / sizeof(InfoTable[0])) {}
51 : OptTable(InfoTable, array_lengthof(InfoTable)) {}
4552 };
4653 }
4754
5764 "-Gchuu", "2"
5865 };
5966
60 TEST(Support, OptionParsing) {
67 TEST(Option, OptionParsing) {
6168 TestOptTable T;
6269 unsigned MAI, MAC;
63 OwningPtr
64 AL(T.ParseArgs(Args,
65 Args + (sizeof(Args) / sizeof(Args[0])),
66 MAI,
67 MAC));
70 OwningPtr AL(T.ParseArgs(Args, array_endof(Args), MAI, MAC));
6871
6972 // Check they all exist.
7073 EXPECT_TRUE(AL->hasArg(OPT_A));
103106 EXPECT_EQ(StringRef(ASL[0]), "-C");
104107 EXPECT_EQ(StringRef(ASL[1]), "desu");
105108 }
109
110 TEST(Option, ParseWithFlagExclusions) {
111 TestOptTable T;
112 unsigned MAI, MAC;
113 OwningPtr AL;
114
115 // Exclude flag3 to avoid parsing as OPT_SLASH_C.
116 AL.reset(T.ParseArgs(Args, array_endof(Args), MAI, MAC,
117 /*FlagsToInclude=*/0,
118 /*FlagsToExclude=*/OptFlag3));
119 EXPECT_TRUE(AL->hasArg(OPT_A));
120 EXPECT_TRUE(AL->hasArg(OPT_C));
121 EXPECT_FALSE(AL->hasArg(OPT_SLASH_C));
122
123 // Exclude flag1 to avoid parsing as OPT_C.
124 AL.reset(T.ParseArgs(Args, array_endof(Args), MAI, MAC,
125 /*FlagsToInclude=*/0,
126 /*FlagsToExclude=*/OptFlag1));
127 EXPECT_TRUE(AL->hasArg(OPT_B));
128 EXPECT_FALSE(AL->hasArg(OPT_C));
129 EXPECT_TRUE(AL->hasArg(OPT_SLASH_C));
130
131 const char *NewArgs[] = { "/C", "foo", "--C=bar" };
132 AL.reset(T.ParseArgs(NewArgs, array_endof(NewArgs), MAI, MAC));
133 EXPECT_TRUE(AL->hasArg(OPT_SLASH_C));
134 EXPECT_TRUE(AL->hasArg(OPT_C));
135 EXPECT_EQ(AL->getLastArgValue(OPT_SLASH_C), "foo");
136 EXPECT_EQ(AL->getLastArgValue(OPT_C), "bar");
137 }
0 include "llvm/Option/OptParser.td"
11
2 def A : Flag<["-"], "A">, HelpText<"The A option">;
3 def B : Joined<["-"], "B">, HelpText<"The B option">, MetaVarName<"B">;
4 def C : Separate<["-"], "C">, HelpText<"The C option">, MetaVarName<"C">;
2 def OptFlag1 : OptionFlag;
3 def OptFlag2 : OptionFlag;
4 def OptFlag3 : OptionFlag;
5
6 def A : Flag<["-"], "A">, HelpText<"The A option">, Flags<[OptFlag1]>;
7 def B : Joined<["-"], "B">, HelpText<"The B option">, MetaVarName<"B">, Flags<[OptFlag2]>;
8 def C : Separate<["-"], "C">, HelpText<"The C option">, MetaVarName<"C">, Flags<[OptFlag1]>;
9 def SLASH_C : Separate<["/", "-"], "C">, HelpText<"The C option">, MetaVarName<"C">, Flags<[OptFlag3]>;
510 def D : CommaJoined<["-"], "D">, HelpText<"The D option">, MetaVarName<"D">;
6 def E : MultiArg<["-"], "E", 2>;
11 def E : MultiArg<["-"], "E", 2>, Flags<[OptFlag1, OptFlag2]>;
712 def F : JoinedOrSeparate<["-"], "F">, HelpText<"The F option">, MetaVarName<"F">;
813 def G : JoinedAndSeparate<["-"], "G">, HelpText<"The G option">, MetaVarName<"G">;
914
10 def Ceq : Joined<["-", "--"], "C=">, Alias;
15 def Ceq : Joined<["-", "--"], "C=">, Alias, Flags<[OptFlag1]>;
1116
1217 def H : Flag<["-"], "H">, Flags<[HelpHidden]>;