diff options
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r-- | llvm/unittests/Support/CommandLineTest.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index f9841f5..4839a31 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -1128,4 +1128,26 @@ TEST(CommandLineTest, PrefixOptions) { EXPECT_TRUE(MacroDefs.front().compare("HAVE_FOO") == 0); } +TEST(CommandLineTest, GroupingWithValue) { + cl::ResetCommandLineParser(); + + StackOption<bool> OptF("f", cl::Grouping, cl::desc("Some flag")); + StackOption<std::string> OptV("v", cl::Grouping, + cl::desc("Grouping option with a value")); + + // Should be possible to use an option which requires a value + // at the end of a group. + const char *args1[] = {"prog", "-fv", "val1"}; + EXPECT_TRUE( + cl::ParseCommandLineOptions(3, args1, StringRef(), &llvm::nulls())); + EXPECT_TRUE(OptF); + EXPECT_STREQ("val1", OptV.c_str()); + cl::ResetAllOptionOccurrences(); + + // Should not crash if it is accidentally used elsewhere in the group. + const char *args2[] = {"prog", "-vf", "val2"}; + EXPECT_FALSE( + cl::ParseCommandLineOptions(3, args2, StringRef(), &llvm::nulls())); +} + } // anonymous namespace |