Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 1 | //===--- utils/unittest/UnitTestMain/TestMain.cpp - unittest driver -------===// |
| 2 | // |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame^] | 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 |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/Support/CommandLine.h" |
| 10 | #include "llvm/Support/Signals.h" |
| 11 | #include "gmock/gmock.h" |
| 12 | #include "gtest/gtest.h" |
| 13 | |
| 14 | #if defined(_WIN32) |
| 15 | # include <windows.h> |
| 16 | # if defined(_MSC_VER) |
| 17 | # include <crtdbg.h> |
| 18 | # endif |
| 19 | #endif |
| 20 | |
| 21 | const char *TestMainArgv0; |
| 22 | |
| 23 | int main(int argc, char **argv) { |
| 24 | llvm::sys::PrintStackTraceOnErrorSignal(argv[0], |
| 25 | true /* Disable crash reporting */); |
| 26 | |
| 27 | // Initialize both gmock and gtest. |
| 28 | testing::InitGoogleMock(&argc, argv); |
| 29 | |
| 30 | llvm::cl::ParseCommandLineOptions(argc, argv); |
| 31 | |
| 32 | // Make it easy for a test to re-execute itself by saving argv[0]. |
| 33 | TestMainArgv0 = argv[0]; |
| 34 | |
| 35 | # if defined(_WIN32) |
| 36 | // Disable all of the possible ways Windows conspires to make automated |
| 37 | // testing impossible. |
| 38 | ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); |
| 39 | # if defined(_MSC_VER) |
| 40 | ::_set_error_mode(_OUT_TO_STDERR); |
| 41 | _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 42 | _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
| 43 | _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 44 | _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); |
| 45 | _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 46 | _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
| 47 | # endif |
| 48 | # endif |
| 49 | |
| 50 | return RUN_ALL_TESTS(); |
| 51 | } |