diff options
Diffstat (limited to 'unittests/Support/CommandLineTest.cpp')
| -rw-r--r-- | unittests/Support/CommandLineTest.cpp | 35 | 
1 files changed, 35 insertions, 0 deletions
| diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp index 660df11446ac..1fb0213b4d18 100644 --- a/unittests/Support/CommandLineTest.cpp +++ b/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 | 
