aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
authorJacques Pienaar <jpienaar@google.com>2025-09-25 21:16:00 +0200
committerGitHub <noreply@github.com>2025-09-25 12:16:00 -0700
commit90a6884f2d088547f7b2650d2151a316b9694f59 (patch)
treeb61abd15d00641c61e42a0b3e34358f53705a987 /llvm/unittests/Support/CommandLineTest.cpp
parent223cfa8018595ff2a809b4e10701bfea884af709 (diff)
downloadllvm-90a6884f2d088547f7b2650d2151a316b9694f59.zip
llvm-90a6884f2d088547f7b2650d2151a316b9694f59.tar.gz
llvm-90a6884f2d088547f7b2650d2151a316b9694f59.tar.bz2
Enable parsing of optional strings (#154364)
Previously a "opt<std::optional<std::string>>>" would fail to parse/would attempt to parse option value as argument.
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 88e6445..7f538f1 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -2117,6 +2117,22 @@ TEST(CommandLineTest, ConsumeAfterTwoPositionals) {
EXPECT_TRUE(Errs.empty());
}
+TEST(CommandLineTest, ConsumeOptionalString) {
+ cl::ResetCommandLineParser();
+
+ StackOption<std::optional<std::string>, cl::opt<std::optional<std::string>>>
+ Input("input");
+
+ const char *Args[] = {"prog", "--input=\"value\""};
+
+ std::string Errs;
+ raw_string_ostream OS(Errs);
+ ASSERT_TRUE(cl::ParseCommandLineOptions(2, Args, StringRef(), &OS));
+ ASSERT_TRUE(Input.has_value());
+ EXPECT_EQ("\"value\"", *Input);
+ EXPECT_TRUE(Errs.empty());
+}
+
TEST(CommandLineTest, ResetAllOptionOccurrences) {
cl::ResetCommandLineParser();