summaryrefslogtreecommitdiffstats
path: root/googletest/test/googletest-printers-test.cc
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2022-10-14 17:32:14 (GMT)
committerCopybara-Service <copybara-worker@google.com>2022-10-14 17:32:49 (GMT)
commit137b6e2770deb44aacd229c20507413120655b22 (patch)
tree951fba6e4571ade162263cfeea6c37ec1177fd38 /googletest/test/googletest-printers-test.cc
parent67174c7675fe500644490c49e8c822173f7e1f9a (diff)
downloadgoogletest-137b6e2770deb44aacd229c20507413120655b22.zip
googletest-137b6e2770deb44aacd229c20507413120655b22.tar.gz
googletest-137b6e2770deb44aacd229c20507413120655b22.tar.bz2
Terse printing of std::reference_wrapper hides pointer
This matches the intention and documentation of terse printing which generally avoids printing the pointer. PiperOrigin-RevId: 481178950 Change-Id: I27039dac1870934d2d5b212e2cc7e97ab82c5b34
Diffstat (limited to 'googletest/test/googletest-printers-test.cc')
-rw-r--r--googletest/test/googletest-printers-test.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc
index acfecf9..d2d88a5 100644
--- a/googletest/test/googletest-printers-test.cc
+++ b/googletest/test/googletest-printers-test.cc
@@ -37,6 +37,7 @@
#include <cstring>
#include <deque>
#include <forward_list>
+#include <functional>
#include <limits>
#include <list>
#include <map>
@@ -193,6 +194,11 @@ OutputStream& operator<<(OutputStream& os,
return os;
}
+struct StreamableInLocal {};
+void operator<<(::std::ostream& os, const StreamableInLocal& /* x */) {
+ os << "StreamableInLocal";
+}
+
// A user-defined streamable but recursively-defined container type in
// a user namespace, it mimics therefore std::filesystem::path or
// boost::filesystem::path.
@@ -1604,6 +1610,23 @@ TEST(PrintToStringTest, ContainsNonLatin) {
"\n As Text: \"From ä — ẑ\"");
}
+TEST(PrintToStringTest, PrintStreamableInLocal) {
+ EXPECT_STREQ("StreamableInLocal",
+ PrintToString(foo::StreamableInLocal()).c_str());
+}
+
+TEST(PrintToStringTest, PrintReferenceToStreamableInLocal) {
+ foo::StreamableInLocal s;
+ std::reference_wrapper<foo::StreamableInLocal> r(s);
+ EXPECT_STREQ("StreamableInLocal", PrintToString(r).c_str());
+}
+
+TEST(PrintToStringTest, PrintReferenceToStreamableInGlobal) {
+ StreamableInGlobal s;
+ std::reference_wrapper<StreamableInGlobal> r(s);
+ EXPECT_STREQ("StreamableInGlobal", PrintToString(r).c_str());
+}
+
TEST(IsValidUTF8Test, IllFormedUTF8) {
// The following test strings are ill-formed UTF-8 and are printed
// as hex only (or ASCII, in case of ASCII bytes) because IsValidUTF8() is