aboutsummaryrefslogtreecommitdiffstats
path: root/googletest/src
diff options
context:
space:
mode:
authorAntoine Pitrou <antoine@python.org>2019-08-06 13:11:40 +0200
committerAntoine Pitrou <antoine@python.org>2019-08-06 13:11:40 +0200
commitc39ee9c460e6bb0b2b86209932b708ddaaf69695 (patch)
treebfdaa24afb4f86592c1065836bbacd7487241c07 /googletest/src
parent11be5f534cfca1139880dd66727c15f5bd1e0780 (diff)
downloadgoogletest-c39ee9c460e6bb0b2b86209932b708ddaaf69695.tar.gz
googletest-c39ee9c460e6bb0b2b86209932b708ddaaf69695.tar.bz2
googletest-c39ee9c460e6bb0b2b86209932b708ddaaf69695.zip
Fix #2371: Redirect Windows CRT assertions to stderr
Diffstat (limited to 'googletest/src')
-rw-r--r--googletest/src/gtest.cc20
1 files changed, 15 insertions, 5 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index a74041e7..cbd48d31 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