TestMain.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===--- utils/unittest/UnitTestMain/TestMain.cpp - unittest driver -------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  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. #if defined(_WIN32)
  14. # include <windows.h>
  15. # if defined(_MSC_VER)
  16. # include <crtdbg.h>
  17. # endif
  18. #endif
  19. const char *TestMainArgv0;
  20. int main(int argc, char **argv) {
  21. llvm::sys::PrintStackTraceOnErrorSignal(argv[0],
  22. true /* Disable crash reporting */);
  23. // Initialize both gmock and gtest.
  24. testing::InitGoogleMock(&argc, argv);
  25. llvm::cl::ParseCommandLineOptions(argc, argv);
  26. // Make it easy for a test to re-execute itself by saving argv[0].
  27. TestMainArgv0 = argv[0];
  28. # if defined(_WIN32)
  29. // Disable all of the possible ways Windows conspires to make automated
  30. // testing impossible.
  31. ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  32. # if defined(_MSC_VER)
  33. ::_set_error_mode(_OUT_TO_STDERR);
  34. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  35. _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
  36. _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  37. _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
  38. _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  39. _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
  40. # endif
  41. # endif
  42. return RUN_ALL_TESTS();
  43. }