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
f3eb2b7e
Commit
f3eb2b7e
authored
Oct 20, 2022
by
Denis Hananein
Browse files
Allow naming expectations #3970
Signed-off-by:
Denis Hananein
<
i@zloylos.me
>
parent
e07617d6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
4 deletions
+29
-4
googlemock/include/gmock/gmock-spec-builders.h
googlemock/include/gmock/gmock-spec-builders.h
+21
-2
googlemock/src/gmock-spec-builders.cc
googlemock/src/gmock-spec-builders.cc
+8
-2
No files found.
googlemock/include/gmock/gmock-spec-builders.h
View file @
f3eb2b7e
...
@@ -772,6 +772,10 @@ class GTEST_API_ ExpectationBase {
...
@@ -772,6 +772,10 @@ class GTEST_API_ ExpectationBase {
retired_
=
true
;
retired_
=
true
;
}
}
void
SetName
(
std
::
string
name
)
{
name_
=
std
::
move
(
name
);
}
const
std
::
string
&
GetName
()
const
{
return
name_
;
}
// Returns true if and only if this expectation is satisfied.
// Returns true if and only if this expectation is satisfied.
bool
IsSatisfied
()
const
GTEST_EXCLUSIVE_LOCK_REQUIRED_
(
g_gmock_mutex
)
{
bool
IsSatisfied
()
const
GTEST_EXCLUSIVE_LOCK_REQUIRED_
(
g_gmock_mutex
)
{
g_gmock_mutex
.
AssertHeld
();
g_gmock_mutex
.
AssertHeld
();
...
@@ -831,6 +835,7 @@ class GTEST_API_ ExpectationBase {
...
@@ -831,6 +835,7 @@ class GTEST_API_ ExpectationBase {
const
char
*
file_
;
// The file that contains the expectation.
const
char
*
file_
;
// The file that contains the expectation.
int
line_
;
// The line number of the expectation.
int
line_
;
// The line number of the expectation.
const
std
::
string
source_text_
;
// The EXPECT_CALL(...) source text.
const
std
::
string
source_text_
;
// The EXPECT_CALL(...) source text.
std
::
string
name_
;
// True if and only if the cardinality is specified explicitly.
// True if and only if the cardinality is specified explicitly.
bool
cardinality_specified_
;
bool
cardinality_specified_
;
Cardinality
cardinality_
;
// The cardinality of the expectation.
Cardinality
cardinality_
;
// The cardinality of the expectation.
...
@@ -909,6 +914,11 @@ class TypedExpectation<R(Args...)> : public ExpectationBase {
...
@@ -909,6 +914,11 @@ class TypedExpectation<R(Args...)> : public ExpectationBase {
return
*
this
;
return
*
this
;
}
}
TypedExpectation
&
Name
(
std
::
string
name
)
{
SetName
(
std
::
move
(
name
));
return
*
this
;
}
// Implements the .Times() clause.
// Implements the .Times() clause.
TypedExpectation
&
Times
(
const
Cardinality
&
a_cardinality
)
{
TypedExpectation
&
Times
(
const
Cardinality
&
a_cardinality
)
{
ExpectationBase
::
UntypedTimes
(
a_cardinality
);
ExpectationBase
::
UntypedTimes
(
a_cardinality
);
...
@@ -1199,10 +1209,15 @@ class TypedExpectation<R(Args...)> : public ExpectationBase {
...
@@ -1199,10 +1209,15 @@ class TypedExpectation<R(Args...)> : public ExpectationBase {
::
std
::
ostream
*
why
)
::
std
::
ostream
*
why
)
GTEST_EXCLUSIVE_LOCK_REQUIRED_
(
g_gmock_mutex
)
{
GTEST_EXCLUSIVE_LOCK_REQUIRED_
(
g_gmock_mutex
)
{
g_gmock_mutex
.
AssertHeld
();
g_gmock_mutex
.
AssertHeld
();
const
::
std
::
string
&
expectation_name
=
GetName
();
if
(
IsSaturated
())
{
if
(
IsSaturated
())
{
// We have an excessive call.
// We have an excessive call.
IncrementCallCount
();
IncrementCallCount
();
*
what
<<
"Mock function called more times than expected - "
;
*
what
<<
"Mock function "
;
if
(
!
expectation_name
.
empty
())
{
*
what
<<
"with name
\"
"
<<
expectation_name
<<
"
\"
"
;
}
*
what
<<
"called more times than expected - "
;
mocker
->
DescribeDefaultActionTo
(
args
,
what
);
mocker
->
DescribeDefaultActionTo
(
args
,
what
);
DescribeCallCountTo
(
why
);
DescribeCallCountTo
(
why
);
...
@@ -1217,7 +1232,11 @@ class TypedExpectation<R(Args...)> : public ExpectationBase {
...
@@ -1217,7 +1232,11 @@ class TypedExpectation<R(Args...)> : public ExpectationBase {
}
}
// Must be done after IncrementCount()!
// Must be done after IncrementCount()!
*
what
<<
"Mock function call matches "
<<
source_text
()
<<
"...
\n
"
;
*
what
<<
"Mock function "
;
if
(
!
expectation_name
.
empty
())
{
*
what
<<
"with name
\"
"
<<
expectation_name
<<
"
\"
"
;
}
*
what
<<
"call matches "
<<
source_text
()
<<
"...
\n
"
;
return
&
(
GetCurrentAction
(
mocker
,
args
));
return
&
(
GetCurrentAction
(
mocker
,
args
));
}
}
...
...
googlemock/src/gmock-spec-builders.cc
View file @
f3eb2b7e
...
@@ -409,8 +409,14 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
...
@@ -409,8 +409,14 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
}
else
if
(
!
untyped_expectation
->
IsSatisfied
())
{
}
else
if
(
!
untyped_expectation
->
IsSatisfied
())
{
expectations_met
=
false
;
expectations_met
=
false
;
::
std
::
stringstream
ss
;
::
std
::
stringstream
ss
;
ss
<<
"Actual function call count doesn't match "
<<
untyped_expectation
->
source_text
()
<<
"...
\n
"
;
const
::
std
::
string
&
expectation_name
=
untyped_expectation
->
GetName
();
ss
<<
"Actual function"
;
if
(
!
expectation_name
.
empty
())
{
ss
<<
" with name
\"
"
<<
expectation_name
<<
"
\"
"
;
}
ss
<<
" call count doesn't match "
<<
untyped_expectation
->
source_text
()
<<
"...
\n
"
;
// No need to show the source file location of the expectation
// No need to show the source file location of the expectation
// in the description, as the Expect() call that follows already
// in the description, as the Expect() call that follows already
// takes care of it.
// takes care of it.
...
...
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