From 37504994338c114247519331237831f88a9a7c40 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 6 Feb 2009 00:47:20 +0000 Subject: Adds tests for EXPECT_FATAL_FAILURE and reduces the golden file bloat (by Zhanyong Wan). Fixes more warnings on Windows (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 541c89b8..b28da96e 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -749,7 +749,7 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); int GetFailedPartCount(const TestResult* result); // A helper for suppressing warnings on unreachable code in some macros. -inline bool True() { return true; } +bool AlwaysTrue(); } // namespace internal } // namespace testing @@ -767,12 +767,18 @@ inline bool True() { return true; } #define GTEST_SUCCESS_(message) \ GTEST_MESSAGE_(message, ::testing::TPRT_SUCCESS) +// Suppresses MSVC warnings 4072 (unreachable code) for the code following +// statement if it returns or throws (or doesn't return or throw in some +// situations). +#define GTEST_HIDE_UNREACHABLE_CODE_(statement) \ + if (::testing::internal::AlwaysTrue()) { statement; } + #define GTEST_TEST_THROW_(statement, expected_exception, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ bool gtest_caught_expected = false; \ try { \ - statement; \ + GTEST_HIDE_UNREACHABLE_CODE_(statement); \ } \ catch (expected_exception const&) { \ gtest_caught_expected = true; \ @@ -796,7 +802,7 @@ inline bool True() { return true; } GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ try { \ - statement; \ + GTEST_HIDE_UNREACHABLE_CODE_(statement); \ } \ catch (...) { \ gtest_msg = "Expected: " #statement " doesn't throw an exception.\n" \ @@ -812,7 +818,7 @@ inline bool True() { return true; } if (const char* gtest_msg = "") { \ bool gtest_caught_any = false; \ try { \ - statement; \ + GTEST_HIDE_UNREACHABLE_CODE_(statement); \ } \ catch (...) { \ gtest_caught_any = true; \ @@ -838,7 +844,7 @@ inline bool True() { return true; } GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ - if (::testing::internal::True()) { statement; } \ + GTEST_HIDE_UNREACHABLE_CODE_(statement); \ if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ gtest_msg = "Expected: " #statement " doesn't generate new fatal " \ "failures in the current thread.\n" \ -- cgit v1.2.3