diff options
author | Abseil Team <absl-team@google.com> | 2018-09-17 10:42:55 -0400 |
---|---|---|
committer | gennadiycivil <misterg@google.com> | 2018-09-20 11:01:16 -0400 |
commit | 1b20bd176fb3bc6feef4ab17488a2ac8850f42dd (patch) | |
tree | d3758fb385322e4e31d1f3526dfaeecc7643f391 /googletest/include | |
parent | 9ea01728503a445179353113d2854492f41bee84 (diff) | |
download | googletest-1b20bd176fb3bc6feef4ab17488a2ac8850f42dd.tar.gz googletest-1b20bd176fb3bc6feef4ab17488a2ac8850f42dd.zip |
Googletest export
support printing std::reference_wrapper<T> in gUnit
PiperOrigin-RevId: 213270392
Diffstat (limited to 'googletest/include')
-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 51865f84..59d2d918 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 0dbf100c..b762f61f 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_ \ |