diff options
| author | Sam McCall <sam.mccall@gmail.com> | 2019-08-21 11:37:06 +0000 |
|---|---|---|
| committer | Sam McCall <sam.mccall@gmail.com> | 2019-08-21 11:37:06 +0000 |
| commit | 2fe9ce60640762f27294ae60c6b508a5bfb72f2b (patch) | |
| tree | 4a340bd9d046c2e7ced126199d7cdced76c20bc8 /llvm/utils | |
| parent | 82275ec51d00c33316506054faebb1033a9b7690 (diff) | |
| download | bcm5719-llvm-2fe9ce60640762f27294ae60c6b508a5bfb72f2b.tar.gz bcm5719-llvm-2fe9ce60640762f27294ae60c6b508a5bfb72f2b.zip | |
[gtest] Fix printing of StringRef and SmallString in assert messages.
Summary:
These are detected by gtest as containers, and so previously printed as e.g.
{ '.' (46, 0x2E), 's' (115, 0x73), 'e' (101, 0x65), 'c' (99, 0x63), '0' (48, 0x30) },
gtest itself overloads PrintTo for std::string and friends, we use the same mechanism.
Reviewers: labath
Subscribers: dexonsmith, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66520
llvm-svn: 369518
Diffstat (limited to 'llvm/utils')
| -rw-r--r-- | llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-printers.h | 29 |
1 files changed, 29 insertions, 0 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..da2b418525c 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,33 @@ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringRef.h" +#include <ostream> + +namespace llvm { + +// 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. + +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_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ |

