diff options
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 3 | ||||
-rw-r--r-- | googlemock/test/gmock-matchers_test.cc | 15 |
2 files changed, 8 insertions, 10 deletions
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index d5bd4a9..0e4aa0b 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -5266,7 +5266,8 @@ class WithWhatMatcherImpl { template <typename Err> bool MatchAndExplain(const Err& err, MatchResultListener* listener) const { - *listener << "which contains .what() that "; + *listener << "which contains .what() (of value = " << err.what() + << ") that "; return matcher_.MatchAndExplain(err.what(), listener); } diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index cd5ae1a..4cec003 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -8515,6 +8515,12 @@ TEST(ThrowsTest, Examples) { ThrowsMessage<std::runtime_error>(HasSubstr("message"))); } +TEST(ThrowsTest, PrintsExceptionWhat) { + EXPECT_THAT( + std::function<void()>([]() { throw std::runtime_error("ABC123XYZ"); }), + ThrowsMessage<std::runtime_error>(HasSubstr("ABC123XYZ"))); +} + TEST(ThrowsTest, DoesNotGenerateDuplicateCatchClauseWarning) { EXPECT_THAT(std::function<void()>([]() { throw std::exception(); }), Throws<std::exception>()); @@ -8630,15 +8636,6 @@ TEST_P(ThrowsPredicateTest, FailWrongTypeNonStd) { HasSubstr("throws an exception of an unknown type")); } -TEST_P(ThrowsPredicateTest, FailWrongMessage) { - Matcher<std::function<void()>> matcher = GetParam(); - StringMatchResultListener listener; - EXPECT_FALSE(matcher.MatchAndExplain( - []() { throw std::runtime_error("wrong message"); }, &listener)); - EXPECT_THAT(listener.str(), HasSubstr("std::runtime_error")); - EXPECT_THAT(listener.str(), Not(HasSubstr("wrong message"))); -} - TEST_P(ThrowsPredicateTest, FailNoThrow) { Matcher<std::function<void()>> matcher = GetParam(); StringMatchResultListener listener; |