Ability to optionally depend on Abseil plus upstream of 183716547
This commit is contained in:
		
							
								
								
									
										20
									
								
								BUILD.bazel
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								BUILD.bazel
									
									
									
									
									
								
							@@ -46,6 +46,12 @@ config_setting(
 | 
				
			|||||||
    values = {"cpu": "x64_windows_msvc"},
 | 
					    values = {"cpu": "x64_windows_msvc"},
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					config_setting(
 | 
				
			||||||
 | 
					    name = "has_absl",
 | 
				
			||||||
 | 
					    values = {"define": "absl=1"},
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Google Test including Google Mock
 | 
					# Google Test including Google Mock
 | 
				
			||||||
cc_library(
 | 
					cc_library(
 | 
				
			||||||
    name = "gtest",
 | 
					    name = "gtest",
 | 
				
			||||||
@@ -88,6 +94,20 @@ cc_library(
 | 
				
			|||||||
            "-pthread",
 | 
					            "-pthread",
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
    }),
 | 
					    }),
 | 
				
			||||||
 | 
					    defines = select ({
 | 
				
			||||||
 | 
					        ":has_absl": [
 | 
				
			||||||
 | 
					        "GTEST_HAS_ABSL=1",
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        "//conditions:default": [],
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ),
 | 
				
			||||||
 | 
					    deps = select ({
 | 
				
			||||||
 | 
					        ":has_absl": [
 | 
				
			||||||
 | 
					        "@com_google_absl//absl/types:optional",
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        "//conditions:default": [],
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cc_library(
 | 
					cc_library(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1 +1,8 @@
 | 
				
			|||||||
workspace(name = "com_google_googletest")
 | 
					workspace(name = "com_google_googletest")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Abseil
 | 
				
			||||||
 | 
					http_archive(
 | 
				
			||||||
 | 
					     name = "com_google_absl",
 | 
				
			||||||
 | 
					     urls = ["https://github.com/abseil/abseil-cpp/archive/master.zip"],
 | 
				
			||||||
 | 
					     strip_prefix = "abseil-cpp-master",
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,6 +46,10 @@
 | 
				
			|||||||
//   2. operator<<(ostream&, const T&) defined in either foo or the
 | 
					//   2. operator<<(ostream&, const T&) defined in either foo or the
 | 
				
			||||||
//      global namespace.
 | 
					//      global namespace.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 | 
					// However if T is an STL-style container then it is printed element-wise
 | 
				
			||||||
 | 
					// unless foo::PrintTo(const T&, ostream*) is defined. Note that
 | 
				
			||||||
 | 
					// operator<<() is ignored for container types.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
// If none of the above is defined, it will print the debug string of
 | 
					// If none of the above is defined, it will print the debug string of
 | 
				
			||||||
// the value if it is a protocol buffer, or print the raw bytes in the
 | 
					// the value if it is a protocol buffer, or print the raw bytes in the
 | 
				
			||||||
// value otherwise.
 | 
					// value otherwise.
 | 
				
			||||||
@@ -107,6 +111,10 @@
 | 
				
			|||||||
# include <tuple>
 | 
					# include <tuple>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if GTEST_HAS_ABSL
 | 
				
			||||||
 | 
					#include "absl/types/optional.h"
 | 
				
			||||||
 | 
					#endif  // GTEST_HAS_ABSL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace testing {
 | 
					namespace testing {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Definitions in the 'internal' and 'internal2' name spaces are
 | 
					// Definitions in the 'internal' and 'internal2' name spaces are
 | 
				
			||||||
@@ -722,6 +730,26 @@ class UniversalPrinter {
 | 
				
			|||||||
  GTEST_DISABLE_MSC_WARNINGS_POP_()
 | 
					  GTEST_DISABLE_MSC_WARNINGS_POP_()
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if GTEST_HAS_ABSL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Printer for absl::optional
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <typename T>
 | 
				
			||||||
 | 
					class UniversalPrinter<::absl::optional<T>> {
 | 
				
			||||||
 | 
					 public:
 | 
				
			||||||
 | 
					  static void Print(const ::absl::optional<T>& value, ::std::ostream* os) {
 | 
				
			||||||
 | 
					    *os << '(';
 | 
				
			||||||
 | 
					    if (!value) {
 | 
				
			||||||
 | 
					      *os << "nullopt";
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      UniversalPrint(*value, os);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    *os << ')';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  // GTEST_HAS_ABSL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UniversalPrintArray(begin, len, os) prints an array of 'len'
 | 
					// UniversalPrintArray(begin, len, os) prints an array of 'len'
 | 
				
			||||||
// elements, starting at address 'begin'.
 | 
					// elements, starting at address 'begin'.
 | 
				
			||||||
template <typename T>
 | 
					template <typename T>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1765,5 +1765,17 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#endif  // GTEST_HAS_STD_TUPLE_
 | 
					#endif  // GTEST_HAS_STD_TUPLE_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if GTEST_HAS_ABSL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(PrintOptionalTest, Basic) {
 | 
				
			||||||
 | 
					  absl::optional<int> value;
 | 
				
			||||||
 | 
					  EXPECT_EQ("(nullopt)", PrintToString(value));
 | 
				
			||||||
 | 
					  value = {7};
 | 
				
			||||||
 | 
					  EXPECT_EQ("(7)", PrintToString(value));
 | 
				
			||||||
 | 
					  EXPECT_EQ("(1.1)", PrintToString(absl::optional<double>{1.1}));
 | 
				
			||||||
 | 
					  EXPECT_EQ("(\"A\")", PrintToString(absl::optional<std::string>{"A"}));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif  // GTEST_HAS_ABSL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}  // namespace gtest_printers_test
 | 
					}  // namespace gtest_printers_test
 | 
				
			||||||
}  // namespace testing
 | 
					}  // namespace testing
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user