diff options
author | Abseil Team <absl-team@google.com> | 2018-09-17 14:42:55 (GMT) |
---|---|---|
committer | gennadiycivil <misterg@google.com> | 2018-09-20 15:01:16 (GMT) |
commit | 1b20bd176fb3bc6feef4ab17488a2ac8850f42dd (patch) | |
tree | d3758fb385322e4e31d1f3526dfaeecc7643f391 /googletest/include/gtest/internal/gtest-internal.h | |
parent | 9ea01728503a445179353113d2854492f41bee84 (diff) | |
download | googletest-1b20bd176fb3bc6feef4ab17488a2ac8850f42dd.zip googletest-1b20bd176fb3bc6feef4ab17488a2ac8850f42dd.tar.gz googletest-1b20bd176fb3bc6feef4ab17488a2ac8850f42dd.tar.bz2 |
Googletest export
support printing std::reference_wrapper<T> in gUnit
PiperOrigin-RevId: 213270392
Diffstat (limited to 'googletest/include/gtest/internal/gtest-internal.h')
-rw-r--r-- | googletest/include/gtest/internal/gtest-internal.h | 56 |
1 files changed, 15 insertions, 41 deletions
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_ \ |