Googletest export
Ensure `.what()` is printed in `ThrowsMessage(...)` to address https://github.com/google/googletest/issues/3582 Closes #3582 PiperOrigin-RevId: 399462851
This commit is contained in:
		@@ -5266,7 +5266,8 @@ class WithWhatMatcherImpl {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  template <typename Err>
 | 
					  template <typename Err>
 | 
				
			||||||
  bool MatchAndExplain(const Err& err, MatchResultListener* listener) const {
 | 
					  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);
 | 
					    return matcher_.MatchAndExplain(err.what(), listener);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8515,6 +8515,12 @@ TEST(ThrowsTest, Examples) {
 | 
				
			|||||||
      ThrowsMessage<std::runtime_error>(HasSubstr("message")));
 | 
					      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) {
 | 
					TEST(ThrowsTest, DoesNotGenerateDuplicateCatchClauseWarning) {
 | 
				
			||||||
  EXPECT_THAT(std::function<void()>([]() { throw std::exception(); }),
 | 
					  EXPECT_THAT(std::function<void()>([]() { throw std::exception(); }),
 | 
				
			||||||
              Throws<std::exception>());
 | 
					              Throws<std::exception>());
 | 
				
			||||||
@@ -8630,15 +8636,6 @@ TEST_P(ThrowsPredicateTest, FailWrongTypeNonStd) {
 | 
				
			|||||||
              HasSubstr("throws an exception of an unknown type"));
 | 
					              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) {
 | 
					TEST_P(ThrowsPredicateTest, FailNoThrow) {
 | 
				
			||||||
  Matcher<std::function<void()>> matcher = GetParam();
 | 
					  Matcher<std::function<void()>> matcher = GetParam();
 | 
				
			||||||
  StringMatchResultListener listener;
 | 
					  StringMatchResultListener listener;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user