aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
authorSon Tuan Vu <vuson@google.com>2022-10-05 20:04:47 +0000
committerSon Tuan Vu <vuson@google.com>2022-10-06 17:50:40 +0000
commita4deb14fdfaa183da938e40b54954afa9c7a11c1 (patch)
tree8a03b3a5f9408c408fb46eab5d85c4682c0fa305 /llvm/unittests/Support/CommandLineTest.cpp
parent7404b855e528f88bf2a395a0a14937ca6812e8d1 (diff)
downloadllvm-a4deb14fdfaa183da938e40b54954afa9c7a11c1.zip
llvm-a4deb14fdfaa183da938e40b54954afa9c7a11c1.tar.gz
llvm-a4deb14fdfaa183da938e40b54954afa9c7a11c1.tar.bz2
[LLVM][Support] Support for `llvm::cl::list`'s default values
This patch introduces support for default values of list of CL options. It fixes the issue in https://github.com/llvm/llvm-project/issues/52667 Reviewed By: bkramer Differential Revision: https://reviews.llvm.org/D135311
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 7af8c89..dd6e122 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -1038,7 +1038,7 @@ TEST(CommandLineTest, ResponseFileEOLs) {
}
}
-TEST(CommandLineTest, SetDefautValue) {
+TEST(CommandLineTest, SetDefaultValue) {
cl::ResetCommandLineParser();
StackOption<std::string> Opt1("opt1", cl::init("true"));
@@ -1046,15 +1046,32 @@ TEST(CommandLineTest, SetDefautValue) {
cl::alias Alias("alias", llvm::cl::aliasopt(Opt2));
StackOption<int> Opt3("opt3", cl::init(3));
- const char *args[] = {"prog", "-opt1=false", "-opt2", "-opt3"};
+ llvm::SmallVector<int, 3> IntVals = {1, 2, 3};
+ llvm::SmallVector<std::string, 3> StrVals = {"foo", "bar", "baz"};
+
+ StackOption<int, cl::list<int>> List1(
+ "list1", cl::list_init<int>(llvm::ArrayRef<int>(IntVals)),
+ cl::CommaSeparated);
+ StackOption<std::string, cl::list<std::string>> List2(
+ "list2", cl::list_init<std::string>(llvm::ArrayRef<std::string>(StrVals)),
+ cl::CommaSeparated);
+ cl::alias ListAlias("list-alias", llvm::cl::aliasopt(List2));
+
+ const char *args[] = {"prog", "-opt1=false", "-list1", "4",
+ "-list1", "5,6", "-opt2", "-opt3"};
EXPECT_TRUE(
- cl::ParseCommandLineOptions(2, args, StringRef(), &llvm::nulls()));
+ cl::ParseCommandLineOptions(7, args, StringRef(), &llvm::nulls()));
EXPECT_EQ(Opt1, "false");
EXPECT_TRUE(Opt2);
EXPECT_EQ(Opt3, 3);
+ for (size_t I = 0, E = IntVals.size(); I < E; ++I) {
+ EXPECT_EQ(IntVals[I] + 3, List1[I]);
+ EXPECT_EQ(StrVals[I], List2[I]);
+ }
+
Opt2 = false;
Opt3 = 1;
@@ -1071,7 +1088,13 @@ TEST(CommandLineTest, SetDefautValue) {
EXPECT_EQ(Opt1, "true");
EXPECT_TRUE(Opt2);
EXPECT_EQ(Opt3, 3);
+ for (size_t I = 0, E = IntVals.size(); I < E; ++I) {
+ EXPECT_EQ(IntVals[I], List1[I]);
+ EXPECT_EQ(StrVals[I], List2[I]);
+ }
+
Alias.removeArgument();
+ ListAlias.removeArgument();
}
TEST(CommandLineTest, ReadConfigFile) {