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
b1c7f93c
Commit
b1c7f93c
authored
Mar 24, 2010
by
zhanyong.wan
Browse files
Improves matcher messages across the board.
parent
676e8cc6
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
504 additions
and
245 deletions
+504
-245
include/gmock/gmock-generated-matchers.h
include/gmock/gmock-generated-matchers.h
+18
-3
include/gmock/gmock-generated-matchers.h.pump
include/gmock/gmock-generated-matchers.h.pump
+15
-2
include/gmock/gmock-matchers.h
include/gmock/gmock-matchers.h
+84
-87
include/gmock/gmock-spec-builders.h
include/gmock/gmock-spec-builders.h
+6
-6
test/gmock-generated-matchers_test.cc
test/gmock-generated-matchers_test.cc
+65
-20
test/gmock-matchers_test.cc
test/gmock-matchers_test.cc
+313
-124
test/gmock_output_test_golden.txt
test/gmock_output_test_golden.txt
+3
-3
No files found.
include/gmock/gmock-generated-matchers.h
View file @
b1c7f93c
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
// This file was GENERATED by command:
// pump.py gmock-generated-matchers.h.pump
// DO NOT EDIT BY HAND!!!
// Copyright 2008, Google Inc.
// Copyright 2008, Google Inc.
// All rights reserved.
// All rights reserved.
...
@@ -231,15 +233,28 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
...
@@ -231,15 +233,28 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
virtual
bool
MatchAndExplain
(
ArgsTuple
args
,
virtual
bool
MatchAndExplain
(
ArgsTuple
args
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
return
inner_matcher_
.
MatchAndExplain
(
GetSelectedArgs
(
args
),
listener
);
const
SelectedArgs
&
selected_args
=
GetSelectedArgs
(
args
);
if
(
!
listener
->
IsInterested
())
return
inner_matcher_
.
Matches
(
selected_args
);
PrintIndices
(
listener
->
stream
());
*
listener
<<
"are "
<<
PrintToString
(
selected_args
);
StringMatchResultListener
inner_listener
;
const
bool
match
=
inner_matcher_
.
MatchAndExplain
(
selected_args
,
&
inner_listener
);
PrintIfNotEmpty
(
inner_listener
.
str
(),
listener
->
stream
());
return
match
;
}
}
virtual
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
virtual
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"are a tuple "
;
PrintIndices
(
os
);
PrintIndices
(
os
);
inner_matcher_
.
DescribeTo
(
os
);
inner_matcher_
.
DescribeTo
(
os
);
}
}
virtual
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
virtual
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"are a tuple "
;
PrintIndices
(
os
);
PrintIndices
(
os
);
inner_matcher_
.
DescribeNegationTo
(
os
);
inner_matcher_
.
DescribeNegationTo
(
os
);
}
}
...
@@ -252,7 +267,7 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
...
@@ -252,7 +267,7 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
// Prints the indices of the selected fields.
// Prints the indices of the selected fields.
static
void
PrintIndices
(
::
std
::
ostream
*
os
)
{
static
void
PrintIndices
(
::
std
::
ostream
*
os
)
{
*
os
<<
"
are a tuple
whose fields ("
;
*
os
<<
"whose fields ("
;
const
int
indices
[
10
]
=
{
k0
,
k1
,
k2
,
k3
,
k4
,
k5
,
k6
,
k7
,
k8
,
k9
};
const
int
indices
[
10
]
=
{
k0
,
k1
,
k2
,
k3
,
k4
,
k5
,
k6
,
k7
,
k8
,
k9
};
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
if
(
indices
[
i
]
<
0
)
if
(
indices
[
i
]
<
0
)
...
...
include/gmock/gmock-generated-matchers.h.pump
View file @
b1c7f93c
...
@@ -118,15 +118,28 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
...
@@ -118,15 +118,28 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
virtual
bool
MatchAndExplain
(
ArgsTuple
args
,
virtual
bool
MatchAndExplain
(
ArgsTuple
args
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
return
inner_matcher_
.
MatchAndExplain
(
GetSelectedArgs
(
args
),
listener
);
const
SelectedArgs
&
selected_args
=
GetSelectedArgs
(
args
);
if
(
!
listener
->
IsInterested
())
return
inner_matcher_
.
Matches
(
selected_args
);
PrintIndices
(
listener
->
stream
());
*
listener
<<
"are "
<<
PrintToString
(
selected_args
);
StringMatchResultListener
inner_listener
;
const
bool
match
=
inner_matcher_
.
MatchAndExplain
(
selected_args
,
&
inner_listener
);
PrintIfNotEmpty
(
inner_listener
.
str
(),
listener
->
stream
());
return
match
;
}
}
virtual
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
virtual
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"are a tuple "
;
PrintIndices
(
os
);
PrintIndices
(
os
);
inner_matcher_
.
DescribeTo
(
os
);
inner_matcher_
.
DescribeTo
(
os
);
}
}
virtual
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
virtual
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"are a tuple "
;
PrintIndices
(
os
);
PrintIndices
(
os
);
inner_matcher_
.
DescribeNegationTo
(
os
);
inner_matcher_
.
DescribeNegationTo
(
os
);
}
}
...
@@ -138,7 +151,7 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
...
@@ -138,7 +151,7 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
// Prints the indices of the selected fields.
// Prints the indices of the selected fields.
static
void
PrintIndices
(
::
std
::
ostream
*
os
)
{
static
void
PrintIndices
(
::
std
::
ostream
*
os
)
{
*
os
<<
"
are a tuple
whose fields ("
;
*
os
<<
"whose fields ("
;
const
int
indices
[
$
n
]
=
{
$
ks
};
const
int
indices
[
$
n
]
=
{
$
ks
};
for
(
int
i
=
0
;
i
<
$
n
;
i
++
)
{
for
(
int
i
=
0
;
i
<
$
n
;
i
++
)
{
if
(
indices
[
i
]
<
0
)
if
(
indices
[
i
]
<
0
)
...
...
include/gmock/gmock-matchers.h
View file @
b1c7f93c
...
@@ -453,12 +453,11 @@ Matcher<T> A();
...
@@ -453,12 +453,11 @@ Matcher<T> A();
// and MUST NOT BE USED IN USER CODE!!!
// and MUST NOT BE USED IN USER CODE!!!
namespace
internal
{
namespace
internal
{
// If the explanation is not empty, prints it to the listener.
// If the explanation is not empty, prints it to the ostream.
// 'listener' must not be NULL.
inline
void
PrintIfNotEmpty
(
const
internal
::
string
&
explanation
,
inline
void
PrintIfNotEmpty
(
std
::
ostream
*
os
)
{
const
internal
::
string
&
explanation
,
MatchResultListener
*
listener
)
{
if
(
explanation
!=
""
&&
os
!=
NULL
)
{
if
(
explanation
!=
""
)
{
*
os
<<
", "
<<
explanation
;
*
listener
<<
", "
<<
explanation
;
}
}
}
}
...
@@ -480,20 +479,11 @@ bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
...
@@ -480,20 +479,11 @@ bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
const
bool
match
=
matcher
.
MatchAndExplain
(
value
,
&
inner_listener
);
const
bool
match
=
matcher
.
MatchAndExplain
(
value
,
&
inner_listener
);
UniversalPrint
(
value
,
listener
->
stream
());
UniversalPrint
(
value
,
listener
->
stream
());
PrintIfNotEmpty
(
inner_listener
.
str
(),
listener
);
PrintIfNotEmpty
(
inner_listener
.
str
(),
listener
->
stream
()
);
return
match
;
return
match
;
}
}
// If the given string is not empty and os is not NULL, wraps the
// string inside a pair of parentheses and streams the result to os.
inline
void
StreamInParensAsNeeded
(
const
internal
::
string
&
str
,
::
std
::
ostream
*
os
)
{
if
(
!
str
.
empty
()
&&
os
!=
NULL
)
{
*
os
<<
" ("
<<
str
<<
")"
;
}
}
// An internal helper class for doing compile-time loop on a tuple's
// An internal helper class for doing compile-time loop on a tuple's
// fields.
// fields.
template
<
size_t
N
>
template
<
size_t
N
>
...
@@ -510,19 +500,19 @@ class TuplePrefix {
...
@@ -510,19 +500,19 @@ class TuplePrefix {
&&
get
<
N
-
1
>
(
matcher_tuple
).
Matches
(
get
<
N
-
1
>
(
value_tuple
));
&&
get
<
N
-
1
>
(
matcher_tuple
).
Matches
(
get
<
N
-
1
>
(
value_tuple
));
}
}
// TuplePrefix<N>::
Describe
MatchFailuresTo(matchers, values, os)
// TuplePrefix<N>::
Explain
MatchFailuresTo(matchers, values, os)
// describes failures in matching the first N fields of matchers
// describes failures in matching the first N fields of matchers
// against the first N fields of values. If there is no failure,
// against the first N fields of values. If there is no failure,
// nothing will be streamed to os.
// nothing will be streamed to os.
template
<
typename
MatcherTuple
,
typename
ValueTuple
>
template
<
typename
MatcherTuple
,
typename
ValueTuple
>
static
void
Describe
MatchFailuresTo
(
const
MatcherTuple
&
matchers
,
static
void
Explain
MatchFailuresTo
(
const
MatcherTuple
&
matchers
,
const
ValueTuple
&
values
,
const
ValueTuple
&
values
,
::
std
::
ostream
*
os
)
{
::
std
::
ostream
*
os
)
{
using
::
std
::
tr1
::
tuple_element
;
using
::
std
::
tr1
::
tuple_element
;
using
::
std
::
tr1
::
get
;
using
::
std
::
tr1
::
get
;
// First, describes failures in the first N - 1 fields.
// First, describes failures in the first N - 1 fields.
TuplePrefix
<
N
-
1
>::
Describe
MatchFailuresTo
(
matchers
,
values
,
os
);
TuplePrefix
<
N
-
1
>::
Explain
MatchFailuresTo
(
matchers
,
values
,
os
);
// Then describes the failure (if any) in the (N - 1)-th (0-based)
// Then describes the failure (if any) in the (N - 1)-th (0-based)
// field.
// field.
...
@@ -542,10 +532,8 @@ class TuplePrefix {
...
@@ -542,10 +532,8 @@ class TuplePrefix {
// isn't interesting to the user most of the time. The
// isn't interesting to the user most of the time. The
// matcher's MatchAndExplain() method handles the case when
// matcher's MatchAndExplain() method handles the case when
// the address is interesting.
// the address is interesting.
internal
::
UniversalPrinter
<
GMOCK_REMOVE_REFERENCE_
(
Value
)
>::
internal
::
UniversalPrint
(
value
,
os
);
Print
(
value
,
os
);
PrintIfNotEmpty
(
listener
.
str
(),
os
);
StreamInParensAsNeeded
(
listener
.
str
(),
os
);
*
os
<<
"
\n
"
;
*
os
<<
"
\n
"
;
}
}
}
}
...
@@ -562,9 +550,9 @@ class TuplePrefix<0> {
...
@@ -562,9 +550,9 @@ class TuplePrefix<0> {
}
}
template
<
typename
MatcherTuple
,
typename
ValueTuple
>
template
<
typename
MatcherTuple
,
typename
ValueTuple
>
static
void
Describe
MatchFailuresTo
(
const
MatcherTuple
&
/* matchers */
,
static
void
Explain
MatchFailuresTo
(
const
MatcherTuple
&
/* matchers */
,
const
ValueTuple
&
/* values */
,
const
ValueTuple
&
/* values */
,
::
std
::
ostream
*
/* os */
)
{}
::
std
::
ostream
*
/* os */
)
{}
};
};
// TupleMatches(matcher_tuple, value_tuple) returns true iff all
// TupleMatches(matcher_tuple, value_tuple) returns true iff all
...
@@ -588,11 +576,11 @@ bool TupleMatches(const MatcherTuple& matcher_tuple,
...
@@ -588,11 +576,11 @@ bool TupleMatches(const MatcherTuple& matcher_tuple,
// Describes failures in matching matchers against values. If there
// Describes failures in matching matchers against values. If there
// is no failure, nothing will be streamed to os.
// is no failure, nothing will be streamed to os.
template
<
typename
MatcherTuple
,
typename
ValueTuple
>
template
<
typename
MatcherTuple
,
typename
ValueTuple
>
void
Describe
MatchFailureTupleTo
(
const
MatcherTuple
&
matchers
,
void
Explain
MatchFailureTupleTo
(
const
MatcherTuple
&
matchers
,
const
ValueTuple
&
values
,
const
ValueTuple
&
values
,
::
std
::
ostream
*
os
)
{
::
std
::
ostream
*
os
)
{
using
::
std
::
tr1
::
tuple_size
;
using
::
std
::
tr1
::
tuple_size
;
TuplePrefix
<
tuple_size
<
MatcherTuple
>::
value
>::
Describe
MatchFailuresTo
(
TuplePrefix
<
tuple_size
<
MatcherTuple
>::
value
>::
Explain
MatchFailuresTo
(
matchers
,
values
,
os
);
matchers
,
values
,
os
);
}
}
...
@@ -695,7 +683,8 @@ class AnythingMatcher {
...
@@ -695,7 +683,8 @@ class AnythingMatcher {
//
//
// The following template definition assumes that the Rhs parameter is
// The following template definition assumes that the Rhs parameter is
// a "bare" type (i.e. neither 'const T' nor 'T&').
// a "bare" type (i.e. neither 'const T' nor 'T&').
#define GMOCK_IMPLEMENT_COMPARISON_MATCHER_(name, op, relation) \
#define GMOCK_IMPLEMENT_COMPARISON_MATCHER_( \
name, op, relation, negated_relation) \
template <typename Rhs> class name##Matcher { \
template <typename Rhs> class name##Matcher { \
public: \
public: \
explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \
explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \
...
@@ -713,11 +702,11 @@ class AnythingMatcher {
...
@@ -713,11 +702,11 @@ class AnythingMatcher {
return lhs op rhs_; \
return lhs op rhs_; \
} \
} \
virtual void DescribeTo(::std::ostream* os) const { \
virtual void DescribeTo(::std::ostream* os) const { \
*os <<
"is "
relation " "; \
*os << relation " "; \
UniversalPrinter<Rhs>::Print(rhs_, os); \
UniversalPrinter<Rhs>::Print(rhs_, os); \
} \
} \
virtual void DescribeNegationTo(::std::ostream* os) const { \
virtual void DescribeNegationTo(::std::ostream* os) const { \
*os <<
"is not "
relation " "; \
*os <<
negated_
relation " "; \
UniversalPrinter<Rhs>::Print(rhs_, os); \
UniversalPrinter<Rhs>::Print(rhs_, os); \
} \
} \
private: \
private: \
...
@@ -730,12 +719,12 @@ class AnythingMatcher {
...
@@ -730,12 +719,12 @@ class AnythingMatcher {
// Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v)
// Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v)
// respectively.
// respectively.
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Eq
,
==
,
"equal to"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Eq
,
==
,
"
is equal to"
,
"isn't
equal to"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Ge
,
>=
,
"
greater than or equal to
"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Ge
,
>=
,
"
is >="
,
"isn't >=
"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Gt
,
>
,
"
greater than
"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Gt
,
>
,
"
is >"
,
"isn't >
"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Le
,
<=
,
"
less than or equal to
"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Le
,
<=
,
"
is <="
,
"isn't <=
"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Lt
,
<
,
"
less than
"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Lt
,
<
,
"
is <"
,
"isn't <
"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Ne
,
!=
,
"
not
equal to"
);
GMOCK_IMPLEMENT_COMPARISON_MATCHER_
(
Ne
,
!=
,
"
isn't equal to"
,
"is
equal to"
);
#undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_
#undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_
...
@@ -751,7 +740,7 @@ class IsNullMatcher {
...
@@ -751,7 +740,7 @@ class IsNullMatcher {
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is NULL"
;
}
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is NULL"
;
}
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is
no
t NULL"
;
*
os
<<
"is
n'
t NULL"
;
}
}
};
};
...
@@ -765,7 +754,7 @@ class NotNullMatcher {
...
@@ -765,7 +754,7 @@ class NotNullMatcher {
return
GetRawPointer
(
p
)
!=
NULL
;
return
GetRawPointer
(
p
)
!=
NULL
;
}
}
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is
no
t NULL"
;
}
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is
n'
t NULL"
;
}
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is NULL"
;
*
os
<<
"is NULL"
;
}
}
...
@@ -820,7 +809,7 @@ class RefMatcher<T&> {
...
@@ -820,7 +809,7 @@ class RefMatcher<T&> {
// in order to match the interface MatcherInterface<Super&>.
// in order to match the interface MatcherInterface<Super&>.
virtual
bool
MatchAndExplain
(
virtual
bool
MatchAndExplain
(
Super
&
x
,
MatchResultListener
*
listener
)
const
{
Super
&
x
,
MatchResultListener
*
listener
)
const
{
*
listener
<<
"is located @"
<<
static_cast
<
const
void
*>
(
&
x
);
*
listener
<<
"
which
is located @"
<<
static_cast
<
const
void
*>
(
&
x
);
return
&
x
==
&
object_
;
return
&
x
==
&
object_
;
}
}
...
@@ -917,10 +906,7 @@ class StrEqualityMatcher {
...
@@ -917,10 +906,7 @@ class StrEqualityMatcher {
private:
private:
void
DescribeToHelper
(
bool
expect_eq
,
::
std
::
ostream
*
os
)
const
{
void
DescribeToHelper
(
bool
expect_eq
,
::
std
::
ostream
*
os
)
const
{
*
os
<<
"is "
;
*
os
<<
(
expect_eq
?
"is "
:
"isn't "
);
if
(
!
expect_eq
)
{
*
os
<<
"not "
;
}
*
os
<<
"equal to "
;
*
os
<<
"equal to "
;
if
(
!
case_sensitive_
)
{
if
(
!
case_sensitive_
)
{
*
os
<<
"(ignoring case) "
;
*
os
<<
"(ignoring case) "
;
...
@@ -1212,8 +1198,11 @@ class BothOfMatcherImpl : public MatcherInterface<T> {
...
@@ -1212,8 +1198,11 @@ class BothOfMatcherImpl : public MatcherInterface<T> {
}
}
virtual
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
virtual
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"not "
;
*
os
<<
"("
;
DescribeTo
(
os
);
matcher1_
.
DescribeNegationTo
(
os
);
*
os
<<
") or ("
;
matcher2_
.
DescribeNegationTo
(
os
);
*
os
<<
")"
;
}
}
virtual
bool
MatchAndExplain
(
T
x
,
MatchResultListener
*
listener
)
const
{
virtual
bool
MatchAndExplain
(
T
x
,
MatchResultListener
*
listener
)
const
{
...
@@ -1240,7 +1229,7 @@ class BothOfMatcherImpl : public MatcherInterface<T> {
...
@@ -1240,7 +1229,7 @@ class BothOfMatcherImpl : public MatcherInterface<T> {
}
else
{
}
else
{
*
listener
<<
s1
;
*
listener
<<
s1
;
if
(
s2
!=
""
)
{
if
(
s2
!=
""
)
{
*
listener
<<
"
;
"
<<
s2
;
*
listener
<<
"
, and
"
<<
s2
;
}
}
}
}
return
true
;
return
true
;
...
@@ -1296,8 +1285,11 @@ class EitherOfMatcherImpl : public MatcherInterface<T> {
...
@@ -1296,8 +1285,11 @@ class EitherOfMatcherImpl : public MatcherInterface<T> {
}
}
virtual
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
virtual
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
"not "
;
*
os
<<
"("
;
DescribeTo
(
os
);
matcher1_
.
DescribeNegationTo
(
os
);
*
os
<<
") and ("
;
matcher2_
.
DescribeNegationTo
(
os
);
*
os
<<
")"
;
}
}
virtual
bool
MatchAndExplain
(
T
x
,
MatchResultListener
*
listener
)
const
{
virtual
bool
MatchAndExplain
(
T
x
,
MatchResultListener
*
listener
)
const
{
...
@@ -1324,7 +1316,7 @@ class EitherOfMatcherImpl : public MatcherInterface<T> {
...
@@ -1324,7 +1316,7 @@ class EitherOfMatcherImpl : public MatcherInterface<T> {
}
else
{
}
else
{
*
listener
<<
s1
;
*
listener
<<
s1
;
if
(
s2
!=
""
)
{
if
(
s2
!=
""
)
{
*
listener
<<
"
;
"
<<
s2
;
*
listener
<<
"
, and
"
<<
s2
;
}
}
}
}
return
false
;
return
false
;
...
@@ -1462,18 +1454,15 @@ class PredicateFormatterFromMatcher {
...
@@ -1462,18 +1454,15 @@ class PredicateFormatterFromMatcher {
// matcher_ has type Matcher<T> (e.g. An<int>()).
// matcher_ has type Matcher<T> (e.g. An<int>()).
const
Matcher
<
const
T
&>
matcher
=
MatcherCast
<
const
T
&>
(
matcher_
);
const
Matcher
<
const
T
&>
matcher
=
MatcherCast
<
const
T
&>
(
matcher_
);
StringMatchResultListener
listener
;
StringMatchResultListener
listener
;
if
(
m
atch
er
.
Match
AndExplain
(
x
,
&
listener
))
{
if
(
M
atch
Print
AndExplain
(
x
,
matcher
,
&
listener
))
return
AssertionSuccess
();
return
AssertionSuccess
();
}
else
{
::
std
::
stringstream
ss
;
::
std
::
stringstream
ss
;
ss
<<
"Value of: "
<<
value_text
<<
"
\n
"
ss
<<
"Value of: "
<<
value_text
<<
"
\n
"
<<
"Expected: "
;
<<
"Expected: "
;
matcher
.
DescribeTo
(
&
ss
);
matcher
.
DescribeTo
(
&
ss
);
ss
<<
"
\n
Actual: "
;
ss
<<
"
\n
Actual: "
<<
listener
.
str
();
UniversalPrinter
<
T
>::
Print
(
x
,
&
ss
);
return
AssertionFailure
()
<<
ss
.
str
();
StreamInParensAsNeeded
(
listener
.
str
(),
&
ss
);
return
AssertionFailure
(
Message
()
<<
ss
.
str
());
}
}
}
private:
private:
...
@@ -1548,12 +1537,12 @@ class FloatingEqMatcher {
...
@@ -1548,12 +1537,12 @@ class FloatingEqMatcher {
::
std
::
numeric_limits
<
FloatType
>::
digits10
+
2
);
::
std
::
numeric_limits
<
FloatType
>::
digits10
+
2
);
if
(
FloatingPoint
<
FloatType
>
(
rhs_
).
is_nan
())
{
if
(
FloatingPoint
<
FloatType
>
(
rhs_
).
is_nan
())
{
if
(
nan_eq_nan_
)
{
if
(
nan_eq_nan_
)
{
*
os
<<
"is
no
t NaN"
;
*
os
<<
"is
n'
t NaN"
;
}
else
{
}
else
{
*
os
<<
"is anything"
;
*
os
<<
"is anything"
;
}
}
}
else
{
}
else
{
*
os
<<
"is
no
t approximately "
<<
rhs_
;
*
os
<<
"is
n'
t approximately "
<<
rhs_
;
}
}
// Restore original precision.
// Restore original precision.
os
->
precision
(
old_precision
);
os
->
precision
(
old_precision
);
...
@@ -1912,7 +1901,7 @@ class ContainerEqMatcher {
...
@@ -1912,7 +1901,7 @@ class ContainerEqMatcher {
::
std
::
ostream
*
const
os
=
listener
->
stream
();
::
std
::
ostream
*
const
os
=
listener
->
stream
();
if
(
os
!=
NULL
)
{
if
(
os
!=
NULL
)
{
// Something is different. Check for
missing
values first.
// Something is different. Check for
extra
values first.
bool
printed_header
=
false
;
bool
printed_header
=
false
;
for
(
typename
LhsStlContainer
::
const_iterator
it
=
for
(
typename
LhsStlContainer
::
const_iterator
it
=
lhs_stl_container
.
begin
();
lhs_stl_container
.
begin
();
...
@@ -1922,7 +1911,7 @@ class ContainerEqMatcher {
...
@@ -1922,7 +1911,7 @@ class ContainerEqMatcher {
if
(
printed_header
)
{
if
(
printed_header
)
{
*
os
<<
", "
;
*
os
<<
", "
;
}
else
{
}
else
{
*
os
<<
"
Only in actual
: "
;
*
os
<<
"
which has these unexpected elements
: "
;
printed_header
=
true
;
printed_header
=
true
;
}
}
UniversalPrinter
<
typename
LhsStlContainer
::
value_type
>::
UniversalPrinter
<
typename
LhsStlContainer
::
value_type
>::
...
@@ -1930,7 +1919,7 @@ class ContainerEqMatcher {
...
@@ -1930,7 +1919,7 @@ class ContainerEqMatcher {
}
}
}
}
// Now check for
extra
values.
// Now check for
missing
values.
bool
printed_header2
=
false
;
bool
printed_header2
=
false
;
for
(
typename
StlContainer
::
const_iterator
it
=
rhs_
.
begin
();
for
(
typename
StlContainer
::
const_iterator
it
=
rhs_
.
begin
();
it
!=
rhs_
.
end
();
++
it
)
{
it
!=
rhs_
.
end
();
++
it
)
{
...
@@ -1940,7 +1929,8 @@ class ContainerEqMatcher {
...
@@ -1940,7 +1929,8 @@ class ContainerEqMatcher {
if
(
printed_header2
)
{
if
(
printed_header2
)
{
*
os
<<
", "
;
*
os
<<
", "
;
}
else
{
}
else
{
*
os
<<
(
printed_header
?
"; not"
:
"Not"
)
<<
" in actual: "
;
*
os
<<
(
printed_header
?
",
\n
and"
:
"which"
)
<<
" doesn't have these expected elements: "
;
printed_header2
=
true
;
printed_header2
=
true
;
}
}
UniversalPrinter
<
typename
StlContainer
::
value_type
>::
Print
(
*
it
,
os
);
UniversalPrinter
<
typename
StlContainer
::
value_type
>::
Print
(
*
it
,
os
);
...
@@ -1990,8 +1980,10 @@ class ContainsMatcherImpl : public MatcherInterface<Container> {
...
@@ -1990,8 +1980,10 @@ class ContainsMatcherImpl : public MatcherInterface<Container> {
size_t
i
=
0
;
size_t
i
=
0
;
for
(
typename
StlContainer
::
const_iterator
it
=
stl_container
.
begin
();
for
(
typename
StlContainer
::
const_iterator
it
=
stl_container
.
begin
();
it
!=
stl_container
.
end
();
++
it
,
++
i
)
{
it
!=
stl_container
.
end
();
++
it
,
++
i
)
{
if
(
inner_matcher_
.
Matches
(
*
it
))
{
StringMatchResultListener
inner_listener
;
*
listener
<<
"element "
<<
i
<<
" matches"
;
if
(
inner_matcher_
.
MatchAndExplain
(
*
it
,
&
inner_listener
))
{
*
listener
<<
"whose element #"
<<
i
<<
" matches"
;
PrintIfNotEmpty
(
inner_listener
.
str
(),
listener
->
stream
());
return
true
;
return
true
;
}
}
}
}
...
@@ -2040,7 +2032,14 @@ class KeyMatcherImpl : public MatcherInterface<PairType> {
...
@@ -2040,7 +2032,14 @@ class KeyMatcherImpl : public MatcherInterface<PairType> {
// Returns true iff 'key_value.first' (the key) matches the inner matcher.
// Returns true iff 'key_value.first' (the key) matches the inner matcher.
virtual
bool
MatchAndExplain
(
PairType
key_value
,
virtual
bool
MatchAndExplain
(
PairType
key_value
,
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
return
inner_matcher_
.
MatchAndExplain
(
key_value
.
first
,
listener
);
StringMatchResultListener
inner_listener
;
const
bool
match
=
inner_matcher_
.
MatchAndExplain
(
key_value
.
first
,
&
inner_listener
);
const
internal
::
string
explanation
=
inner_listener
.
str
();
if
(
explanation
!=
""
)
{
*
listener
<<
"whose first field is a value "
<<
explanation
;
}
return
match
;
}
}
// Describes what this matcher does.
// Describes what this matcher does.
...
@@ -2125,14 +2124,14 @@ class PairMatcherImpl : public MatcherInterface<PairType> {
...
@@ -2125,14 +2124,14 @@ class PairMatcherImpl : public MatcherInterface<PairType> {
if
(
!
first_matcher_
.
MatchAndExplain
(
a_pair
.
first
,
if
(
!
first_matcher_
.
MatchAndExplain
(
a_pair
.
first
,
&
first_inner_listener
))
{
&
first_inner_listener
))
{
*
listener
<<
"whose first field does not match"
;
*
listener
<<
"whose first field does not match"
;
PrintIfNotEmpty
(
first_inner_listener
.
str
(),
listener
);
PrintIfNotEmpty
(
first_inner_listener
.
str
(),
listener
->
stream
()
);
return
false
;
return
false
;
}
}
StringMatchResultListener
second_inner_listener
;
StringMatchResultListener
second_inner_listener
;
if
(
!
second_matcher_
.
MatchAndExplain
(
a_pair
.
second
,
if
(
!
second_matcher_
.
MatchAndExplain
(
a_pair
.
second
,
&
second_inner_listener
))
{
&
second_inner_listener
))
{
*
listener
<<
"whose second field does not match"
;
*
listener
<<
"whose second field does not match"
;
PrintIfNotEmpty
(
second_inner_listener
.
str
(),
listener
);
PrintIfNotEmpty
(
second_inner_listener
.
str
(),
listener
->
stream
()
);
return
false
;
return
false
;
}
}
ExplainSuccess
(
first_inner_listener
.
str
(),
second_inner_listener
.
str
(),
ExplainSuccess
(
first_inner_listener
.
str
(),
second_inner_listener
.
str
(),
...
@@ -2217,7 +2216,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
...
@@ -2217,7 +2216,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
}
else
{
}
else
{
*
os
<<
"has "
<<
Elements
(
count
())
<<
" where
\n
"
;
*
os
<<
"has "
<<
Elements
(
count
())
<<
" where
\n
"
;
for
(
size_t
i
=
0
;
i
!=
count
();
++
i
)
{
for
(
size_t
i
=
0
;
i
!=
count
();
++
i
)
{
*
os
<<
"element "
<<
i
<<
" "
;
*
os
<<
"element
#
"
<<
i
<<
" "
;
matchers_
[
i
].
DescribeTo
(
os
);
matchers_
[
i
].
DescribeTo
(
os
);
if
(
i
+
1
<
count
())
{
if
(
i
+
1
<
count
())
{
*
os
<<
",
\n
"
;
*
os
<<
",
\n
"
;
...
@@ -2229,13 +2228,13 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
...
@@ -2229,13 +2228,13 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
// Describes what the negation of this matcher does.
// Describes what the negation of this matcher does.
virtual
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
virtual
void
DescribeNegationTo
(
::
std
::
ostream
*
os
)
const
{
if
(
count
()
==
0
)
{
if
(
count
()
==
0
)
{
*
os
<<
"is
no
t empty"
;
*
os
<<
"is
n'
t empty"
;
return
;
return
;
}
}
*
os
<<
"does
no
t have "
<<
Elements
(
count
())
<<
", or
\n
"
;
*
os
<<
"does
n'
t have "
<<
Elements
(
count
())
<<
", or
\n
"
;
for
(
size_t
i
=
0
;
i
!=
count
();
++
i
)
{
for
(
size_t
i
=
0
;
i
!=
count
();
++
i
)
{
*
os
<<
"element "
<<
i
<<
" "
;
*
os
<<
"element
#
"
<<
i
<<
" "
;
matchers_
[
i
].
DescribeNegationTo
(
os
);
matchers_
[
i
].
DescribeNegationTo
(
os
);
if
(
i
+
1
<
count
())
{
if
(
i
+
1
<
count
())
{
*
os
<<
", or
\n
"
;
*
os
<<
", or
\n
"
;
...
@@ -2253,7 +2252,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
...
@@ -2253,7 +2252,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
// prints the empty container. Otherwise we just need to show
// prints the empty container. Otherwise we just need to show
// how many elements there actually are.
// how many elements there actually are.
if
(
actual_count
!=
0
)
{
if
(
actual_count
!=
0
)
{
*
listener
<<
"has "
<<
Elements
(
actual_count
);
*
listener
<<
"
which
has "
<<
Elements
(
actual_count
);
}
}
return
false
;
return
false
;
}
}
...
@@ -2268,24 +2267,22 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
...
@@ -2268,24 +2267,22 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
}
else
{
}
else
{
// The container has the right size but the i-th element
// The container has the right size but the i-th element
// doesn't match its expectation.
// doesn't match its expectation.
*
listener
<<
"element "
<<
i
<<
" doesn't match"
;
*
listener
<<
"whose element #"
<<
i
<<
" doesn't match"
;
PrintIfNotEmpty
(
s
.
str
(),
listener
->
stream
());
StreamInParensAsNeeded
(
s
.
str
(),
listener
->
stream
());
return
false
;
return
false
;
}
}
}
}
// Every element matches its expectation. We need to explain why
// Every element matches its expectation. We need to explain why
// (the obvious ones can be skipped).
// (the obvious ones can be skipped).
bool
reason_printed
=
false
;
bool
reason_printed
=
false
;
for
(
size_t
i
=
0
;
i
!=
count
();
++
i
)
{
for
(
size_t
i
=
0
;
i
!=
count
();
++
i
)
{
const
internal
::
string
&
s
=
explanations
[
i
];
const
internal
::
string
&
s
=
explanations
[
i
];
if
(
!
s
.
empty
())
{
if
(
!
s
.
empty
())
{
if
(
reason_printed
)
{
if
(
reason_printed
)
{
*
listener
<<
",
\n
"
;
*
listener
<<
",
\n
and
"
;
}
}
*
listener
<<
"element "
<<
i
<<
" "
<<
s
;
*
listener
<<
"
whose
element
#
"
<<
i
<<
"
matches,
"
<<
s
;
reason_printed
=
true
;
reason_printed
=
true
;
}
}
}
}
...
...
include/gmock/gmock-spec-builders.h
View file @
b1c7f93c
...
@@ -993,8 +993,8 @@ class TypedExpectation : public ExpectationBase {
...
@@ -993,8 +993,8 @@ class TypedExpectation : public ExpectationBase {
// Describes the result of matching the arguments against this
// Describes the result of matching the arguments against this
// expectation to the given ostream.
// expectation to the given ostream.
// L >= g_gmock_mutex
// L >= g_gmock_mutex
void
Describe
MatchResultTo
(
const
ArgumentTuple
&
args
,
void
Explain
MatchResultTo
(
const
ArgumentTuple
&
args
,
::
std
::
ostream
*
os
)
const
{
::
std
::
ostream
*
os
)
const
{
g_gmock_mutex
.
AssertHeld
();
g_gmock_mutex
.
AssertHeld
();
if
(
is_retired
())
{
if
(
is_retired
())
{
...
@@ -1002,7 +1002,7 @@ class TypedExpectation : public ExpectationBase {
...
@@ -1002,7 +1002,7 @@ class TypedExpectation : public ExpectationBase {
<<
" Actual: it is retired
\n
"
;
<<
" Actual: it is retired
\n
"
;
}
else
if
(
!
Matches
(
args
))
{
}
else
if
(
!
Matches
(
args
))
{
if
(
!
TupleMatches
(
matchers_
,
args
))
{
if
(
!
TupleMatches
(
matchers_
,
args
))
{
Describe
MatchFailureTupleTo
(
matchers_
,
args
,
os
);
Explain
MatchFailureTupleTo
(
matchers_
,
args
,
os
);
}
}
StringMatchResultListener
listener
;
StringMatchResultListener
listener
;
if
(
!
extra_matcher_
.
MatchAndExplain
(
args
,
&
listener
))
{
if
(
!
extra_matcher_
.
MatchAndExplain
(
args
,
&
listener
))
{
...
@@ -1010,7 +1010,7 @@ class TypedExpectation : public ExpectationBase {
...
@@ -1010,7 +1010,7 @@ class TypedExpectation : public ExpectationBase {
extra_matcher_
.
DescribeTo
(
os
);
extra_matcher_
.
DescribeTo
(
os
);
*
os
<<
"
\n
Actual: don't match"
;
*
os
<<
"
\n
Actual: don't match"
;
internal
::
StreamInParensAsNeeded
(
listener
.
str
(),
os
);
internal
::
PrintIfNotEmpty
(
listener
.
str
(),
os
);
*
os
<<
"
\n
"
;
*
os
<<
"
\n
"
;
}
}
}
else
if
(
!
AllPrerequisitesAreSatisfied
())
{
}
else
if
(
!
AllPrerequisitesAreSatisfied
())
{
...
@@ -1028,7 +1028,7 @@ class TypedExpectation : public ExpectationBase {
...
@@ -1028,7 +1028,7 @@ class TypedExpectation : public ExpectationBase {
*
os
<<
" (end of pre-requisites)
\n
"
;
*
os
<<
" (end of pre-requisites)
\n
"
;
}
else
{
}
else
{
// This line is here just for completeness' sake. It will never
// This line is here just for completeness' sake. It will never
// be executed as currently the
Describe
MatchResultTo() function
// be executed as currently the
Explain
MatchResultTo() function
// is called only when the mock function call does NOT match the
// is called only when the mock function call does NOT match the
// expectation.
// expectation.
*
os
<<
"The call matches the expectation.
\n
"
;
*
os
<<
"The call matches the expectation.
\n
"
;
...
@@ -1618,7 +1618,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
...
@@ -1618,7 +1618,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
*
why
<<
"tried expectation #"
<<
i
<<
": "
;
*
why
<<
"tried expectation #"
<<
i
<<
": "
;
}
}
*
why
<<
expectations_
[
i
]
->
source_text
()
<<
"...
\n
"
;
*
why
<<
expectations_
[
i
]
->
source_text
()
<<
"...
\n
"
;
expectations_
[
i
]
->
Describe
MatchResultTo
(
args
,
why
);
expectations_
[
i
]
->
Explain
MatchResultTo
(
args
,
why
);
expectations_
[
i
]
->
DescribeCallCountTo
(
why
);
expectations_
[
i
]
->
DescribeCallCountTo
(
why
);
}
}
}
}
...
...
test/gmock-generated-matchers_test.cc
View file @
b1c7f93c
...
@@ -211,6 +211,43 @@ TEST(ArgsTest, DescribesNegationCorrectly) {
...
@@ -211,6 +211,43 @@ TEST(ArgsTest, DescribesNegationCorrectly) {
DescribeNegation
(
m
));
DescribeNegation
(
m
));
}
}
TEST
(
ArgsTest
,
ExplainsMatchResultWithoutInnerExplanation
)
{
const
Matcher
<
tuple
<
bool
,
int
,
int
>
>
m
=
Args
<
1
,
2
>
(
Eq
());
EXPECT_EQ
(
"whose fields (#1, #2) are (42, 42)"
,
Explain
(
m
,
make_tuple
(
false
,
42
,
42
)));
EXPECT_EQ
(
"whose fields (#1, #2) are (42, 43)"
,
Explain
(
m
,
make_tuple
(
false
,
42
,
43
)));
}
// For testing Args<>'s explanation.
class
LessThanMatcher
:
public
MatcherInterface
<
tuple
<
char
,
int
>
>
{
public:
virtual
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{}
virtual
bool
MatchAndExplain
(
tuple
<
char
,
int
>
value
,
MatchResultListener
*
listener
)
const
{
const
int
diff
=
get
<
0
>
(
value
)
-
get
<
1
>
(
value
);
if
(
diff
>
0
)
{
*
listener
<<
"where the first value is "
<<
diff
<<
" more than the second"
;
}
return
diff
<
0
;
}
};
Matcher
<
tuple
<
char
,
int
>
>
LessThan
()
{
return
MakeMatcher
(
new
LessThanMatcher
);
}
TEST
(
ArgsTest
,
ExplainsMatchResultWithInnerExplanation
)
{
const
Matcher
<
tuple
<
char
,
int
,
int
>
>
m
=
Args
<
0
,
2
>
(
LessThan
());
EXPECT_EQ
(
"whose fields (#0, #2) are ('a' (97), 42), "
"where the first value is 55 more than the second"
,
Explain
(
m
,
make_tuple
(
'a'
,
42
,
42
)));
EXPECT_EQ
(
"whose fields (#0, #2) are ('
\\
0', 43)"
,
Explain
(
m
,
make_tuple
(
'\0'
,
42
,
43
)));
}
// For testing ExplainMatchResultTo().
// For testing ExplainMatchResultTo().
class
GreaterThanMatcher
:
public
MatcherInterface
<
int
>
{
class
GreaterThanMatcher
:
public
MatcherInterface
<
int
>
{
public:
public:
...
@@ -224,11 +261,11 @@ class GreaterThanMatcher : public MatcherInterface<int> {
...
@@ -224,11 +261,11 @@ class GreaterThanMatcher : public MatcherInterface<int> {
MatchResultListener
*
listener
)
const
{
MatchResultListener
*
listener
)
const
{
const
int
diff
=
lhs
-
rhs_
;
const
int
diff
=
lhs
-
rhs_
;
if
(
diff
>
0
)
{
if
(
diff
>
0
)
{
*
listener
<<
"is "
<<
diff
<<
" more than "
<<
rhs_
;
*
listener
<<
"
which
is "
<<
diff
<<
" more than "
<<
rhs_
;
}
else
if
(
diff
==
0
)
{
}
else
if
(
diff
==
0
)
{
*
listener
<<
"is the same as "
<<
rhs_
;
*
listener
<<
"
which
is the same as "
<<
rhs_
;
}
else
{
}
else
{
*
listener
<<
"is "
<<
-
diff
<<
" less than "
<<
rhs_
;
*
listener
<<
"
which
is "
<<
-
diff
<<
" less than "
<<
rhs_
;
}
}
return
lhs
>
rhs_
;
return
lhs
>
rhs_
;
...
@@ -254,32 +291,32 @@ TEST(ElementsAreTest, CanDescribeExpectingNoElement) {
...
@@ -254,32 +291,32 @@ TEST(ElementsAreTest, CanDescribeExpectingNoElement) {
TEST
(
ElementsAreTest
,
CanDescribeExpectingOneElement
)
{
TEST
(
ElementsAreTest
,
CanDescribeExpectingOneElement
)
{
Matcher
<
vector
<
int
>
>
m
=
ElementsAre
(
Gt
(
5
));
Matcher
<
vector
<
int
>
>
m
=
ElementsAre
(
Gt
(
5
));
EXPECT_EQ
(
"has 1 element that is
greater than
5"
,
Describe
(
m
));
EXPECT_EQ
(
"has 1 element that is
>
5"
,
Describe
(
m
));
}
}
TEST
(
ElementsAreTest
,
CanDescribeExpectingManyElements
)
{
TEST
(
ElementsAreTest
,
CanDescribeExpectingManyElements
)
{
Matcher
<
list
<
string
>
>
m
=
ElementsAre
(
StrEq
(
"one"
),
"two"
);
Matcher
<
list
<
string
>
>
m
=
ElementsAre
(
StrEq
(
"one"
),
"two"
);
EXPECT_EQ
(
"has 2 elements where
\n
"
EXPECT_EQ
(
"has 2 elements where
\n
"
"element 0 is equal to
\"
one
\"
,
\n
"
"element
#
0 is equal to
\"
one
\"
,
\n
"
"element 1 is equal to
\"
two
\"
"
,
Describe
(
m
));
"element
#
1 is equal to
\"
two
\"
"
,
Describe
(
m
));
}
}
TEST
(
ElementsAreTest
,
CanDescribeNegationOfExpectingNoElement
)
{
TEST
(
ElementsAreTest
,
CanDescribeNegationOfExpectingNoElement
)
{
Matcher
<
vector
<
int
>
>
m
=
ElementsAre
();
Matcher
<
vector
<
int
>
>
m
=
ElementsAre
();
EXPECT_EQ
(
"is
no
t empty"
,
DescribeNegation
(
m
));
EXPECT_EQ
(
"is
n'
t empty"
,
DescribeNegation
(
m
));
}
}
TEST
(
ElementsAreTest
,
CanDescribeNegationOfExpectingOneElment
)
{
TEST
(
ElementsAreTest
,
CanDescribeNegationOfExpectingOneElment
)
{
Matcher
<
const
list
<
int
>&
>
m
=
ElementsAre
(
Gt
(
5
));
Matcher
<
const
list
<
int
>&
>
m
=
ElementsAre
(
Gt
(
5
));
EXPECT_EQ
(
"does
no
t have 1 element, or
\n
"
EXPECT_EQ
(
"does
n'
t have 1 element, or
\n
"
"element 0 is
not greater than
5"
,
DescribeNegation
(
m
));
"element
#
0 is
n't >
5"
,
DescribeNegation
(
m
));
}
}
TEST
(
ElementsAreTest
,
CanDescribeNegationOfExpectingManyElements
)
{
TEST
(
ElementsAreTest
,
CanDescribeNegationOfExpectingManyElements
)
{
Matcher
<
const
list
<
string
>&
>
m
=
ElementsAre
(
"one"
,
"two"
);
Matcher
<
const
list
<
string
>&
>
m
=
ElementsAre
(
"one"
,
"two"
);
EXPECT_EQ
(
"does
no
t have 2 elements, or
\n
"
EXPECT_EQ
(
"does
n'
t have 2 elements, or
\n
"
"element 0 is
no
t equal to
\"
one
\"
, or
\n
"
"element
#
0 is
n'
t equal to
\"
one
\"
, or
\n
"
"element 1 is
no
t equal to
\"
two
\"
"
,
DescribeNegation
(
m
));
"element
#
1 is
n'
t equal to
\"
two
\"
"
,
DescribeNegation
(
m
));
}
}
TEST
(
ElementsAreTest
,
DoesNotExplainTrivialMatch
)
{
TEST
(
ElementsAreTest
,
DoesNotExplainTrivialMatch
)
{
...
@@ -297,8 +334,9 @@ TEST(ElementsAreTest, ExplainsNonTrivialMatch) {
...
@@ -297,8 +334,9 @@ TEST(ElementsAreTest, ExplainsNonTrivialMatch) {
const
int
a
[]
=
{
10
,
0
,
100
};
const
int
a
[]
=
{
10
,
0
,
100
};
vector
<
int
>
test_vector
(
a
,
a
+
GMOCK_ARRAY_SIZE_
(
a
));
vector
<
int
>
test_vector
(
a
,
a
+
GMOCK_ARRAY_SIZE_
(
a
));
EXPECT_EQ
(
"element 0 is 9 more than 1,
\n
"
EXPECT_EQ
(
"whose element #0 matches, which is 9 more than 1,
\n
"
"element 2 is 98 more than 2"
,
Explain
(
m
,
test_vector
));
"and whose element #2 matches, which is 98 more than 2"
,
Explain
(
m
,
test_vector
));
}
}
TEST
(
ElementsAreTest
,
CanExplainMismatchWrongSize
)
{
TEST
(
ElementsAreTest
,
CanExplainMismatchWrongSize
)
{
...
@@ -309,7 +347,7 @@ TEST(ElementsAreTest, CanExplainMismatchWrongSize) {
...
@@ -309,7 +347,7 @@ TEST(ElementsAreTest, CanExplainMismatchWrongSize) {
EXPECT_EQ
(
""
,
Explain
(
m
,
test_list
));
EXPECT_EQ
(
""
,
Explain
(
m
,
test_list
));
test_list
.
push_back
(
1
);
test_list
.
push_back
(
1
);
EXPECT_EQ
(
"has 1 element"
,
Explain
(
m
,
test_list
));
EXPECT_EQ
(
"
which
has 1 element"
,
Explain
(
m
,
test_list
));
}
}
TEST
(
ElementsAreTest
,
CanExplainMismatchRightSize
)
{
TEST
(
ElementsAreTest
,
CanExplainMismatchRightSize
)
{
...
@@ -318,10 +356,11 @@ TEST(ElementsAreTest, CanExplainMismatchRightSize) {
...
@@ -318,10 +356,11 @@ TEST(ElementsAreTest, CanExplainMismatchRightSize) {
vector
<
int
>
v
;
vector
<
int
>
v
;
v
.
push_back
(
2
);
v
.
push_back
(
2
);
v
.
push_back
(
1
);
v
.
push_back
(
1
);
EXPECT_EQ
(
"element 0 doesn't match"
,
Explain
(
m
,
v
));
EXPECT_EQ
(
"
whose
element
#
0 doesn't match"
,
Explain
(
m
,
v
));
v
[
0
]
=
1
;
v
[
0
]
=
1
;
EXPECT_EQ
(
"element 1 doesn't match (is 4 less than 5)"
,
Explain
(
m
,
v
));
EXPECT_EQ
(
"whose element #1 doesn't match, which is 4 less than 5"
,
Explain
(
m
,
v
));
}
}
TEST
(
ElementsAreTest
,
MatchesOneElementVector
)
{
TEST
(
ElementsAreTest
,
MatchesOneElementVector
)
{
...
@@ -1030,16 +1069,22 @@ TEST(ContainsTest, SetDoesNotMatchWhenElementIsNotInContainer) {
...
@@ -1030,16 +1069,22 @@ TEST(ContainsTest, SetDoesNotMatchWhenElementIsNotInContainer) {
EXPECT_THAT
(
c_string_set
,
Not
(
Contains
(
string
(
"hello"
).
c_str
())));
EXPECT_THAT
(
c_string_set
,
Not
(
Contains
(
string
(
"hello"
).
c_str
())));
}
}
TEST
(
ContainsTest
,
DescribesItself
Correctly
)
{
TEST
(
ContainsTest
,
ExplainsMatchResult
Correctly
)
{
const
int
a
[
2
]
=
{
1
,
2
};
const
int
a
[
2
]
=
{
1
,
2
};
Matcher
<
const
int
(
&
)[
2
]
>
m
=
Contains
(
2
);
Matcher
<
const
int
(
&
)[
2
]
>
m
=
Contains
(
2
);
EXPECT_EQ
(
"element 1 matches"
,
Explain
(
m
,
a
));
EXPECT_EQ
(
"
whose
element
#
1 matches"
,
Explain
(
m
,
a
));
m
=
Contains
(
3
);
m
=
Contains
(
3
);
EXPECT_EQ
(
""
,
Explain
(
m
,
a
));
EXPECT_EQ
(
""
,
Explain
(
m
,
a
));
m
=
Contains
(
GreaterThan
(
0
));
EXPECT_EQ
(
"whose element #0 matches, which is 1 more than 0"
,
Explain
(
m
,
a
));
m
=
Contains
(
GreaterThan
(
10
));
EXPECT_EQ
(
""
,
Explain
(
m
,
a
));
}
}
TEST
(
ContainsTest
,
ExplainsMatchResult
Correctly
)
{
TEST
(
ContainsTest
,
DescribesItself
Correctly
)
{
Matcher
<
vector
<
int
>
>
m
=
Contains
(
1
);
Matcher
<
vector
<
int
>
>
m
=
Contains
(
1
);
EXPECT_EQ
(
"contains at least one element that is equal to 1"
,
Describe
(
m
));
EXPECT_EQ
(
"contains at least one element that is equal to 1"
,
Describe
(
m
));
...
...
test/gmock-matchers_test.cc
View file @
b1c7f93c
This diff is collapsed.
Click to expand it.
test/gmock_output_test_golden.txt
View file @
b1c7f93c
...
@@ -175,8 +175,8 @@ Google Mock tried the following 1 expectation, but it didn't match:
...
@@ -175,8 +175,8 @@ Google Mock tried the following 1 expectation, but it didn't match:
FILE:#: EXPECT_CALL(foo_, Bar(Ref(s), _, Ge(0)))...
FILE:#: EXPECT_CALL(foo_, Bar(Ref(s), _, Ge(0)))...
Expected arg #0: references the variable @0x# "Hi"
Expected arg #0: references the variable @0x# "Hi"
Actual: "Ho"
(
is located @0x#
)
Actual: "Ho"
, which
is located @0x#
Expected arg #2: is
greater than or equal to
0
Expected arg #2: is
>=
0
Actual: -0.1
Actual: -0.1
Expected: to be called once
Expected: to be called once
Actual: never called - unsatisfied and active
Actual: never called - unsatisfied and active
...
@@ -204,7 +204,7 @@ Unexpected mock function call - returning default value.
...
@@ -204,7 +204,7 @@ Unexpected mock function call - returning default value.
Google Mock tried the following 1 expectation, but it didn't match:
Google Mock tried the following 1 expectation, but it didn't match:
FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))...
FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))...
Expected arg #0: is
greater than or equal to
2
Expected arg #0: is
>=
2
Actual: 1
Actual: 1
Expected args: are a pair (x, y) where x >= y
Expected args: are a pair (x, y) where x >= y
Actual: don't match
Actual: don't match
...
...
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