llvm.org GIT mirror llvm / 9c0c3bf
Teach googletest to use raw_ostream instead of just std::ostream. This can break when there are implicit conversions from types raw_ostream understands but std::ostream doesn't, but it increases the number of cases that Just Work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81093 91177308-0d34-0410-b5e6-96231b3b80d8 Jeffrey Yasskin 10 years ago
3 changed file(s) with 26 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1414 using namespace llvm;
1515
1616 namespace {
17
18 // Support APInt output to an std::ostream.
19 inline std::ostream &operator<<(std::ostream &OS, const APInt &Value) {
20 raw_os_ostream RawOS(OS);
21 RawOS << Value;
22 return OS;
23 }
2417
2518 class ConstantRangeTest : public ::testing::Test {
2619 protected:
2323 $ rm -f gtest-all.cc gtest_main.cc
2424
2525 $ mv COPYING LICENSE.TXT
26
27
28 Modified as follows:
29 * To GTestStreamToHelper in include/gtest/internal/gtest-internal.h,
30 added the ability to stream with raw_os_ostream.
5555 #include
5656 #include
5757
58 #include "llvm/Support/raw_os_ostream.h"
59
5860 // Due to C++ preprocessor weirdness, we need double indirection to
5961 // concatenate two tokens when one of them is __LINE__. Writing
6062 //
9193 // ::operator<<;" in the definition of Message's operator<<. That fix
9294 // doesn't require a helper function, but unfortunately doesn't
9395 // compile with MSVC.
96
97 // LLVM INTERNAL CHANGE: To allow operator<< to work with both
98 // std::ostreams and LLVM's raw_ostreams, we define a special
99 // std::ostream with an implicit conversion to raw_ostream& and stream
100 // to that. This causes the compiler to prefer std::ostream overloads
101 // but still find raw_ostream& overloads.
102 namespace llvm {
103 class convertible_fwd_ostream : public std::ostream {
104 std::ostream& os_;
105 raw_os_ostream ros_;
106
107 public:
108 convertible_fwd_ostream(std::ostream& os)
109 : std::ostream(os.rdbuf()), os_(os), ros_(*this) {}
110 operator raw_ostream&() { return ros_; }
111 };
112 }
94113 template
95114 inline void GTestStreamToHelper(std::ostream* os, const T& val) {
96 *os << val;
115 llvm::convertible_fwd_ostream cos(*os);
116 cos << val;
97117 }
98118
99119 namespace testing {