aboutsummaryrefslogtreecommitdiffstats
path: root/test/gtest_catch_exceptions_test_.cc
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-08-31 18:21:13 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-08-31 18:21:13 +0000
commit35c39756495bea5959de5778aaaf33a94f8c1e2e (patch)
treefe8cac8d619895feaa69a4e3678f1edd9d4945c4 /test/gtest_catch_exceptions_test_.cc
parenta9f380f5c7ff75cd715c58e11885dddc54baef02 (diff)
downloadgoogletest-35c39756495bea5959de5778aaaf33a94f8c1e2e.tar.gz
googletest-35c39756495bea5959de5778aaaf33a94f8c1e2e.tar.bz2
googletest-35c39756495bea5959de5778aaaf33a94f8c1e2e.zip
Casts char to unsigned char before calling isspace() etc to avoid undefined behavior (by Zhanyong Wan); removes conditional #includes keyed on GTEST_HAS_PROTOBUF_ (by Zhanyong Wan); publishes GTEST_HAS_STREAM_REDIRECTION (by Vlad Losev); forward declares some classes properly (by Samuel Benzaquen); honors the --gtest_catch_exceptions flag (by Vlad Losev).
Diffstat (limited to 'test/gtest_catch_exceptions_test_.cc')
-rw-r--r--test/gtest_catch_exceptions_test_.cc17
1 files changed, 13 insertions, 4 deletions
diff --git a/test/gtest_catch_exceptions_test_.cc b/test/gtest_catch_exceptions_test_.cc
index 86736811..2ba6eb44 100644
--- a/test/gtest_catch_exceptions_test_.cc
+++ b/test/gtest_catch_exceptions_test_.cc
@@ -35,17 +35,18 @@
#include <gtest/gtest.h>
#include <stdio.h> // NOLINT
+#include <stdlib.h> // For exit().
#if GTEST_HAS_SEH
#include <windows.h>
#endif
#if GTEST_HAS_EXCEPTIONS
+#include <exception> // For set_terminate().
#include <stdexcept>
#endif
using testing::Test;
-using testing::GTEST_FLAG(catch_exceptions);
#if GTEST_HAS_SEH
@@ -287,12 +288,20 @@ TEST(CxxExceptionTest, ThrowsNonStdCxxException) {
throw "C-string";
}
+// 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(3);
+}
+
#endif // GTEST_HAS_EXCEPTIONS
int main(int argc, char** argv) {
-#if GTEST_HAS_SEH
- // Tells Google Test to catch SEH-style exceptions on Windows.
- GTEST_FLAG(catch_exceptions) = true;
+#if GTEST_HAS_EXCEPTIONS
+ std::set_terminate(&TerminateHandler);
#endif
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();