diff options
author | Antoine Pitrou <antoine@python.org> | 2019-08-06 11:11:40 (GMT) |
---|---|---|
committer | Antoine Pitrou <antoine@python.org> | 2019-08-06 11:11:40 (GMT) |
commit | c39ee9c460e6bb0b2b86209932b708ddaaf69695 (patch) | |
tree | bfdaa24afb4f86592c1065836bbacd7487241c07 /googletest/src | |
parent | 11be5f534cfca1139880dd66727c15f5bd1e0780 (diff) | |
download | googletest-c39ee9c460e6bb0b2b86209932b708ddaaf69695.zip googletest-c39ee9c460e6bb0b2b86209932b708ddaaf69695.tar.gz googletest-c39ee9c460e6bb0b2b86209932b708ddaaf69695.tar.bz2 |
Fix #2371: Redirect Windows CRT assertions to stderrrefs/pull/2372/head
Diffstat (limited to 'googletest/src')
-rw-r--r-- | googletest/src/gtest.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index a74041e..cbd48d3 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -80,6 +80,11 @@ #elif GTEST_OS_WINDOWS // We are on Windows proper. +# include <windows.h> // NOLINT +# undef min + +# include <crtdbg.h> // NOLINT +# include <debugapi.h> // NOLINT # include <io.h> // NOLINT # include <sys/timeb.h> // NOLINT # include <sys/types.h> // NOLINT @@ -91,11 +96,6 @@ # include <sys/time.h> // NOLINT # endif // GTEST_OS_WINDOWS_MINGW -// cpplint thinks that the header is already included, so we want to -// silence it. -# include <windows.h> // NOLINT -# undef min - #else // Assume other platforms have gettimeofday(). @@ -4914,6 +4914,16 @@ int UnitTest::Run() { 0x0, // Clear the following flags: _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump. # endif + + // In debug mode, the Windows CRT can crash with an assertion over invalid + // input (e.g. passing an invalid file descriptor). The default handling + // for these assertions is to pop up a dialog and wait for user input. + // Instead ask the CRT to dump such assertions to stderr non-interactively. + if (!IsDebuggerPresent()) { + (void)_CrtSetReportMode(_CRT_ASSERT, + _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + } } #endif // GTEST_OS_WINDOWS |