diff options
author | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2010-09-27 17:44:16 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2010-09-27 17:44:16 +0000 |
commit | 736baa8ac028f01a5c79ebecb6fc7043b47d3c4e (patch) | |
tree | 2ce1a86efd7d158d649842382c4ea11c64542a60 /include/gmock/gmock-matchers.h | |
parent | 4c91551c3b342ec58910f3622297217615b0afb3 (diff) | |
download | googletest-736baa8ac028f01a5c79ebecb6fc7043b47d3c4e.tar.gz googletest-736baa8ac028f01a5c79ebecb6fc7043b47d3c4e.tar.bz2 googletest-736baa8ac028f01a5c79ebecb6fc7043b47d3c4e.zip |
Prints the type of the actual value as part of a match message when appropriate.
Diffstat (limited to 'include/gmock/gmock-matchers.h')
-rw-r--r-- | include/gmock/gmock-matchers.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/include/gmock/gmock-matchers.h b/include/gmock/gmock-matchers.h index 1938be90..627f3ff0 100644 --- a/include/gmock/gmock-matchers.h +++ b/include/gmock/gmock-matchers.h @@ -461,6 +461,16 @@ inline void PrintIfNotEmpty(const internal::string& explanation, } } +// Returns true if the given type name is easy to read by a human. +// This is used to decide whether printing the type of a value might +// be helpful. +inline bool IsReadableTypeName(const string& type_name) { + // We consider a type name readable if it's short or doesn't contain + // a template or function type. + return (type_name.length() <= 20 || + type_name.find_first_of("<(") == string::npos); +} + // Matches the value against the given matcher, prints the value and explains // the match result to the listener. Returns the match result. // 'listener' must not be NULL. @@ -479,6 +489,11 @@ bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher, const bool match = matcher.MatchAndExplain(value, &inner_listener); UniversalPrint(value, listener->stream()); +#if GTEST_HAS_RTTI + const string& type_name = GetTypeName<Value>(); + if (IsReadableTypeName(type_name)) + *listener->stream() << " (of type " << type_name << ")"; +#endif PrintIfNotEmpty(inner_listener.str(), listener->stream()); return match; |