aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
authorYevgeny Rouban <yrouban@azul.com>2022-03-09 18:10:21 +0700
committerYevgeny Rouban <yrouban@azul.com>2022-03-10 08:26:34 +0700
commitfcd9fa416d0d3585f9d6c68302df8ba39889608a (patch)
treef65dd18cd20cb7200f92ae6bf2dee689da9d9878 /llvm/unittests/Support/CommandLineTest.cpp
parent43f208e94c246fbb9dc5463c1a8af8eb00d4c7e5 (diff)
downloadllvm-fcd9fa416d0d3585f9d6c68302df8ba39889608a.zip
llvm-fcd9fa416d0d3585f9d6c68302df8ba39889608a.tar.gz
llvm-fcd9fa416d0d3585f9d6c68302df8ba39889608a.tar.bz2
[Support] Try 2: Reset option to its default if its Default field is undefined
opt::setDefaultImpl() is changed to set the option value to the option type's default if the Default field is not set. This results in option value reset by Option::reset() or ResetAllOptionOccurrences() even if the cl::init() is not specified. Example: StackOption<std::string> Str("str"); // No cl::init(). Str = "some value"; cl::ResetAllOptionOccurrences(); EXPECT_EQ("", Str); // The Str is reset. Reviewed By: lattner Differential Revision: https://reviews.llvm.org/D115433
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 9a7f4f3..c683f91 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -1934,8 +1934,9 @@ TEST(CommandLineTest, ConsumeAfterTwoPositionals) {
TEST(CommandLineTest, ResetAllOptionOccurrences) {
cl::ResetCommandLineParser();
- // -option -enableA -enableC [sink] input [args]
+ // -option -str -enableA -enableC [sink] input [args]
StackOption<bool> Option("option");
+ StackOption<std::string> Str("str");
enum Vals { ValA, ValB, ValC };
StackOption<Vals, cl::bits<Vals>> Bits(
cl::values(clEnumValN(ValA, "enableA", "Enable A"),
@@ -1945,15 +1946,16 @@ TEST(CommandLineTest, ResetAllOptionOccurrences) {
StackOption<std::string> Input(cl::Positional);
StackOption<std::string, cl::list<std::string>> ExtraArgs(cl::ConsumeAfter);
- const char *Args[] = {"prog", "-option", "-enableA", "-enableC",
- "-unknown", "input", "-arg"};
+ const char *Args[] = {"prog", "-option", "-str=STR", "-enableA",
+ "-enableC", "-unknown", "input", "-arg"};
std::string Errs;
raw_string_ostream OS(Errs);
- EXPECT_TRUE(cl::ParseCommandLineOptions(7, Args, StringRef(), &OS));
+ EXPECT_TRUE(cl::ParseCommandLineOptions(8, Args, StringRef(), &OS));
EXPECT_TRUE(OS.str().empty());
EXPECT_TRUE(Option);
+ EXPECT_EQ("STR", Str);
EXPECT_EQ((1u << ValA) | (1u << ValC), Bits.getBits());
EXPECT_EQ(1u, Sink.size());
EXPECT_EQ("-unknown", Sink[0]);
@@ -1963,6 +1965,7 @@ TEST(CommandLineTest, ResetAllOptionOccurrences) {
cl::ResetAllOptionOccurrences();
EXPECT_FALSE(Option);
+ EXPECT_EQ("", Str);
EXPECT_EQ(0u, Bits.getBits());
EXPECT_EQ(0u, Sink.size());
EXPECT_EQ(0, Input.getNumOccurrences());