summaryrefslogtreecommitdiffstats
path: root/googletest/include/gtest/internal/gtest-internal.h
diff options
context:
space:
mode:
authorJonny007-MKD <me@jonny007-mkd.de>2018-09-14 21:22:04 (GMT)
committerJonny007-MKD <me@jonny007-mkd.de>2018-09-14 21:22:04 (GMT)
commit6494f5232b130a29321e661166442bac324c4383 (patch)
treea641bcc7d9d5513c83d463a6194950aeb5344df0 /googletest/include/gtest/internal/gtest-internal.h
parent631e3a58389a21bec310470b7788b30dfa17a217 (diff)
downloadgoogletest-6494f5232b130a29321e661166442bac324c4383.zip
googletest-6494f5232b130a29321e661166442bac324c4383.tar.gz
googletest-6494f5232b130a29321e661166442bac324c4383.tar.bz2
Print message of unexpected std::exception in EXPECT_THROW, too
Diffstat (limited to 'googletest/include/gtest/internal/gtest-internal.h')
-rw-r--r--googletest/include/gtest/internal/gtest-internal.h38
1 files changed, 25 insertions, 13 deletions
diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h
index da3ebd2..5a1181a 100644
--- a/googletest/include/gtest/internal/gtest-internal.h
+++ b/googletest/include/gtest/internal/gtest-internal.h
@@ -1194,7 +1194,7 @@ class AdditionalMessage
public:
AdditionalMessage(const char* message) : value(message) {}
AdditionalMessage& operator=(const std::string& message) { value = message; return *this; }
- operator bool() const { return ::testing::internal::AlwaysTrue(); }
+ operator bool() const { return true; }
const std::string& get() const { return value; }
@@ -1229,29 +1229,41 @@ private:
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
- if (::testing::internal::ConstCharPtr gtest_msg = "") { \
+ if (::testing::internal::AdditionalMessage message = "") { \
bool gtest_caught_expected = false; \
try { \
- GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ try { \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ } \
+ catch (expected_exception const&) { \
+ gtest_caught_expected = true; \
+ throw; \
+ } \
} \
- catch (expected_exception const&) { \
- gtest_caught_expected = true; \
+ catch (const std::exception& e) { \
+ if (!gtest_caught_expected) { \
+ message = \
+ "it throws a different type " \
+ "with message: " + std::string(e.what()); \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
+ } \
} \
catch (...) { \
- gtest_msg.value = \
- "Expected: " #statement " throws an exception of type " \
- #expected_exception ".\n Actual: it throws a different type."; \
- goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
+ if (!gtest_caught_expected) { \
+ message = \
+ "it throws a different type."; \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
+ } \
} \
if (!gtest_caught_expected) { \
- gtest_msg.value = \
- "Expected: " #statement " throws an exception of type " \
- #expected_exception ".\n Actual: it throws nothing."; \
+ message = \
+ "it throws nothing."; \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
} \
} else \
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
- fail(gtest_msg.value)
+ fail(("Expected: " #statement " throws an exception of type " \
+ #expected_exception ".\n Actual: " + message.get()).c_str())
#define GTEST_TEST_NO_THROW_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \