From 044eb2f6afba375a914ac9d8024f8f5142bb912e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 18 Dec 2017 20:10:56 +0000 Subject: Vendor import of llvm trunk r321017: https://llvm.org/svn/llvm-project/llvm/trunk@321017 --- unittests/Support/CommandLineTest.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'unittests/Support/CommandLineTest.cpp') 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 Opt1("opt1", cl::init("true")); + StackOption Opt2("opt2", cl::init(true)); + cl::alias Alias("alias", llvm::cl::aliasopt(Opt2)); + StackOption 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 -- cgit v1.2.3