summaryrefslogtreecommitdiffstats
path: root/googletest/include/gtest/internal
diff options
context:
space:
mode:
authorJonny007-MKD <me@jonny007-mkd.de>2018-09-23 13:15:38 (GMT)
committerJonny007-MKD <me@jonny007-mkd.de>2018-09-23 13:15:38 (GMT)
commit1cb10b357a8a96b54ae60d4103918892f58d7fb3 (patch)
tree0f974c09429f23f55a838cd2720819348ac669d5 /googletest/include/gtest/internal
parent258def01a68e3a4d080fee6d4502035218e61e38 (diff)
downloadgoogletest-1cb10b357a8a96b54ae60d4103918892f58d7fb3.zip
googletest-1cb10b357a8a96b54ae60d4103918892f58d7fb3.tar.gz
googletest-1cb10b357a8a96b54ae60d4103918892f58d7fb3.tar.bz2
Readded changes from 6494f5232b130a29321e661166442bac324c4383
Diffstat (limited to 'googletest/include/gtest/internal')
-rw-r--r--googletest/include/gtest/internal/gtest-internal.h56
1 files changed, 41 insertions, 15 deletions
diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h
index b762f61..0dbf100 100644
--- a/googletest/include/gtest/internal/gtest-internal.h
+++ b/googletest/include/gtest/internal/gtest-internal.h
@@ -1189,6 +1189,19 @@ class NativeArray {
GTEST_DISALLOW_ASSIGN_(NativeArray);
};
+class AdditionalMessage
+{
+public:
+ AdditionalMessage(const char* message) : value(message) {}
+ void set(const std::string& message) { value = message; }
+ operator bool() const { return true; }
+
+ const std::string& get() const { return value; }
+
+private:
+ std::string value;
+};
+
} // namespace internal
} // namespace testing
@@ -1216,43 +1229,56 @@ class NativeArray {
#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.set("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.set("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.set("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_ \
- if (::testing::internal::AlwaysTrue()) { \
+ if (::testing::internal::AdditionalMessage message = ".") { \
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \
+ catch (const std::exception& e) { \
+ message.set(std::string(": ") + e.what()); \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
+ } \
catch (...) { \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
} \
} else \
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
- fail("Expected: " #statement " doesn't throw an exception.\n" \
- " Actual: it throws.")
+ fail(("Expected: " #statement " doesn't throw an exception.\n" \
+ " Actual: it throws" + message.get()).c_str())
#define GTEST_TEST_ANY_THROW_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \