Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / third-party / unittest / UnitTestMain / TestMain.cpp
blob35ba72ba3fcd3786fa19674d7f3472be28b6961d
1 //===--- utils/unittest/UnitTestMain/TestMain.cpp - unittest driver -------===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/CommandLine.h"
10 #include "llvm/Support/Signals.h"
11 #include "gmock/gmock.h"
12 #include "gtest/gtest.h"
13 #include <stdlib.h>
15 #if defined(_WIN32)
16 # include <windows.h>
17 # if defined(_MSC_VER)
18 # include <crtdbg.h>
19 # endif
20 #endif
22 const char *TestMainArgv0;
24 int main(int argc, char **argv) {
25 // Skip setting up signal handlers for tests that need to test things without
26 // them configured.
27 if (!getenv("LLVM_PROGRAM_TEST_NO_STACKTRACE_HANDLER")) {
28 llvm::sys::PrintStackTraceOnErrorSignal(argv[0],
29 true /* Disable crash reporting */);
32 // Initialize both gmock and gtest.
33 testing::InitGoogleMock(&argc, argv);
35 llvm::cl::ParseCommandLineOptions(argc, argv);
37 // Make it easy for a test to re-execute itself by saving argv[0].
38 TestMainArgv0 = argv[0];
40 # if defined(_WIN32)
41 // Disable all of the possible ways Windows conspires to make automated
42 // testing impossible.
43 ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
44 # if defined(_MSC_VER)
45 ::_set_error_mode(_OUT_TO_STDERR);
46 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
47 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
48 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
49 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
50 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
51 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
52 # endif
53 # endif
55 return RUN_ALL_TESTS();