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