aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock/include/gmock/gmock-matchers.h
diff options
context:
space:
mode:
authorChris Johnson <chrisjohnsonmail@gmail.com>2018-12-14 13:11:15 -0600
committerGitHub <noreply@github.com>2018-12-14 13:11:15 -0600
commit130e5aa86a7a71501cf8fa7cd6f507928f01bd79 (patch)
tree2bc11702641f6bcca31032b4c343238d7b9178f6 /googlemock/include/gmock/gmock-matchers.h
parentfe14e3030737509c2b9f9adad80ff56f80e988a2 (diff)
parentb5f5c596a9915106c1ac36a3f89db4e0e49c07d1 (diff)
downloadgoogletest-130e5aa86a7a71501cf8fa7cd6f507928f01bd79.tar.gz
googletest-130e5aa86a7a71501cf8fa7cd6f507928f01bd79.tar.bz2
googletest-130e5aa86a7a71501cf8fa7cd6f507928f01bd79.zip
Merge pull request #2 from google/master
merge upstream/master into master
Diffstat (limited to 'googlemock/include/gmock/gmock-matchers.h')
-rw-r--r--googlemock/include/gmock/gmock-matchers.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index b859f1aa..68278bea 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -1296,14 +1296,24 @@ class PredicateFormatterFromMatcher {
// We don't write MatcherCast<const T&> either, as that allows
// potentially unsafe downcasting of the matcher argument.
const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
- StringMatchResultListener listener;
- if (MatchPrintAndExplain(x, matcher, &listener))
+
+ // The expected path here is that the matcher should match (i.e. that most
+ // tests pass) so optimize for this case.
+ if (matcher.Matches(x)) {
return AssertionSuccess();
+ }
::std::stringstream ss;
ss << "Value of: " << value_text << "\n"
<< "Expected: ";
matcher.DescribeTo(&ss);
+
+ // Rerun the matcher to "PrintAndExain" the failure.
+ StringMatchResultListener listener;
+ if (MatchPrintAndExplain(x, matcher, &listener)) {
+ ss << "\n The matcher failed on the initial attempt; but passed when "
+ "rerun to generate the explanation.";
+ }
ss << "\n Actual: " << listener.str();
return AssertionFailure() << ss.str();
}