aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
authorDon Hinton <hintonda@gmail.com>2019-11-06 07:43:00 -0800
committerDon Hinton <hintonda@gmail.com>2019-11-06 08:17:33 -0800
commit405e83689fb42f8ae673d9a26bd21366c4a055be (patch)
treedde23dd0fc497c08f7c32026376fc8be4fe4e6a3 /llvm/unittests/Support/CommandLineTest.cpp
parent9f97480cddd77bd2d169131a290cc996fc78df0f (diff)
downloadllvm-405e83689fb42f8ae673d9a26bd21366c4a055be.zip
llvm-405e83689fb42f8ae673d9a26bd21366c4a055be.tar.gz
llvm-405e83689fb42f8ae673d9a26bd21366c4a055be.tar.bz2
[CommandLine] Add inline ArgName printing
Summary: This patch adds PrintArgInline (after PrintArg) that strips the leading spaces from an argument before printing them, for usage inline. Related bug: PR42943 <https://bugs.llvm.org/show_bug.cgi?id=42943> Patch by Daan Sprenkels! Reviewers: jhenderson, chandlerc, hintonda Reviewed By: jhenderson Subscribers: hiraditya, kristina, llvm-commits, dsprenkels Tags: #llvm Differential Revision: https://reviews.llvm.org/D69501
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 1a1c8a4..1948413 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -1653,4 +1653,54 @@ TEST(CommandLineTest, LongOptions) {
EXPECT_TRUE(Errs.empty()); Errs.clear();
cl::ResetAllOptionOccurrences();
}
+
+TEST(CommandLineTest, OptionErrorMessage) {
+ // When there is an error, we expect some error message like:
+ // prog: for the -a option: [...]
+ //
+ // Test whether the "for the -a option"-part is correctly formatted.
+ cl::ResetCommandLineParser();
+
+ StackOption<bool> OptA("a", cl::desc("Some option"));
+ StackOption<bool> OptLong("long", cl::desc("Some long option"));
+
+ std::string Errs;
+ raw_string_ostream OS(Errs);
+
+ OptA.error("custom error", OS);
+ OS.flush();
+ EXPECT_FALSE(Errs.find("for the -a option:") == std::string::npos);
+ Errs.clear();
+
+ OptLong.error("custom error", OS);
+ OS.flush();
+ EXPECT_FALSE(Errs.find("for the --long option:") == std::string::npos);
+ Errs.clear();
+
+ cl::ResetAllOptionOccurrences();
+}
+
+TEST(CommandLineTest, OptionErrorMessageSuggest) {
+ // When there is an error, and the edit-distance is not very large,
+ // we expect some error message like:
+ // prog: did you mean '--option'?
+ //
+ // Test whether this message is well-formatted.
+ cl::ResetCommandLineParser();
+
+ StackOption<bool> OptLong("aluminium", cl::desc("Some long option"));
+
+ const char *args[] = {"prog", "--aluminum"};
+
+ std::string Errs;
+ raw_string_ostream OS(Errs);
+
+ EXPECT_FALSE(cl::ParseCommandLineOptions(2, args, StringRef(), &OS));
+ OS.flush();
+ EXPECT_FALSE(Errs.find("prog: Did you mean '--aluminium'?\n") ==
+ std::string::npos);
+ Errs.clear();
+
+ cl::ResetAllOptionOccurrences();
+}
} // anonymous namespace