diff options
author | Jonny007-MKD <me@jonny007-mkd.de> | 2018-09-13 08:24:10 (GMT) |
---|---|---|
committer | Jonny007-MKD <me@jonny007-mkd.de> | 2018-09-13 08:24:10 (GMT) |
commit | 0354ccb049ea2b9e4696adb8b5a013287daf0c33 (patch) | |
tree | 095bb31d7647df81162f3d75aefe661e4f659260 /googletest/include/gtest/internal/gtest-internal.h | |
parent | 5131cf737cf3a4d81923c9c72536a07384292cd7 (diff) | |
download | googletest-0354ccb049ea2b9e4696adb8b5a013287daf0c33.zip googletest-0354ccb049ea2b9e4696adb8b5a013287daf0c33.tar.gz googletest-0354ccb049ea2b9e4696adb8b5a013287daf0c33.tar.bz2 |
Added special catch for std::exception in GTEST_TEST_NO_THROW_
Diffstat (limited to 'googletest/include/gtest/internal/gtest-internal.h')
-rw-r--r-- | googletest/include/gtest/internal/gtest-internal.h | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index b762f61..b968fb1 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 std::string& message) : value(message) {} + AdditionalMessage& operator=(const std::string& message) { value = message; return *this; } + operator bool() const { return ::testing::internal::AlwaysTrue(); } + + const std::string& get() const { return value; } + +private: + std::string value; +}; + } // namespace internal } // namespace testing @@ -1242,17 +1255,21 @@ class NativeArray { #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 = 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_ \ |