Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / unittests / Support / CommandLineInit / CommandLineInitTest.cpp
blobdce79b2a3d2c715fc5b2e7817e76ebd18ca17a0e
1 //===- llvm/unittest/Support/CommandLineInit/CommandLineInitTest.cpp ------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file
10 /// Check if preset options in libSupport -- e.g., "help", "version", etc. --
11 /// are correctly initialized and registered before getRegisteredOptions is
12 /// invoked.
13 ///
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"
22 #if defined(_WIN32)
23 #include <windows.h>
24 #if defined(_MSC_VER)
25 #include <crtdbg.h>
26 #endif
27 #endif
29 using namespace llvm;
31 int main(int argc, char **argv) {
32 testing::InitGoogleTest(&argc, argv);
34 #if defined(_WIN32)
35 // Disable all of the possible ways Windows conspires to make automated
36 // testing impossible.
37 ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
38 #if defined(_MSC_VER)
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);
46 #endif
47 #endif
49 return RUN_ALL_TESTS();
52 TEST(CommandLineInitTest, GetPresetOptions) {
53 StringMap<cl::Option *> &Map =
54 cl::getRegisteredOptions(cl::SubCommand::getTopLevel());
56 for (auto *Str :
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 << '`';