TestMain.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. //===----------------------------------------------------------------------===//
  8. #include "llvm/Support/CommandLine.h"
  9. #include "llvm/Support/Signals.h"
  10. #include "gmock/gmock.h"
  11. #include "gtest/gtest.h"
  12. #if defined(_WIN32)
  13. # include <windows.h>
  14. # if defined(_MSC_VER)
  15. # include <crtdbg.h>
  16. # endif
  17. #endif
  18. const char *TestMainArgv0;
  19. int main(int argc, char **argv) {
  20. llvm::sys::PrintStackTraceOnErrorSignal(argv[0],
  21. true /* Disable crash reporting */);
  22. // Initialize both gmock and gtest.
  23. testing::InitGoogleMock(&argc, argv);
  24. llvm::cl::ParseCommandLineOptions(argc, argv);
  25. // Make it easy for a test to re-execute itself by saving argv[0].
  26. TestMainArgv0 = argv[0];
  27. # if defined(_WIN32)
  28. // Disable all of the possible ways Windows conspires to make automated
  29. // testing impossible.
  30. ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  31. # if defined(_MSC_VER)
  32. ::_set_error_mode(_OUT_TO_STDERR);
  33. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  34. _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
  35. _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  36. _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
  37. _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  38. _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
  39. # endif
  40. # endif
  41. return RUN_ALL_TESTS();
  42. }