[ELF] Make some InputSection/InputFile member functions const. NFC
[llvm-project.git] / llvm / unittests / Option / OptionParsingTest.cpp
blob804a8016414dbce424645d0143b84a87879a50f1
1 //===- unittest/Support/OptionParsingTest.cpp - OptTable tests ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/STLExtras.h"
10 #include "llvm/Option/Arg.h"
11 #include "llvm/Option/ArgList.h"
12 #include "llvm/Option/Option.h"
13 #include "gtest/gtest.h"
15 using namespace llvm;
16 using namespace llvm::opt;
18 #if defined(__clang__)
19 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
20 #endif
22 enum ID {
23 OPT_INVALID = 0, // This is not an option ID.
24 #define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
25 #include "Opts.inc"
26 LastOption
27 #undef OPTION
30 #define PREFIX(NAME, VALUE) \
31 static constexpr StringLiteral NAME##_init[] = VALUE; \
32 static constexpr ArrayRef<StringLiteral> NAME(NAME##_init, \
33 std::size(NAME##_init) - 1);
34 #include "Opts.inc"
35 #undef PREFIX
37 static constexpr const StringLiteral PrefixTable_init[] =
38 #define PREFIX_UNION(VALUES) VALUES
39 #include "Opts.inc"
40 #undef PREFIX_UNION
42 static constexpr const ArrayRef<StringLiteral>
43 PrefixTable(PrefixTable_init, std::size(PrefixTable_init) - 1);
45 enum OptionFlags {
46 OptFlag1 = (1 << 4),
47 OptFlag2 = (1 << 5),
48 OptFlag3 = (1 << 6)
51 enum OptionVisibility {
52 SubtoolVis = (1 << 2),
55 static constexpr OptTable::Info InfoTable[] = {
56 #define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
57 #include "Opts.inc"
58 #undef OPTION
61 namespace {
62 class TestOptTable : public GenericOptTable {
63 public:
64 TestOptTable(bool IgnoreCase = false)
65 : GenericOptTable(InfoTable, IgnoreCase) {}
68 class TestPrecomputedOptTable : public PrecomputedOptTable {
69 public:
70 TestPrecomputedOptTable(bool IgnoreCase = false)
71 : PrecomputedOptTable(InfoTable, PrefixTable, IgnoreCase) {}
75 const char *Args[] = {
76 "-A",
77 "-Bhi",
78 "--C=desu",
79 "-C", "bye",
80 "-D,adena",
81 "-E", "apple", "bloom",
82 "-Fblarg",
83 "-F", "42",
84 "-Gchuu", "2"
87 // Test fixture
88 template <typename T> class OptTableTest : public ::testing::Test {};
90 template <typename T> class DISABLED_OptTableTest : public ::testing::Test {};
92 // Test both precomputed and computed OptTables with the same suite of tests.
93 using OptTableTestTypes =
94 ::testing::Types<TestOptTable, TestPrecomputedOptTable>;
96 TYPED_TEST_SUITE(OptTableTest, OptTableTestTypes, );
97 TYPED_TEST_SUITE(DISABLED_OptTableTest, OptTableTestTypes, );
99 TYPED_TEST(OptTableTest, OptionParsing) {
100 TypeParam T;
101 unsigned MAI, MAC;
102 InputArgList AL = T.ParseArgs(Args, MAI, MAC);
104 // Check they all exist.
105 EXPECT_TRUE(AL.hasArg(OPT_A));
106 EXPECT_TRUE(AL.hasArg(OPT_B));
107 EXPECT_TRUE(AL.hasArg(OPT_C));
108 EXPECT_TRUE(AL.hasArg(OPT_D));
109 EXPECT_TRUE(AL.hasArg(OPT_E));
110 EXPECT_TRUE(AL.hasArg(OPT_F));
111 EXPECT_TRUE(AL.hasArg(OPT_G));
113 // Check the values.
114 EXPECT_EQ("hi", AL.getLastArgValue(OPT_B));
115 EXPECT_EQ("bye", AL.getLastArgValue(OPT_C));
116 EXPECT_EQ("adena", AL.getLastArgValue(OPT_D));
117 std::vector<std::string> Es = AL.getAllArgValues(OPT_E);
118 EXPECT_EQ("apple", Es[0]);
119 EXPECT_EQ("bloom", Es[1]);
120 EXPECT_EQ("42", AL.getLastArgValue(OPT_F));
121 std::vector<std::string> Gs = AL.getAllArgValues(OPT_G);
122 EXPECT_EQ("chuu", Gs[0]);
123 EXPECT_EQ("2", Gs[1]);
125 // Check the help text.
126 std::string Help;
127 raw_string_ostream RSO(Help);
128 T.printHelp(RSO, "test", "title!");
129 EXPECT_NE(std::string::npos, Help.find("-A"));
131 // Check usage line.
132 T.printHelp(RSO, "name [options] file...", "title!");
133 EXPECT_NE(std::string::npos, Help.find("USAGE: name [options] file...\n"));
135 // Test aliases.
136 auto Cs = AL.filtered(OPT_C);
137 ASSERT_NE(Cs.begin(), Cs.end());
138 EXPECT_EQ("desu", StringRef((*Cs.begin())->getValue()));
139 ArgStringList ASL;
140 (*Cs.begin())->render(AL, ASL);
141 ASSERT_EQ(2u, ASL.size());
142 EXPECT_EQ("-C", StringRef(ASL[0]));
143 EXPECT_EQ("desu", StringRef(ASL[1]));
146 TYPED_TEST(OptTableTest, ParseWithFlagExclusions) {
147 TypeParam T;
148 unsigned MAI, MAC;
150 // Exclude flag3 to avoid parsing as OPT_SLASH_C.
151 InputArgList AL = T.ParseArgs(Args, MAI, MAC,
152 /*FlagsToInclude=*/0,
153 /*FlagsToExclude=*/OptFlag3);
154 EXPECT_TRUE(AL.hasArg(OPT_A));
155 EXPECT_TRUE(AL.hasArg(OPT_C));
156 EXPECT_FALSE(AL.hasArg(OPT_SLASH_C));
158 // Exclude flag1 to avoid parsing as OPT_C.
159 AL = T.ParseArgs(Args, MAI, MAC,
160 /*FlagsToInclude=*/0,
161 /*FlagsToExclude=*/OptFlag1);
162 EXPECT_TRUE(AL.hasArg(OPT_B));
163 EXPECT_FALSE(AL.hasArg(OPT_C));
164 EXPECT_TRUE(AL.hasArg(OPT_SLASH_C));
166 const char *NewArgs[] = { "/C", "foo", "--C=bar" };
167 AL = T.ParseArgs(NewArgs, MAI, MAC);
168 EXPECT_TRUE(AL.hasArg(OPT_SLASH_C));
169 EXPECT_TRUE(AL.hasArg(OPT_C));
170 EXPECT_EQ("foo", AL.getLastArgValue(OPT_SLASH_C));
171 EXPECT_EQ("bar", AL.getLastArgValue(OPT_C));
174 TYPED_TEST(OptTableTest, ParseWithVisibility) {
175 TypeParam T;
176 unsigned MAI, MAC;
178 const char *STArgs[] = {"-A", "-Q", "-R"};
180 // With no visibility specified, we find all of the arguments.
181 InputArgList AL = T.ParseArgs(STArgs, MAI, MAC);
182 EXPECT_TRUE(AL.hasArg(OPT_A));
183 EXPECT_TRUE(AL.hasArg(OPT_Q));
184 EXPECT_TRUE(AL.hasArg(OPT_R));
186 // Default visibility omits SubtoolVis.
187 AL = T.ParseArgs(STArgs, MAI, MAC, Visibility(DefaultVis));
188 EXPECT_TRUE(AL.hasArg(OPT_A));
189 EXPECT_FALSE(AL.hasArg(OPT_Q));
190 EXPECT_TRUE(AL.hasArg(OPT_R));
192 // ~SubtoolVis still finds arguments that are visible in Default.
193 AL = T.ParseArgs(STArgs, MAI, MAC, Visibility(~SubtoolVis));
194 EXPECT_TRUE(AL.hasArg(OPT_A));
195 EXPECT_FALSE(AL.hasArg(OPT_Q));
196 EXPECT_TRUE(AL.hasArg(OPT_R));
198 // Only SubtoolVis.
199 AL = T.ParseArgs(STArgs, MAI, MAC, Visibility(SubtoolVis));
200 EXPECT_FALSE(AL.hasArg(OPT_A));
201 EXPECT_TRUE(AL.hasArg(OPT_Q));
202 EXPECT_TRUE(AL.hasArg(OPT_R));
204 // Both Default and SubtoolVis are found.
205 AL = T.ParseArgs(STArgs, MAI, MAC, Visibility(DefaultVis | SubtoolVis));
206 EXPECT_TRUE(AL.hasArg(OPT_A));
207 EXPECT_TRUE(AL.hasArg(OPT_Q));
208 EXPECT_TRUE(AL.hasArg(OPT_R));
211 TYPED_TEST(OptTableTest, ParseAliasInGroup) {
212 TypeParam T;
213 unsigned MAI, MAC;
215 const char *MyArgs[] = { "-I" };
216 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
217 EXPECT_TRUE(AL.hasArg(OPT_H));
220 TYPED_TEST(OptTableTest, AliasArgs) {
221 TypeParam T;
222 unsigned MAI, MAC;
224 const char *MyArgs[] = { "-J", "-Joo" };
225 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
226 EXPECT_TRUE(AL.hasArg(OPT_B));
227 EXPECT_EQ("foo", AL.getAllArgValues(OPT_B)[0]);
228 EXPECT_EQ("bar", AL.getAllArgValues(OPT_B)[1]);
231 TYPED_TEST(OptTableTest, IgnoreCase) {
232 TypeParam T(true);
233 unsigned MAI, MAC;
235 const char *MyArgs[] = { "-a", "-joo" };
236 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
237 EXPECT_TRUE(AL.hasArg(OPT_A));
238 EXPECT_TRUE(AL.hasArg(OPT_B));
241 #if defined(__clang__)
242 // Disable the warning that triggers on exactly what is being tested.
243 #pragma clang diagnostic push
244 #pragma clang diagnostic ignored "-Wself-move"
245 #endif
247 TYPED_TEST(OptTableTest, InputArgListSelfAssign) {
248 TypeParam T;
249 unsigned MAI, MAC;
250 InputArgList AL = T.ParseArgs(Args, MAI, MAC,
251 /*FlagsToInclude=*/0,
252 /*FlagsToExclude=*/OptFlag3);
253 EXPECT_TRUE(AL.hasArg(OPT_A));
254 EXPECT_TRUE(AL.hasArg(OPT_C));
255 EXPECT_FALSE(AL.hasArg(OPT_SLASH_C));
257 AL = std::move(AL);
259 EXPECT_TRUE(AL.hasArg(OPT_A));
260 EXPECT_TRUE(AL.hasArg(OPT_C));
261 EXPECT_FALSE(AL.hasArg(OPT_SLASH_C));
264 #if defined(__clang__)
265 #pragma clang diagnostic pop
266 #endif
268 TYPED_TEST(OptTableTest, DoNotIgnoreCase) {
269 TypeParam T;
270 unsigned MAI, MAC;
272 const char *MyArgs[] = { "-a", "-joo" };
273 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
274 EXPECT_FALSE(AL.hasArg(OPT_A));
275 EXPECT_FALSE(AL.hasArg(OPT_B));
278 TYPED_TEST(OptTableTest, SlurpEmpty) {
279 TypeParam T;
280 unsigned MAI, MAC;
282 const char *MyArgs[] = { "-A", "-slurp" };
283 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
284 EXPECT_TRUE(AL.hasArg(OPT_A));
285 EXPECT_TRUE(AL.hasArg(OPT_Slurp));
286 EXPECT_EQ(0U, AL.getAllArgValues(OPT_Slurp).size());
289 TYPED_TEST(OptTableTest, Slurp) {
290 TypeParam T;
291 unsigned MAI, MAC;
293 const char *MyArgs[] = { "-A", "-slurp", "-B", "--", "foo" };
294 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
295 EXPECT_EQ(AL.size(), 2U);
296 EXPECT_TRUE(AL.hasArg(OPT_A));
297 EXPECT_FALSE(AL.hasArg(OPT_B));
298 EXPECT_TRUE(AL.hasArg(OPT_Slurp));
299 EXPECT_EQ(3U, AL.getAllArgValues(OPT_Slurp).size());
300 EXPECT_EQ("-B", AL.getAllArgValues(OPT_Slurp)[0]);
301 EXPECT_EQ("--", AL.getAllArgValues(OPT_Slurp)[1]);
302 EXPECT_EQ("foo", AL.getAllArgValues(OPT_Slurp)[2]);
305 TYPED_TEST(OptTableTest, SlurpJoinedEmpty) {
306 TypeParam T;
307 unsigned MAI, MAC;
309 const char *MyArgs[] = { "-A", "-slurpjoined" };
310 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
311 EXPECT_TRUE(AL.hasArg(OPT_A));
312 EXPECT_TRUE(AL.hasArg(OPT_SlurpJoined));
313 EXPECT_EQ(AL.getAllArgValues(OPT_SlurpJoined).size(), 0U);
316 TYPED_TEST(OptTableTest, SlurpJoinedOneJoined) {
317 TypeParam T;
318 unsigned MAI, MAC;
320 const char *MyArgs[] = { "-A", "-slurpjoinedfoo" };
321 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
322 EXPECT_TRUE(AL.hasArg(OPT_A));
323 EXPECT_TRUE(AL.hasArg(OPT_SlurpJoined));
324 EXPECT_EQ(AL.getAllArgValues(OPT_SlurpJoined).size(), 1U);
325 EXPECT_EQ(AL.getAllArgValues(OPT_SlurpJoined)[0], "foo");
328 TYPED_TEST(OptTableTest, SlurpJoinedAndSeparate) {
329 TypeParam T;
330 unsigned MAI, MAC;
332 const char *MyArgs[] = { "-A", "-slurpjoinedfoo", "bar", "baz" };
333 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
334 EXPECT_TRUE(AL.hasArg(OPT_A));
335 EXPECT_TRUE(AL.hasArg(OPT_SlurpJoined));
336 EXPECT_EQ(3U, AL.getAllArgValues(OPT_SlurpJoined).size());
337 EXPECT_EQ("foo", AL.getAllArgValues(OPT_SlurpJoined)[0]);
338 EXPECT_EQ("bar", AL.getAllArgValues(OPT_SlurpJoined)[1]);
339 EXPECT_EQ("baz", AL.getAllArgValues(OPT_SlurpJoined)[2]);
342 TYPED_TEST(OptTableTest, SlurpJoinedButSeparate) {
343 TypeParam T;
344 unsigned MAI, MAC;
346 const char *MyArgs[] = { "-A", "-slurpjoined", "foo", "bar", "baz" };
347 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
348 EXPECT_TRUE(AL.hasArg(OPT_A));
349 EXPECT_TRUE(AL.hasArg(OPT_SlurpJoined));
350 EXPECT_EQ(3U, AL.getAllArgValues(OPT_SlurpJoined).size());
351 EXPECT_EQ("foo", AL.getAllArgValues(OPT_SlurpJoined)[0]);
352 EXPECT_EQ("bar", AL.getAllArgValues(OPT_SlurpJoined)[1]);
353 EXPECT_EQ("baz", AL.getAllArgValues(OPT_SlurpJoined)[2]);
356 TYPED_TEST(OptTableTest, FlagAliasToJoined) {
357 TypeParam T;
358 unsigned MAI, MAC;
360 // Check that a flag alias provides an empty argument to a joined option.
361 const char *MyArgs[] = { "-K" };
362 InputArgList AL = T.ParseArgs(MyArgs, MAI, MAC);
363 EXPECT_EQ(AL.size(), 1U);
364 EXPECT_TRUE(AL.hasArg(OPT_B));
365 EXPECT_EQ(1U, AL.getAllArgValues(OPT_B).size());
366 EXPECT_EQ("", AL.getAllArgValues(OPT_B)[0]);
369 TYPED_TEST(OptTableTest, FindNearest) {
370 TypeParam T;
371 std::string Nearest;
373 // Options that are too short should not be considered
374 // "near" other short options.
375 EXPECT_GT(T.findNearest("-A", Nearest), 4U);
376 EXPECT_GT(T.findNearest("/C", Nearest), 4U);
377 EXPECT_GT(T.findNearest("--C=foo", Nearest), 4U);
379 // The nearest candidate should mirror the amount of prefix
380 // characters used in the original string.
381 EXPECT_EQ(1U, T.findNearest("-blorb", Nearest));
382 EXPECT_EQ(Nearest, "-blorp");
383 EXPECT_EQ(1U, T.findNearest("--blorm", Nearest));
384 EXPECT_EQ(Nearest, "--blorp");
385 EXPECT_EQ(1U, T.findNearest("-blarg", Nearest));
386 EXPECT_EQ(Nearest, "-blarn");
387 EXPECT_EQ(1U, T.findNearest("--blarm", Nearest));
388 EXPECT_EQ(Nearest, "--blarn");
389 EXPECT_EQ(1U, T.findNearest("-fjormp", Nearest));
390 EXPECT_EQ(Nearest, "--fjormp");
392 // The nearest candidate respects the prefix and value delimiter
393 // of the original string.
394 EXPECT_EQ(1U, T.findNearest("/framb:foo", Nearest));
395 EXPECT_EQ(Nearest, "/cramb:foo");
397 // `--glormp` should have an editing distance > 0 from `--glormp=`.
398 EXPECT_GT(T.findNearest("--glorrmp", Nearest), 0U);
399 EXPECT_EQ(Nearest, "--glorrmp=");
400 EXPECT_EQ(0U, T.findNearest("--glorrmp=foo", Nearest));
402 // `--blurmps` should correct to `--blurmp`, not `--blurmp=`, even though
403 // both naively have an editing distance of 1.
404 EXPECT_EQ(1U, T.findNearest("--blurmps", Nearest));
405 EXPECT_EQ(Nearest, "--blurmp");
407 // ...but `--blurmps=foo` should correct to `--blurmp=foo`.
408 EXPECT_EQ(1U, T.findNearest("--blurmps=foo", Nearest));
409 EXPECT_EQ(Nearest, "--blurmp=foo");
411 // Flags should be included and excluded as specified.
412 EXPECT_EQ(1U, T.findNearest("-doopf", Nearest,
413 /*FlagsToInclude=*/OptFlag2,
414 /*FlagsToExclude=*/0));
415 EXPECT_EQ(Nearest, "-doopf2");
416 EXPECT_EQ(1U, T.findNearest("-doopf", Nearest,
417 /*FlagsToInclude=*/0,
418 /*FlagsToExclude=*/OptFlag2));
419 EXPECT_EQ(Nearest, "-doopf1");
421 // Spelling should respect visibility.
422 EXPECT_EQ(1U, T.findNearest("-xyzzy", Nearest, Visibility(DefaultVis)));
423 EXPECT_EQ(Nearest, "-xyzzy2");
424 EXPECT_EQ(1U, T.findNearest("-xyzzy", Nearest, Visibility(SubtoolVis)));
425 EXPECT_EQ(Nearest, "-xyzzy1");
428 TYPED_TEST(DISABLED_OptTableTest, FindNearestFIXME) {
429 TypeParam T;
430 std::string Nearest;
432 // FIXME: Options with joined values should not have those values considered
433 // when calculating distance. The test below would fail if run, but it should
434 // succeed.
435 EXPECT_EQ(1U, T.findNearest("--erbghFoo", Nearest));
436 EXPECT_EQ(Nearest, "--ermghFoo");
439 TYPED_TEST(OptTableTest, ParseGroupedShortOptions) {
440 TypeParam T;
441 T.setGroupedShortOptions(true);
442 unsigned MAI, MAC;
444 // Grouped short options can be followed by a long Flag (-Joo), or a non-Flag
445 // option (-C=1).
446 const char *Args1[] = {"-AIJ", "-AIJoo", "-AC=1"};
447 InputArgList AL = T.ParseArgs(Args1, MAI, MAC);
448 EXPECT_TRUE(AL.hasArg(OPT_A));
449 EXPECT_TRUE(AL.hasArg(OPT_H));
450 ASSERT_EQ((size_t)2, AL.getAllArgValues(OPT_B).size());
451 EXPECT_EQ("foo", AL.getAllArgValues(OPT_B)[0]);
452 EXPECT_EQ("bar", AL.getAllArgValues(OPT_B)[1]);
453 ASSERT_TRUE(AL.hasArg(OPT_C));
454 EXPECT_EQ("1", AL.getAllArgValues(OPT_C)[0]);
456 // Prefer a long option to a short option.
457 const char *Args2[] = {"-AB"};
458 InputArgList AL2 = T.ParseArgs(Args2, MAI, MAC);
459 EXPECT_TRUE(!AL2.hasArg(OPT_A));
460 EXPECT_TRUE(AL2.hasArg(OPT_AB));
462 // Short options followed by a long option. We probably should disallow this.
463 const char *Args3[] = {"-AIblorp"};
464 InputArgList AL3 = T.ParseArgs(Args3, MAI, MAC);
465 EXPECT_TRUE(AL3.hasArg(OPT_A));
466 EXPECT_TRUE(AL3.hasArg(OPT_Blorp));
469 TYPED_TEST(OptTableTest, ParseDashDash) {
470 TypeParam T;
471 T.setDashDashParsing(true);
472 unsigned MAI, MAC;
474 const char *Args1[] = {"-A", "--"};
475 InputArgList AL = T.ParseArgs(Args1, MAI, MAC);
476 EXPECT_TRUE(AL.hasArg(OPT_A));
477 EXPECT_EQ(size_t(0), AL.getAllArgValues(OPT_INPUT).size());
478 EXPECT_EQ(size_t(0), AL.getAllArgValues(OPT_UNKNOWN).size());
480 const char *Args2[] = {"-A", "--", "-A", "--", "-B"};
481 AL = T.ParseArgs(Args2, MAI, MAC);
482 EXPECT_TRUE(AL.hasArg(OPT_A));
483 EXPECT_FALSE(AL.hasArg(OPT_B));
484 const std::vector<std::string> Input = AL.getAllArgValues(OPT_INPUT);
485 ASSERT_EQ(size_t(3), Input.size());
486 EXPECT_EQ("-A", Input[0]);
487 EXPECT_EQ("--", Input[1]);
488 EXPECT_EQ("-B", Input[2]);
489 EXPECT_EQ(size_t(0), AL.getAllArgValues(OPT_UNKNOWN).size());
491 T.setDashDashParsing(false);
492 AL = T.ParseArgs(Args2, MAI, MAC);
493 EXPECT_TRUE(AL.hasArg(OPT_A));
494 EXPECT_TRUE(AL.hasArg(OPT_B));
495 EXPECT_EQ(size_t(0), AL.getAllArgValues(OPT_INPUT).size());
496 const std::vector<std::string> Unknown = AL.getAllArgValues(OPT_UNKNOWN);
497 ASSERT_EQ(size_t(2), Unknown.size());
498 EXPECT_EQ("--", Unknown[0]);
499 EXPECT_EQ("--", Unknown[1]);
502 TYPED_TEST(OptTableTest, UnknownOptions) {
503 TypeParam T;
504 unsigned MAI, MAC;
505 const char *Args[] = {"-u", "--long", "0"};
506 for (int I = 0; I < 2; ++I) {
507 T.setGroupedShortOptions(I != 0);
508 InputArgList AL = T.ParseArgs(Args, MAI, MAC);
509 const std::vector<std::string> Unknown = AL.getAllArgValues(OPT_UNKNOWN);
510 ASSERT_EQ((size_t)2, Unknown.size());
511 EXPECT_EQ("-u", Unknown[0]);
512 EXPECT_EQ("--long", Unknown[1]);
516 TYPED_TEST(OptTableTest, FlagsWithoutValues) {
517 TypeParam T;
518 T.setGroupedShortOptions(true);
519 unsigned MAI, MAC;
520 const char *Args[] = {"-A=1", "-A="};
521 InputArgList AL = T.ParseArgs(Args, MAI, MAC);
522 const std::vector<std::string> Unknown = AL.getAllArgValues(OPT_UNKNOWN);
523 ASSERT_EQ((size_t)2, Unknown.size());
524 EXPECT_EQ("-A=1", Unknown[0]);
525 EXPECT_EQ("-A=", Unknown[1]);
528 TYPED_TEST(OptTableTest, UnknownGroupedShortOptions) {
529 TypeParam T;
530 T.setGroupedShortOptions(true);
531 unsigned MAI, MAC;
532 const char *Args[] = {"-AuzK", "-AuzK"};
533 InputArgList AL = T.ParseArgs(Args, MAI, MAC);
534 const std::vector<std::string> Unknown = AL.getAllArgValues(OPT_UNKNOWN);
535 ASSERT_EQ((size_t)4, Unknown.size());
536 EXPECT_EQ("-u", Unknown[0]);
537 EXPECT_EQ("-z", Unknown[1]);
538 EXPECT_EQ("-u", Unknown[2]);
539 EXPECT_EQ("-z", Unknown[3]);