diff options
Diffstat (limited to 'googletest/include/gtest')
-rw-r--r-- | googletest/include/gtest/gtest-printers.h | 8 | ||||
-rw-r--r-- | googletest/include/gtest/internal/gtest-internal.h | 56 |
2 files changed, 23 insertions, 41 deletions
diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 51865f8..59d2d91 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -639,7 +639,15 @@ inline void PrintTo(absl::string_view sp, ::std::ostream* os) { #endif // GTEST_HAS_ABSL #if GTEST_LANG_CXX11 + inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; } + +template <typename T> +void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) { + // Delegate to wrapped value. + PrintTo(ref.get(), os); +} + #endif // GTEST_LANG_CXX11 #if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_ diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 0dbf100..b762f61 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1189,19 +1189,6 @@ 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 @@ -1229,56 +1216,43 @@ private: #define GTEST_TEST_THROW_(statement, expected_exception, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::AdditionalMessage message = "") { \ + if (::testing::internal::ConstCharPtr gtest_msg = "") { \ bool gtest_caught_expected = false; \ try { \ - try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } \ - catch (expected_exception const&) { \ - gtest_caught_expected = true; \ - throw; \ - } \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ - 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 (expected_exception const&) { \ + gtest_caught_expected = true; \ } \ catch (...) { \ - if (!gtest_caught_expected) { \ - message.set("it throws a different type."); \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ - } \ + 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 nothing."); \ + gtest_msg.value = \ + "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws nothing."; \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } else \ GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ - fail(("Expected: " #statement " throws an exception of type " \ - #expected_exception ".\n Actual: " + message.get()).c_str()) + fail(gtest_msg.value) #define GTEST_TEST_NO_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::AdditionalMessage message = ".") { \ + if (::testing::internal::AlwaysTrue()) { \ 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" + message.get()).c_str()) + fail("Expected: " #statement " doesn't throw an exception.\n" \ + " Actual: it throws.") #define GTEST_TEST_ANY_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |