diff options
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/Support/CommandLine.h | 3 | ||||
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 3 | ||||
-rw-r--r-- | llvm/unittests/Support/CommandLineTest.cpp | 24 |
3 files changed, 27 insertions, 3 deletions
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h index e53ac06a3cd..c0e9d972498 100644 --- a/llvm/include/llvm/Support/CommandLine.h +++ b/llvm/include/llvm/Support/CommandLine.h @@ -20,6 +20,7 @@ #ifndef LLVM_SUPPORT_COMMANDLINE_H #define LLVM_SUPPORT_COMMANDLINE_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/Twine.h" @@ -1938,7 +1939,7 @@ void HideUnrelatedOptions(cl::OptionCategory &Category); /// Some tools (like clang-format) like to be able to hide all options that are /// not specific to the tool. This function allows a tool to specify a single /// option category to display in the -help output. -void HideUnrelatedOptions(SmallVectorImpl<cl::OptionCategory *> &Categories); +void HideUnrelatedOptions(ArrayRef<cl::OptionCategory *> Categories); } // End namespace cl diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 4cd6f0c5f0a..f17d1f69ad6 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -1861,8 +1861,7 @@ void cl::HideUnrelatedOptions(cl::OptionCategory &Category) { } } -void cl::HideUnrelatedOptions( - SmallVectorImpl<cl::OptionCategory *> &Categories) { +void cl::HideUnrelatedOptions(ArrayRef<cl::OptionCategory *> Categories) { auto CategoriesBegin = Categories.begin(); auto CategoriesEnd = Categories.end(); StringMap<cl::Option *> Options; diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index 4fa14e252fb..750559341cf 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -247,4 +247,28 @@ TEST(CommandLineTest, HideUnrelatedOptions) { << "Hid default option that should be visable."; } +cl::OptionCategory TestCategory2("Test Options set 2", "Description"); + +TEST(CommandLineTest, HideUnrelatedOptionsMulti) { + cl::opt<int> TestOption1("test-option-1"); + cl::opt<int> TestOption2("test-option-2", cl::cat(TestCategory)); + cl::opt<int> TestOption3("test-option-3", cl::cat(TestCategory2)); + + cl::OptionCategory *VisibleCategories[] = {&TestCategory, &TestCategory2}; + + cl::HideUnrelatedOptions(makeArrayRef(VisibleCategories)); + + ASSERT_EQ(cl::ReallyHidden, TestOption1.getOptionHiddenFlag()) + << "Failed to hide extra option."; + ASSERT_EQ(cl::NotHidden, TestOption2.getOptionHiddenFlag()) + << "Hid extra option that should be visable."; + ASSERT_EQ(cl::NotHidden, TestOption3.getOptionHiddenFlag()) + << "Hid extra option that should be visable."; + + StringMap<cl::Option *> Map; + cl::getRegisteredOptions(Map); + ASSERT_EQ(cl::NotHidden, Map["help"]->getOptionHiddenFlag()) + << "Hid default option that should be visable."; +} + } // anonymous namespace |