This allows users accessing options in libSupport before invoking
cl::ParseCommandLineOptions, and also matches the behavior before
D105959.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I'm not sure if we need a test for it. I tried to add one but the test passed even without this patch, as those options were already initialized before running the test.
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index a0352bc8a4c5..c18d34ab4323 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -89,6 +89,12 @@ public: ~StackSubCommand() { unregisterSubCommand(); } }; +TEST(CommandLineTest, RetrievePresetOptions) { + StringMap<cl::Option *> &Map = + cl::getRegisteredOptions(*cl::TopLevelSubCommand); + + ASSERT_TRUE(Map.count("help") == 1) << "Could not get preset option `help`"; +} cl::OptionCategory TestCategory("Test Options", "Description"); TEST(CommandLineTest, ModifyExisitingOption) {
Seems nice to have a test for this...
One idea would be to split this test out of SupportTests to avoid being affected by other tests' running the initializer... assuming that's what's preventing the test from being useful?
Another idea would be to add a new llvm-clopt-test executable that exposes this codepath somehow. The tool could check if the first command-line argument is -register, and avoid parsing the command-line in that case.
Is there a way to clear all the registered options, prior to reregistering them again? Alternatively, would it be simple to add? I'm guessing even if it were, it might not solve our problems though, since the variables are local statics, so resetting wouldn't cause them to be reinstantiated...
I believe so. So I think I need to split the test from SupportTests as @dexonsmith suggested.
llvm/unittests/Support/CommandLineInit/CMakeLists.txt | ||
---|---|---|
2 | I believe so. Most part of the file was copied from add_unittest in llvm/cmake/modules/AddLLVM.cmake, except that gtest_main was excluded from target_link_libraries to prevent the test linking against TestMain.cpp. | |
llvm/unittests/Support/CommandLineInit/CommandLineInitTest.cpp | ||
32 | Yep. Should I add a comment in the source code? |
This file looks a bit complex. Is all stuff here needed?