diff options
author | Igor Kudrin <ikudrin@accesssoftek.com> | 2024-01-09 05:03:16 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-09 05:03:16 +0700 |
commit | b2ea9ec7fcf37ca01979c11c5b2b1cab0e1ae212 (patch) | |
tree | 36297062bd98a49f07403ec2b3bfb06714d2f865 /llvm/unittests/Support/CommandLineTest.cpp | |
parent | f84bfa2f92d2aa3329bc06902a12c0f4c54d7297 (diff) | |
download | llvm-b2ea9ec7fcf37ca01979c11c5b2b1cab0e1ae212.zip llvm-b2ea9ec7fcf37ca01979c11c5b2b1cab0e1ae212.tar.gz llvm-b2ea9ec7fcf37ca01979c11c5b2b1cab0e1ae212.tar.bz2 |
[CommandLine] Do not print empty categories with '--help-hidden' (#77043)
If a category has no options associated with it, the `--help-hidden`
command still shows that category with the annotation "This option
category has no options", and this is how it was implemented from the
beginning when the categories were introduced, see commit 0537a98878. A
feature to hide unrelated options was added later, in
https://reviews.llvm.org/D7100. Now, if a tool needs to hide unrelated
options that are associated with categories, leaving some of them empty,
those categories will still be visible on the `--help-hidden` output,
even if they have no use for the tool; see the changes in
`llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test` for an example.
The patch ensures that only categories with options are shown on both
main and hidden help output.
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r-- | llvm/unittests/Support/CommandLineTest.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index a9d0790..99d99c7 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -2301,4 +2301,29 @@ TEST(CommandLineTest, SubCommandGroups) { EXPECT_FALSE(SC3.OptionsMap.contains("opt12")); } +TEST(CommandLineTest, HelpWithEmptyCategory) { + cl::ResetCommandLineParser(); + + cl::OptionCategory Category1("First Category"); + cl::OptionCategory Category2("Second Category"); + StackOption<int> Opt1("opt1", cl::cat(Category1)); + StackOption<int> Opt2("opt2", cl::cat(Category2)); + cl::HideUnrelatedOptions(Category2); + + const char *args[] = {"prog"}; + EXPECT_TRUE(cl::ParseCommandLineOptions(std::size(args), args, StringRef(), + &llvm::nulls())); + auto Output = interceptStdout( + []() { cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); }); + EXPECT_EQ(std::string::npos, Output.find("First Category")) + << "An empty category should not be printed"; + + Output = interceptStdout( + []() { cl::PrintHelpMessage(/*Hidden=*/true, /*Categorized=*/true); }); + EXPECT_EQ(std::string::npos, Output.find("First Category")) + << "An empty category should not be printed"; + + cl::ResetCommandLineParser(); +} + } // anonymous namespace |