aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Mauro <dmauro@google.com>2018-07-12 13:46:50 -0400
committerDerek Mauro <dmauro@google.com>2018-07-12 13:46:50 -0400
commit6c7878a151f05d64f675b800b054c5fc43f3dd6d (patch)
tree4b73b4e6ed35633bb67b8bbd4e6f78fb1d248eb9
parent41f0e24335d8874cc87420a6349bb1844e2a15de (diff)
downloadgoogletest-6c7878a151f05d64f675b800b054c5fc43f3dd6d.tar.gz
googletest-6c7878a151f05d64f675b800b054c5fc43f3dd6d.tar.bz2
googletest-6c7878a151f05d64f675b800b054c5fc43f3dd6d.zip
Adds the UniversalPrinter for absl::variant.
-rw-r--r--BUILD.bazel36
-rw-r--r--googletest/include/gtest/gtest-printers.h23
2 files changed, 42 insertions, 17 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
index 6d828294..f6dccd38 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -38,7 +38,7 @@ licenses(["notice"])
config_setting(
name = "windows",
- values = { "cpu": "x64_windows" },
+ values = {"cpu": "x64_windows"},
)
config_setting(
@@ -51,7 +51,6 @@ config_setting(
values = {"define": "absl=1"},
)
-
# Google Test including Google Mock
cc_library(
name = "gtest",
@@ -70,7 +69,7 @@ cc_library(
"googlemock/src/gmock_main.cc",
],
),
- hdrs =glob([
+ hdrs = glob([
"googletest/include/gtest/*.h",
"googlemock/include/gmock/*.h",
]),
@@ -81,6 +80,14 @@ cc_library(
"//conditions:default": ["-pthread"],
},
),
+ defines = select(
+ {
+ ":has_absl": [
+ "GTEST_HAS_ABSL=1",
+ ],
+ "//conditions:default": [],
+ },
+ ),
includes = [
"googlemock",
"googlemock/include",
@@ -94,21 +101,16 @@ cc_library(
"-pthread",
],
}),
- defines = select ({
- ":has_absl": [
- "GTEST_HAS_ABSL=1",
- ],
- "//conditions:default": [],
- }
+ deps = select(
+ {
+ ":has_absl": [
+ "@com_google_absl//absl/types:optional",
+ "@com_google_absl//absl/types:variant",
+ "@com_google_absl//absl/strings",
+ ],
+ "//conditions:default": [],
+ },
),
- deps = select ({
- ":has_absl": [
- "@com_google_absl//absl/types:optional",
- "@com_google_absl//absl/strings"
- ],
- "//conditions:default": [],
- }
- )
)
cc_library(
diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h
index 373946b9..66d54b94 100644
--- a/googletest/include/gtest/gtest-printers.h
+++ b/googletest/include/gtest/gtest-printers.h
@@ -114,6 +114,7 @@
#if GTEST_HAS_ABSL
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
+#include "absl/types/variant.h"
#endif // GTEST_HAS_ABSL
namespace testing {
@@ -787,6 +788,28 @@ class UniversalPrinter<::absl::optional<T>> {
}
};
+// Printer for absl::variant
+
+template <typename... T>
+class UniversalPrinter<::absl::variant<T...>> {
+ public:
+ static void Print(const ::absl::variant<T...>& value, ::std::ostream* os) {
+ *os << '(';
+ absl::visit(Visitor{os}, value);
+ *os << ')';
+ }
+
+ private:
+ struct Visitor {
+ template <typename U>
+ void operator()(const U& u) const {
+ *os << "'" << GetTypeName<U>() << "' with value ";
+ UniversalPrint(u, os);
+ }
+ ::std::ostream* os;
+ };
+};
+
#endif // GTEST_HAS_ABSL
// UniversalPrintArray(begin, len, os) prints an array of 'len'