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/unittests/ADT/SmallStringTest.cpp | |
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/unittests/ADT/SmallStringTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/SmallStringTest.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/llvm/unittests/ADT/SmallStringTest.cpp b/llvm/unittests/ADT/SmallStringTest.cpp index 6868381c5cf..686215fd223 100644 --- a/llvm/unittests/ADT/SmallStringTest.cpp +++ b/llvm/unittests/ADT/SmallStringTest.cpp @@ -169,7 +169,7 @@ TEST_F(SmallStringTest, Realloc) { EXPECT_EQ("abcdyyy", theString.slice(0, 7)); } -TEST(StringRefTest, Comparisons) { +TEST_F(SmallStringTest, Comparisons) { EXPECT_EQ(-1, SmallString<10>("aab").compare("aad")); EXPECT_EQ( 0, SmallString<10>("aab").compare("aab")); EXPECT_EQ( 1, SmallString<10>("aab").compare("aaa")); @@ -203,4 +203,12 @@ TEST(StringRefTest, Comparisons) { EXPECT_EQ( 1, SmallString<10>("V8_q0").compare_numeric("V1_q0")); } +// Check gtest prints SmallString as a string instead of a container of chars. +// The code is in utils/unittest/googletest/internal/custom/gtest-printers.h +TEST_F(SmallStringTest, GTestPrinter) { + EXPECT_EQ(R"("foo")", ::testing::PrintToString(SmallString<1>("foo"))); + const SmallVectorImpl<char> &ErasedSmallString = SmallString<1>("foo"); + EXPECT_EQ(R"("foo")", ::testing::PrintToString(ErasedSmallString)); } + +} // namespace |