summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2021-09-28 16:50:05 (GMT)
committerCJ Johnson <johnsoncj@google.com>2021-09-28 20:33:40 (GMT)
commitab36804e42d4cb85b7e7fe9946928597840684db (patch)
treefea34ceaee0a3e33e9546b2126386071ee876a82
parente4717df71a4f45bf9f0ac88c6cd9846a0bc248dd (diff)
downloadgoogletest-ab36804e42d4cb85b7e7fe9946928597840684db.zip
googletest-ab36804e42d4cb85b7e7fe9946928597840684db.tar.gz
googletest-ab36804e42d4cb85b7e7fe9946928597840684db.tar.bz2
Googletest export
Ensure `.what()` is printed in `ThrowsMessage(...)` to address https://github.com/google/googletest/issues/3582 Closes #3582 PiperOrigin-RevId: 399462851
-rw-r--r--googlemock/include/gmock/gmock-matchers.h3
-rw-r--r--googlemock/test/gmock-matchers_test.cc15
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;