Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
df0d0a3f
Unverified
Commit
df0d0a3f
authored
Jul 12, 2018
by
Gennadiy Civil
Committed by
GitHub
Jul 12, 2018
Browse files
Merge pull request #1662 from derekmauro/variant
Adds the UniversalPrinter for absl::variant.
parents
41f0e243
6c7878a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
17 deletions
+42
-17
BUILD.bazel
BUILD.bazel
+19
-17
googletest/include/gtest/gtest-printers.h
googletest/include/gtest/gtest-printers.h
+23
-0
No files found.
BUILD.bazel
View file @
df0d0a3f
...
@@ -38,7 +38,7 @@ licenses(["notice"])
...
@@ -38,7 +38,7 @@ licenses(["notice"])
config_setting
(
config_setting
(
name
=
"windows"
,
name
=
"windows"
,
values
=
{
"cpu"
:
"x64_windows"
},
values
=
{
"cpu"
:
"x64_windows"
},
)
)
config_setting
(
config_setting
(
...
@@ -51,7 +51,6 @@ config_setting(
...
@@ -51,7 +51,6 @@ config_setting(
values
=
{
"define"
:
"absl=1"
},
values
=
{
"define"
:
"absl=1"
},
)
)
# Google Test including Google Mock
# Google Test including Google Mock
cc_library
(
cc_library
(
name
=
"gtest"
,
name
=
"gtest"
,
...
@@ -70,7 +69,7 @@ cc_library(
...
@@ -70,7 +69,7 @@ cc_library(
"googlemock/src/gmock_main.cc"
,
"googlemock/src/gmock_main.cc"
,
],
],
),
),
hdrs
=
glob
([
hdrs
=
glob
([
"googletest/include/gtest/*.h"
,
"googletest/include/gtest/*.h"
,
"googlemock/include/gmock/*.h"
,
"googlemock/include/gmock/*.h"
,
]),
]),
...
@@ -81,6 +80,14 @@ cc_library(
...
@@ -81,6 +80,14 @@ cc_library(
"//conditions:default"
:
[
"-pthread"
],
"//conditions:default"
:
[
"-pthread"
],
},
},
),
),
defines
=
select
(
{
":has_absl"
:
[
"GTEST_HAS_ABSL=1"
,
],
"//conditions:default"
:
[],
},
),
includes
=
[
includes
=
[
"googlemock"
,
"googlemock"
,
"googlemock/include"
,
"googlemock/include"
,
...
@@ -94,21 +101,16 @@ cc_library(
...
@@ -94,21 +101,16 @@ cc_library(
"-pthread"
,
"-pthread"
,
],
],
}),
}),
defines
=
select
({
deps
=
select
(
":has_absl"
:
[
{
"GTEST_HAS_ABSL=1"
,
":has_absl"
:
[
],
"@com_google_absl//absl/types:optional"
,
"//conditions:default"
:
[],
"@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
(
cc_library
(
...
...
googletest/include/gtest/gtest-printers.h
View file @
df0d0a3f
...
@@ -114,6 +114,7 @@
...
@@ -114,6 +114,7 @@
#if GTEST_HAS_ABSL
#if GTEST_HAS_ABSL
#include "absl/strings/string_view.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "absl/types/optional.h"
#include "absl/types/variant.h"
#endif // GTEST_HAS_ABSL
#endif // GTEST_HAS_ABSL
namespace
testing
{
namespace
testing
{
...
@@ -787,6 +788,28 @@ class UniversalPrinter<::absl::optional<T>> {
...
@@ -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
#endif // GTEST_HAS_ABSL
// UniversalPrintArray(begin, len, os) prints an array of 'len'
// UniversalPrintArray(begin, len, os) prints an array of 'len'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment