Merge pull request #3581 from cclauss:codespell
PiperOrigin-RevId: 400792845
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index 6863560..d952369 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -5266,7 +5266,8 @@
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 3af3d71..d1505bf 100644
--- a/googlemock/test/gmock-matchers_test.cc
+++ b/googlemock/test/gmock-matchers_test.cc
@@ -8515,6 +8515,12 @@
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 @@
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;
diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h
index 2e33df4..98d0494 100644
--- a/googletest/include/gtest/gtest-printers.h
+++ b/googletest/include/gtest/gtest-printers.h
@@ -742,6 +742,14 @@
}
};
+template <>
+class UniversalPrinter<decltype(Nullopt())> {
+ public:
+ static void Print(decltype(Nullopt()), ::std::ostream* os) {
+ *os << "(nullopt)";
+ }
+};
+
#endif // GTEST_INTERNAL_HAS_OPTIONAL
#if GTEST_INTERNAL_HAS_VARIANT
diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h
index e8a6b51..d3eab57 100644
--- a/googletest/include/gtest/internal/gtest-port.h
+++ b/googletest/include/gtest/internal/gtest-port.h
@@ -2325,6 +2325,7 @@
namespace internal {
template <typename T>
using Optional = ::absl::optional<T>;
+inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; }
} // namespace internal
} // namespace testing
#else
@@ -2338,6 +2339,7 @@
namespace internal {
template <typename T>
using Optional = ::std::optional<T>;
+inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }
} // namespace internal
} // namespace testing
// The case where absl is configured NOT to alias std::optional is not
diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc
index e1e8e1c..9c9a223 100644
--- a/googletest/test/googletest-printers-test.cc
+++ b/googletest/test/googletest-printers-test.cc
@@ -1873,6 +1873,7 @@
#if GTEST_INTERNAL_HAS_OPTIONAL
TEST(PrintOptionalTest, Basic) {
+ EXPECT_EQ("(nullopt)", PrintToString(internal::Nullopt()));
internal::Optional<int> value;
EXPECT_EQ("(nullopt)", PrintToString(value));
value = {7};