summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compiler-rt/cmake/Modules/AddCompilerRT.cmake4
-rw-r--r--compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp4
-rw-r--r--llvm/unittests/ADT/SmallStringTest.cpp10
-rw-r--r--llvm/unittests/ADT/StringRefTest.cpp6
-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
6 files changed, 48 insertions, 7 deletions
diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index f7ee932f214..322e4221a81 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -360,7 +360,7 @@ set(COMPILER_RT_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_CFLAGS})
set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc)
set(COMPILER_RT_GTEST_CFLAGS
- -DGTEST_NO_LLVM_RAW_OSTREAM=1
+ -DGTEST_NO_LLVM_SUPPORT=1
-DGTEST_HAS_RTTI=0
-I${COMPILER_RT_GTEST_PATH}/include
-I${COMPILER_RT_GTEST_PATH}
@@ -370,7 +370,7 @@ set(COMPILER_RT_GTEST_CFLAGS
set(COMPILER_RT_GMOCK_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock)
set(COMPILER_RT_GMOCK_SOURCE ${COMPILER_RT_GMOCK_PATH}/src/gmock-all.cc)
set(COMPILER_RT_GMOCK_CFLAGS
- -DGTEST_NO_LLVM_RAW_OSTREAM=1
+ -DGTEST_NO_LLVM_SUPPORT=1
-DGTEST_HAS_RTTI=0
-I${COMPILER_RT_GMOCK_PATH}/include
-I${COMPILER_RT_GMOCK_PATH}
diff --git a/compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp b/compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp
index abb203d5140..7fc4b9a55b0 100644
--- a/compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp
+++ b/compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp
@@ -6,8 +6,8 @@
// with ASan) involving C++ standard library types when using libcxx.
#define _LIBCPP_HAS_NO_ASAN
-// Do not attempt to use LLVM ostream from gtest.
-#define GTEST_NO_LLVM_RAW_OSTREAM 1
+// Do not attempt to use LLVM ostream etc from gtest.
+#define GTEST_NO_LLVM_SUPPORT 1
#include "FuzzerCorpus.h"
#include "FuzzerDictionary.h"
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
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp
index a45e83c1163..f341cf402a0 100644
--- a/llvm/unittests/ADT/StringRefTest.cpp
+++ b/llvm/unittests/ADT/StringRefTest.cpp
@@ -1055,6 +1055,12 @@ TEST(StringRefTest, StringLiteral) {
EXPECT_EQ(StringRef("Bar"), Strings[1]);
}
+// Check gtest prints StringRef as a string instead of a container of chars.
+// The code is in utils/unittest/googletest/internal/custom/gtest-printers.h
+TEST(StringRefTest, GTestPrinter) {
+ EXPECT_EQ(R"("foo")", ::testing::PrintToString(StringRef("foo")));
+}
+
static_assert(is_trivially_copyable<StringRef>::value, "trivially copyable");
} // end anonymous namespace
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