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
ea31cb15
Unverified
Commit
ea31cb15
authored
Jan 31, 2018
by
Gennadiy Civil
Committed by
GitHub
Jan 31, 2018
Browse files
Merge pull request #1435 from gennadiycivil/master
Code merges
parents
a1923a59
e6ec8bc5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
22 deletions
+67
-22
BUILD.bazel
BUILD.bazel
+1
-0
ci/build-linux-bazel.sh
ci/build-linux-bazel.sh
+1
-0
googletest/include/gtest/gtest-printers.h
googletest/include/gtest/gtest-printers.h
+58
-15
googletest/test/gtest-printers_test.cc
googletest/test/gtest-printers_test.cc
+7
-7
No files found.
BUILD.bazel
View file @
ea31cb15
...
...
@@ -104,6 +104,7 @@ cc_library(
deps
=
select
({
":has_absl"
:
[
"@com_google_absl//absl/types:optional"
,
"@com_google_absl//absl/strings"
],
"//conditions:default"
:
[],
}
...
...
ci/build-linux-bazel.sh
View file @
ea31cb15
...
...
@@ -33,3 +33,4 @@ set -e
bazel build
--curses
=
no //...:all
bazel
test
--curses
=
no //...:all
bazel
test
--curses
=
no //...:all
--define
absl
=
1
googletest/include/gtest/gtest-printers.h
View file @
ea31cb15
...
...
@@ -113,6 +113,7 @@
#if GTEST_HAS_ABSL
#include "absl/types/optional.h"
#include "absl/strings/string_view.h"
#endif // GTEST_HAS_ABSL
namespace
testing
{
...
...
@@ -133,7 +134,11 @@ enum TypeKind {
kProtobuf
,
// a protobuf type
kConvertibleToInteger
,
// a type implicitly convertible to BiggestInt
// (e.g. a named or unnamed enum type)
kOtherType
// anything else
#if GTEST_HAS_ABSL
kConvertibleToStringView
,
// a type implicitly convertible to
// absl::string_view
#endif
kOtherType
// anything else
};
// TypeWithoutFormatter<T, kTypeKind>::PrintValue(value, os) is called
...
...
@@ -146,7 +151,7 @@ class TypeWithoutFormatter {
// This default version is called when kTypeKind is kOtherType.
static
void
PrintValue
(
const
T
&
value
,
::
std
::
ostream
*
os
)
{
PrintBytesInObjectTo
(
static_cast
<
const
unsigned
char
*>
(
reinterpret_cast
<
const
void
*>
(
&
value
)),
reinterpret_cast
<
const
void
*>
(
&
value
)),
sizeof
(
value
),
os
);
}
};
...
...
@@ -184,6 +189,19 @@ class TypeWithoutFormatter<T, kConvertibleToInteger> {
}
};
#if GTEST_HAS_ABSL
template
<
typename
T
>
class
TypeWithoutFormatter
<
T
,
kConvertibleToStringView
>
{
public:
// Since T has neither operator<< nor PrintTo() but can be implicitly
// converted to absl::string_view, we print it as a absl::string_view.
//
// Note: the implementation is further below, as it depends on
// internal::PrintTo symbol which is defined later in the file.
static
void
PrintValue
(
const
T
&
value
,
::
std
::
ostream
*
os
);
};
#endif
// Prints the given value to the given ostream. If the value is a
// protocol message, its debug string is printed; if it's an enum or
// of a type implicitly convertible to BiggestInt, it's printed as an
...
...
@@ -211,10 +229,19 @@ class TypeWithoutFormatter<T, kConvertibleToInteger> {
template
<
typename
Char
,
typename
CharTraits
,
typename
T
>
::
std
::
basic_ostream
<
Char
,
CharTraits
>&
operator
<<
(
::
std
::
basic_ostream
<
Char
,
CharTraits
>&
os
,
const
T
&
x
)
{
TypeWithoutFormatter
<
T
,
(
internal
::
IsAProtocolMessage
<
T
>::
value
?
kProtobuf
:
internal
::
ImplicitlyConvertible
<
const
T
&
,
internal
::
BiggestInt
>::
value
?
kConvertibleToInteger
:
kOtherType
)
>::
PrintValue
(
x
,
&
os
);
TypeWithoutFormatter
<
T
,
(
internal
::
IsAProtocolMessage
<
T
>::
value
?
kProtobuf
:
internal
::
ImplicitlyConvertible
<
const
T
&
,
internal
::
BiggestInt
>::
value
?
kConvertibleToInteger
:
#if GTEST_HAS_ABSL
internal
::
ImplicitlyConvertible
<
const
T
&
,
absl
::
string_view
>::
value
?
kConvertibleToStringView
:
#endif
kOtherType
)
>::
PrintValue
(
x
,
&
os
);
return
os
;
}
...
...
@@ -435,7 +462,8 @@ void DefaultPrintTo(WrapPrinterType<kPrintFunctionPointer> /* dummy */,
*
os
<<
"NULL"
;
}
else
{
// T is a function type, so '*os << p' doesn't do what we want
// (it just prints p as bool). Cast p to const void* to print it.
// (it just prints p as bool). We want to print p as a const
// void*.
*
os
<<
reinterpret_cast
<
const
void
*>
(
p
);
}
}
...
...
@@ -464,17 +492,15 @@ void PrintTo(const T& value, ::std::ostream* os) {
// DefaultPrintTo() is overloaded. The type of its first argument
// determines which version will be picked.
//
// Note that we check for
recursive and other
container types here, prior
//
to we check
for protocol message types in our operator<<. The rationale is:
// Note that we check for container types here, prior
to we check
// for protocol message types in our operator<<. The rationale is:
//
// For protocol messages, we want to give people a chance to
// override Google Mock's format by defining a PrintTo() or
// operator<<. For STL containers, other formats can be
// incompatible with Google Mock's format for the container
// elements; therefore we check for container types here to ensure
// that our format is used. To prevent an infinite runtime recursion
// during the output of recursive container types, we check first for
// those.
// that our format is used.
//
// Note that MSVC and clang-cl do allow an implicit conversion from
// pointer-to-function to pointer-to-object, but clang-cl warns on it.
...
...
@@ -492,8 +518,8 @@ void PrintTo(const T& value, ::std::ostream* os) {
#else
:
!
internal
::
ImplicitlyConvertible
<
T
,
const
void
*>::
value
#endif
?
kPrintFunctionPointer
:
kPrintPointer
>
(),
?
kPrintFunctionPointer
:
kPrintPointer
>
(),
value
,
os
);
}
...
...
@@ -601,6 +627,13 @@ inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
}
#endif // GTEST_HAS_STD_WSTRING
#if GTEST_HAS_ABSL
// Overload for absl::string_view.
inline
void
PrintTo
(
absl
::
string_view
sp
,
::
std
::
ostream
*
os
)
{
PrintTo
(
::
std
::
string
(
sp
),
os
);
}
#endif // GTEST_HAS_ABSL
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
// Helper function for printing a tuple. T must be instantiated with
// a tuple type.
...
...
@@ -896,7 +929,7 @@ void UniversalPrint(const T& value, ::std::ostream* os) {
UniversalPrinter
<
T1
>::
Print
(
value
,
os
);
}
typedef
::
std
::
vector
<
string
>
Strings
;
typedef
::
std
::
vector
<
::
std
::
string
>
Strings
;
// TuplePolicy<TupleT> must provide:
// - tuple_size
...
...
@@ -1016,6 +1049,16 @@ Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
}
// namespace internal
#if GTEST_HAS_ABSL
namespace
internal2
{
template
<
typename
T
>
void
TypeWithoutFormatter
<
T
,
kConvertibleToStringView
>::
PrintValue
(
const
T
&
value
,
::
std
::
ostream
*
os
)
{
internal
::
PrintTo
(
absl
::
string_view
(
value
),
os
);
}
}
// namespace internal2
#endif
template
<
typename
T
>
::
std
::
string
PrintToString
(
const
T
&
value
)
{
::
std
::
stringstream
ss
;
...
...
googletest/test/gtest-printers_test.cc
View file @
ea31cb15
...
...
@@ -837,22 +837,22 @@ TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
EXPECT_EQ
(
"AllowsGenericStreamingAndImplicitConversionTemplate"
,
Print
(
a
));
}
#if GTEST_HAS_
STRING_PIECE_
#if GTEST_HAS_
ABSL
// Tests printing
StringPiece
.
// Tests printing
::absl::string_view
.
TEST
(
PrintString
P
ie
ce
Test
,
SimpleString
P
ie
ce
)
{
const
StringPiece
sp
=
"Hello"
;
TEST
(
PrintString
V
ie
w
Test
,
SimpleString
V
ie
w
)
{
const
::
absl
::
string_view
sp
=
"Hello"
;
EXPECT_EQ
(
"
\"
Hello
\"
"
,
Print
(
sp
));
}
TEST
(
PrintString
P
ie
ce
Test
,
UnprintableCharacters
)
{
TEST
(
PrintString
V
ie
w
Test
,
UnprintableCharacters
)
{
const
char
str
[]
=
"NUL (
\0
) and
\r\t
"
;
const
StringPiece
sp
(
str
,
sizeof
(
str
)
-
1
);
const
::
absl
::
string_view
sp
(
str
,
sizeof
(
str
)
-
1
);
EXPECT_EQ
(
"
\"
NUL (
\\
0) and
\\
r
\\
t
\"
"
,
Print
(
sp
));
}
#endif // GTEST_HAS_
STRING_PIECE_
#endif // GTEST_HAS_
ABSL
// Tests printing STL containers.
...
...
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