diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 7db65a48..d12d7bf7 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1453,7 +1453,7 @@ class TrulyMatcher { // interested in the address of the argument. template bool MatchAndExplain(T& x, // NOLINT - MatchResultListener* /* listener */) const { + MatchResultListener* listener) const { // Without the if-statement, MSVC sometimes warns about converting // a value to bool (warning 4800). // @@ -1462,6 +1462,7 @@ class TrulyMatcher { // having no operator!(). if (predicate_(x)) return true; + *listener << "didn't satisfy the given predicate"; return false; } diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 0ce5b588..b7e253d7 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2984,6 +2984,13 @@ TEST(TrulyTest, WorksForByRefArguments) { EXPECT_FALSE(m.Matches(n)); } +// Tests that Truly(predicate) provides a helpful reason when it fails. +TEST(TrulyTest, ExplainsFailures) { + StringMatchResultListener listener; + EXPECT_FALSE(ExplainMatchResult(Truly(IsPositive), -1, &listener)); + EXPECT_EQ(listener.str(), "didn't satisfy the given predicate"); +} + // Tests that Matches(m) is a predicate satisfied by whatever that // matches matcher m. TEST(MatchesTest, IsSatisfiedByWhatMatchesTheMatcher) {