summaryrefslogtreecommitdiffstats
path: root/llvm/utils/unittest/googletest/include/gtest
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2019-08-21 13:56:29 +0000
committerSam McCall <sam.mccall@gmail.com>2019-08-21 13:56:29 +0000
commita451156bb6ceb3700f6ea42e47e9a95d67723318 (patch)
tree4227645ea627fffc6f82efaaec49e7573e954211 /llvm/utils/unittest/googletest/include/gtest
parent4d668a1f077d1ddea6130c52f793817063046b68 (diff)
downloadbcm5719-llvm-a451156bb6ceb3700f6ea42e47e9a95d67723318.tar.gz
bcm5719-llvm-a451156bb6ceb3700f6ea42e47e9a95d67723318.zip
reland [gtest] Fix printing of StringRef and SmallString in assert messages.
Renames GTEST_NO_LLVM_RAW_OSTREAM -> GTEST_NO_LLVM_SUPPORT and guards the new features behind it. This reverts commit a063bcf3ef5a879adbe9639a3c187d876eee0e66. llvm-svn: 369527
Diffstat (limited to 'llvm/utils/unittest/googletest/include/gtest')
-rw-r--r--llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-printers.h27
-rw-r--r--llvm/utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h4
2 files changed, 29 insertions, 2 deletions
diff --git a/llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-printers.h b/llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-printers.h
index 60c1ea050b6..d4ae0834100 100644
--- a/llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-printers.h
+++ b/llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-printers.h
@@ -39,4 +39,31 @@
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
+#if !GTEST_NO_LLVM_SUPPORT
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include <ostream>
+// Printing of llvm String types.
+// gtest sees these as containers of char (they have nested iterator types),
+// so their operator<< is never considered unless we provide PrintTo().
+// PrintStringTo provides quotes and escaping, at the cost of a copy.
+namespace llvm {
+inline void PrintTo(llvm::StringRef S, std::ostream *OS) {
+ *OS << ::testing::PrintToString(S.str());
+}
+// We need both SmallString<N> and SmallVectorImpl<char> overloads:
+// - the SmallString<N> template is needed as overload resolution will
+// instantiate generic PrintTo<T> rather than do derived-to-base conversion
+// - but SmallVectorImpl<char> is sometimes the actual static type, in code
+// that erases the small size
+template <unsigned N>
+inline void PrintTo(const SmallString<N> &S, std::ostream *OS) {
+ *OS << ::testing::PrintToString(std::string(S.data(), S.size()));
+}
+inline void PrintTo(const SmallVectorImpl<char> &S, std::ostream *OS) {
+ *OS << ::testing::PrintToString(std::string(S.data(), S.size()));
+}
+} // namespace llvm
+#endif // !GTEST_NO_LLVM_SUPPORT
+
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
diff --git a/llvm/utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h b/llvm/utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h
index a9837c5037c..72f23184abd 100644
--- a/llvm/utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h
+++ b/llvm/utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h
@@ -40,7 +40,7 @@ auto printable(const T &V) -> decltype(StreamSwitch<T>::printable(V)) {
// If raw_ostream support is enabled, we specialize for types with operator<<
// that takes a raw_ostream.
-#if !GTEST_NO_LLVM_RAW_OSTREAM
+#if !GTEST_NO_LLVM_SUPPORT
#include "llvm/ADT/Optional.h"
#include "llvm/Support/raw_os_ostream.h"
#include "llvm/Support/raw_ostream.h"
@@ -81,6 +81,6 @@ struct StreamSwitch<llvm::Optional<T>,
}
};
} // namespace llvm_gtest
-#endif // !GTEST_NO_LLVM_RAW_OSTREAM
+#endif // !GTEST_NO_LLVM_SUPPORT
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_RAW_OSTREAM_H_
OpenPOWER on IntegriCloud