1 //===- llvm/unittest/Support/CommandLineInit/CommandLineInitTest.cpp ------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// Check if preset options in libSupport -- e.g., "help", "version", etc. --
11 /// are correctly initialized and registered before getRegisteredOptions is
14 /// Most code here comes from llvm/utils/unittest/UnitTestMain/TestMain.cpp,
15 /// except that llvm::cl::ParseCommandLineOptions() call is removed.
17 //===----------------------------------------------------------------------===//
19 #include "llvm/Support/CommandLine.h"
20 #include "gtest/gtest.h"
31 int main(int argc
, char **argv
) {
32 testing::InitGoogleTest(&argc
, argv
);
35 // Disable all of the possible ways Windows conspires to make automated
36 // testing impossible.
37 ::SetErrorMode(SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
39 ::_set_error_mode(_OUT_TO_STDERR
);
40 _CrtSetReportMode(_CRT_WARN
, _CRTDBG_MODE_FILE
| _CRTDBG_MODE_DEBUG
);
41 _CrtSetReportFile(_CRT_WARN
, _CRTDBG_FILE_STDERR
);
42 _CrtSetReportMode(_CRT_ERROR
, _CRTDBG_MODE_FILE
| _CRTDBG_MODE_DEBUG
);
43 _CrtSetReportFile(_CRT_ERROR
, _CRTDBG_FILE_STDERR
);
44 _CrtSetReportMode(_CRT_ASSERT
, _CRTDBG_MODE_FILE
| _CRTDBG_MODE_DEBUG
);
45 _CrtSetReportFile(_CRT_ASSERT
, _CRTDBG_FILE_STDERR
);
49 return RUN_ALL_TESTS();
52 TEST(CommandLineInitTest
, GetPresetOptions
) {
53 StringMap
<cl::Option
*> &Map
=
54 cl::getRegisteredOptions(cl::SubCommand::getTopLevel());
57 {"help", "help-hidden", "help-list", "help-list-hidden", "version"})
58 EXPECT_EQ(Map
.count(Str
), (size_t)1)
59 << "Could not get preset option `" << Str
<< '`';