llvm.org GIT mirror llvm / a26ebc8
Revert "[gtest] Fix printing of StringRef and SmallString in assert messages." This reverts commit 4becb2ab4e9f52ce98272d1f5930d6942af5172b. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369525 91177308-0d34-0410-b5e6-96231b3b80d8 Sam McCall a month ago
3 changed file(s) with 2 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
168168 EXPECT_EQ("abcdyyy", theString.slice(0, 7));
169169 }
170170
171 TEST_F(SmallStringTest, Comparisons) {
171 TEST(StringRefTest, Comparisons) {
172172 EXPECT_EQ(-1, SmallString<10>("aab").compare("aad"));
173173 EXPECT_EQ( 0, SmallString<10>("aab").compare("aab"));
174174 EXPECT_EQ( 1, SmallString<10>("aab").compare("aaa"));
202202 EXPECT_EQ( 1, SmallString<10>("V8_q0").compare_numeric("V1_q0"));
203203 }
204204
205 // Check gtest prints SmallString as a string instead of a container of chars.
206 // The code is in utils/unittest/googletest/internal/custom/gtest-printers.h
207 TEST_F(SmallStringTest, GTestPrinter) {
208 EXPECT_EQ(R"("foo")", ::testing::PrintToString(SmallString<1>("foo")));
209 const SmallVectorImpl &ErasedSmallString = SmallString<1>("foo");
210 EXPECT_EQ(R"("foo")", ::testing::PrintToString(ErasedSmallString));
211 }
212
213 } // namespace
205 }
10541054 EXPECT_EQ(StringRef("Bar"), Strings[1]);
10551055 }
10561056
1057 // Check gtest prints StringRef as a string instead of a container of chars.
1058 // The code is in utils/unittest/googletest/internal/custom/gtest-printers.h
1059 TEST(StringRefTest, GTestPrinter) {
1060 EXPECT_EQ(R"("foo")", ::testing::PrintToString(StringRef("foo")));
1061 }
1062
10631057 static_assert(is_trivially_copyable::value, "trivially copyable");
10641058
10651059 } // end anonymous namespace
3838 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
3939 #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
4040
41 #include "llvm/ADT/SmallString.h"
42 #include "llvm/ADT/StringRef.h"
43 #include
44
45 namespace llvm {
46
47 // Printing of llvm String types.
48 // gtest sees these as containers of char (they have nested iterator types),
49 // so their operator<< is never considered unless we provide PrintTo().
50 // PrintStringTo provides quotes and escaping, at the cost of a copy.
51
52 inline void PrintTo(llvm::StringRef S, std::ostream *OS) {
53 *OS << ::testing::PrintToString(S.str());
54 }
55 // We need both SmallString and SmallVectorImpl overloads:
56 // - the SmallString template is needed as overload resolution will
57 // instantiate generic PrintTo rather than do derived-to-base conversion
58 // - but SmallVectorImpl is sometimes the actual static type, in code
59 // that erases the small size
60 template
61 inline void PrintTo(const SmallString &S, std::ostream *OS) {
62 *OS << ::testing::PrintToString(std::string(S.data(), S.size()));
63 }
64 inline void PrintTo(const SmallVectorImpl &S, std::ostream *OS) {
65 *OS << ::testing::PrintToString(std::string(S.data(), S.size()));
66 }
67
68 } // namespace llvm
69
7041 #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_