aboutsummaryrefslogtreecommitdiffstats
path: root/test/gtest_throw_on_failure_test_.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/gtest_throw_on_failure_test_.cc')
-rw-r--r--test/gtest_throw_on_failure_test_.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/test/gtest_throw_on_failure_test_.cc b/test/gtest_throw_on_failure_test_.cc
index 03776ecb..2b88fe3d 100644
--- a/test/gtest_throw_on_failure_test_.cc
+++ b/test/gtest_throw_on_failure_test_.cc
@@ -37,12 +37,28 @@
#include "gtest/gtest.h"
+#include <stdio.h> // for fflush, fprintf, NULL, etc.
+#include <stdlib.h> // for exit
+#include <exception> // for set_terminate
+
+// This terminate handler aborts the program using exit() rather than abort().
+// This avoids showing pop-ups on Windows systems and core dumps on Unix-like
+// ones.
+void TerminateHandler() {
+ fprintf(stderr, "%s\n", "Unhandled C++ exception terminating the program.");
+ fflush(NULL);
+ exit(1);
+}
+
int main(int argc, char** argv) {
+#if GTEST_HAS_EXCEPTIONS
+ std::set_terminate(&TerminateHandler);
+#endif
testing::InitGoogleTest(&argc, argv);
// We want to ensure that people can use Google Test assertions in
// other testing frameworks, as long as they initialize Google Test
- // properly and set the thrown-on-failure mode. Therefore, we don't
+ // properly and set the throw-on-failure mode. Therefore, we don't
// use Google Test's constructs for defining and running tests
// (e.g. TEST and RUN_ALL_TESTS) here.