aboutsummaryrefslogtreecommitdiff
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.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 660df11..1fb0213 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -613,4 +613,39 @@ TEST(CommandLineTest, ResponseFiles) {
llvm::sys::fs::remove(TestDir);
}
+TEST(CommandLineTest, SetDefautValue) {
+ cl::ResetCommandLineParser();
+
+ StackOption<std::string> Opt1("opt1", cl::init("true"));
+ StackOption<bool> Opt2("opt2", cl::init(true));
+ cl::alias Alias("alias", llvm::cl::aliasopt(Opt2));
+ StackOption<int> Opt3("opt3", cl::init(3));
+
+ const char *args[] = {"prog", "-opt1=false", "-opt2", "-opt3"};
+
+ EXPECT_TRUE(
+ cl::ParseCommandLineOptions(2, args, StringRef(), &llvm::nulls()));
+
+ EXPECT_TRUE(Opt1 == "false");
+ EXPECT_TRUE(Opt2);
+ EXPECT_TRUE(Opt3 == 3);
+
+ Opt2 = false;
+ Opt3 = 1;
+
+ cl::ResetAllOptionOccurrences();
+
+ for (auto &OM : cl::getRegisteredOptions(*cl::TopLevelSubCommand)) {
+ cl::Option *O = OM.second;
+ if (O->ArgStr == "opt2") {
+ continue;
+ }
+ O->setDefault();
+ }
+
+ EXPECT_TRUE(Opt1 == "true");
+ EXPECT_TRUE(Opt2);
+ EXPECT_TRUE(Opt3 == 3);
+}
+
} // anonymous namespace