[PATCH] D43330: [gtest] Add PrintTo overload for StringRef.

Ilya Biryukov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 02:48:47 PST 2018


ilya-biryukov created this revision.
ilya-biryukov added a reviewer: sammccall.

It was printed using code for generic containers before, resulting in
unreadable output.


Repository:
  rL LLVM

https://reviews.llvm.org/D43330

Files:
  utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h


Index: utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h
===================================================================
--- utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h
+++ utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h
@@ -42,8 +42,9 @@
 // If raw_ostream support is enabled, we specialize for types with operator<<
 // that takes a raw_ostream.
 #if !GTEST_NO_LLVM_RAW_OSTREAM
-#include "llvm/Support/raw_ostream.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_os_ostream.h"
+#include "llvm/Support/raw_ostream.h"
 #include <ostream>
 namespace llvm_gtest {
 
@@ -69,6 +70,16 @@
   static const RawStreamProxy<T> printable(const T &V) { return {V}; }
 };
 } // namespace llvm_gtest
-#endif  // !GTEST_NO_LLVM_RAW_OSTREAM
+
+namespace llvm {
+// Without this overload StringRef will be printed as a generic container.
+inline void PrintTo(const llvm::StringRef &Val, std::ostream *S) {
+  if (!S)
+    return;
+  llvm::raw_os_ostream OS(*S);
+  OS << Val;
+}
+} // namespace llvm
+#endif // !GTEST_NO_LLVM_RAW_OSTREAM
 
 #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_RAW_OSTREAM_H_


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43330.134395.patch
Type: text/x-patch
Size: 1172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180215/d4f75bdf/attachment.bin>


More information about the llvm-commits mailing list