summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index e227586ba3e..72c9e32a60d 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -476,4 +476,33 @@ TEST(CommandLineTest, RemoveFromAllSubCommands) {
EXPECT_FALSE(cl::ParseCommandLineOptions(3, args2, StringRef(), true));
}
+TEST(CommandLineTest, GetRegisteredSubcommands) {
+ cl::ResetCommandLineParser();
+
+ StackSubCommand SC1("sc1", "First Subcommand");
+ StackOption<bool> Opt1("opt1", cl::sub(SC1), cl::init(false));
+ StackSubCommand SC2("sc2", "Second subcommand");
+ StackOption<bool> Opt2("opt2", cl::sub(SC2), cl::init(false));
+
+ const char *args0[] = {"prog", "sc1"};
+ const char *args1[] = {"prog", "sc2"};
+
+ EXPECT_TRUE(cl::ParseCommandLineOptions(2, args0, StringRef(), true));
+ EXPECT_FALSE(Opt1);
+ EXPECT_FALSE(Opt2);
+ for (auto *S : cl::getRegisteredSubcommands()) {
+ if (*S)
+ EXPECT_EQ("sc1", S->getName());
+ }
+
+ cl::ResetAllOptionOccurrences();
+ EXPECT_TRUE(cl::ParseCommandLineOptions(2, args1, StringRef(), true));
+ EXPECT_FALSE(Opt1);
+ EXPECT_FALSE(Opt2);
+ for (auto *S : cl::getRegisteredSubcommands()) {
+ if (*S)
+ EXPECT_EQ("sc2", S->getName());
+ }
+}
+
} // anonymous namespace
OpenPOWER on IntegriCloud