Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
6cbd3753
Commit
6cbd3753
authored
Dec 11, 2018
by
misterg
Committed by
Gennadiy Civil
Dec 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
rollback of 224929783 PiperOrigin-RevId: 225008559
parent
06bb8d4d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
96 deletions
+7
-96
gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+2
-12
gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+5
-84
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
6cbd3753
...
@@ -1296,24 +1296,14 @@ class PredicateFormatterFromMatcher {
...
@@ -1296,24 +1296,14 @@ class PredicateFormatterFromMatcher {
// We don't write MatcherCast<const T&> either, as that allows
// We don't write MatcherCast<const T&> either, as that allows
// potentially unsafe downcasting of the matcher argument.
// potentially unsafe downcasting of the matcher argument.
const
Matcher
<
const
T
&>
matcher
=
SafeMatcherCast
<
const
T
&>
(
matcher_
);
const
Matcher
<
const
T
&>
matcher
=
SafeMatcherCast
<
const
T
&>
(
matcher_
);
StringMatchResultListener
listener
;
// The expected path here is that the matcher should match (i.e. that most
if
(
MatchPrintAndExplain
(
x
,
matcher
,
&
listener
))
// tests pass) so optimize for this case.
if
(
matcher
.
Matches
(
x
))
{
return
AssertionSuccess
();
return
AssertionSuccess
();
}
::
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
);
// Rerun the matcher to "PrintAndExain" the failure.
StringMatchResultListener
listener
;
if
(
MatchPrintAndExplain
(
x
,
matcher
,
&
listener
))
{
ss
<<
"
\n
The matcher failed on the initial attempt; but passed when "
"rerun to generate the explanation."
;
}
ss
<<
"
\n
Actual: "
<<
listener
.
str
();
ss
<<
"
\n
Actual: "
<<
listener
.
str
();
return
AssertionFailure
()
<<
ss
.
str
();
return
AssertionFailure
()
<<
ss
.
str
();
}
}
...
...
googlemock/test/gmock-matchers_test.cc
View file @
6cbd3753
...
@@ -85,7 +85,6 @@ using std::pair;
...
@@ -85,7 +85,6 @@ using std::pair;
using
std
::
set
;
using
std
::
set
;
using
std
::
stringstream
;
using
std
::
stringstream
;
using
std
::
vector
;
using
std
::
vector
;
using
testing
::
_
;
using
testing
::
A
;
using
testing
::
A
;
using
testing
::
AllArgs
;
using
testing
::
AllArgs
;
using
testing
::
AllOf
;
using
testing
::
AllOf
;
...
@@ -111,12 +110,12 @@ using testing::Le;
...
@@ -111,12 +110,12 @@ using testing::Le;
using
testing
::
Lt
;
using
testing
::
Lt
;
using
testing
::
MakeMatcher
;
using
testing
::
MakeMatcher
;
using
testing
::
MakePolymorphicMatcher
;
using
testing
::
MakePolymorphicMatcher
;
using
testing
::
MatchResultListener
;
using
testing
::
Matcher
;
using
testing
::
Matcher
;
using
testing
::
MatcherCast
;
using
testing
::
MatcherCast
;
using
testing
::
MatcherInterface
;
using
testing
::
MatcherInterface
;
using
testing
::
Matches
;
using
testing
::
Matches
;
using
testing
::
MatchesRegex
;
using
testing
::
MatchesRegex
;
using
testing
::
MatchResultListener
;
using
testing
::
NanSensitiveDoubleEq
;
using
testing
::
NanSensitiveDoubleEq
;
using
testing
::
NanSensitiveDoubleNear
;
using
testing
::
NanSensitiveDoubleNear
;
using
testing
::
NanSensitiveFloatEq
;
using
testing
::
NanSensitiveFloatEq
;
...
@@ -136,14 +135,15 @@ using testing::StartsWith;
...
@@ -136,14 +135,15 @@ using testing::StartsWith;
using
testing
::
StrCaseEq
;
using
testing
::
StrCaseEq
;
using
testing
::
StrCaseNe
;
using
testing
::
StrCaseNe
;
using
testing
::
StrEq
;
using
testing
::
StrEq
;
using
testing
::
StringMatchResultListener
;
using
testing
::
StrNe
;
using
testing
::
StrNe
;
using
testing
::
StringMatchResultListener
;
using
testing
::
Truly
;
using
testing
::
Truly
;
using
testing
::
TypedEq
;
using
testing
::
TypedEq
;
using
testing
::
UnorderedPointwise
;
using
testing
::
UnorderedPointwise
;
using
testing
::
Value
;
using
testing
::
Value
;
using
testing
::
WhenSorted
;
using
testing
::
WhenSorted
;
using
testing
::
WhenSortedBy
;
using
testing
::
WhenSortedBy
;
using
testing
::
_
;
using
testing
::
internal
::
DummyMatchResultListener
;
using
testing
::
internal
::
DummyMatchResultListener
;
using
testing
::
internal
::
ElementMatcherPair
;
using
testing
::
internal
::
ElementMatcherPair
;
using
testing
::
internal
::
ElementMatcherPairs
;
using
testing
::
internal
::
ElementMatcherPairs
;
...
@@ -152,11 +152,10 @@ using testing::internal::FloatingEqMatcher;
...
@@ -152,11 +152,10 @@ using testing::internal::FloatingEqMatcher;
using
testing
::
internal
::
FormatMatcherDescription
;
using
testing
::
internal
::
FormatMatcherDescription
;
using
testing
::
internal
::
IsReadableTypeName
;
using
testing
::
internal
::
IsReadableTypeName
;
using
testing
::
internal
::
MatchMatrix
;
using
testing
::
internal
::
MatchMatrix
;
using
testing
::
internal
::
PredicateFormatterFromMatcher
;
using
testing
::
internal
::
RE
;
using
testing
::
internal
::
RE
;
using
testing
::
internal
::
StreamMatchResultListener
;
using
testing
::
internal
::
StreamMatchResultListener
;
using
testing
::
internal
::
string
;
using
testing
::
internal
::
Strings
;
using
testing
::
internal
::
Strings
;
using
testing
::
internal
::
string
;
// For testing ExplainMatchResultTo().
// For testing ExplainMatchResultTo().
class
GreaterThanMatcher
:
public
MatcherInterface
<
int
>
{
class
GreaterThanMatcher
:
public
MatcherInterface
<
int
>
{
...
@@ -4933,7 +4932,7 @@ TYPED_TEST(ContainerEqTest, DuplicateDifference) {
...
@@ -4933,7 +4932,7 @@ TYPED_TEST(ContainerEqTest, DuplicateDifference) {
}
}
#endif // GTEST_HAS_TYPED_TEST
#endif // GTEST_HAS_TYPED_TEST
// Tests that mu
lt
iple missing values are reported.
// Tests that mu
tl
iple missing values are reported.
// Using just vector here, so order is predictable.
// Using just vector here, so order is predictable.
TEST
(
ContainerEqExtraTest
,
MultipleValuesMissing
)
{
TEST
(
ContainerEqExtraTest
,
MultipleValuesMissing
)
{
static
const
int
vals
[]
=
{
1
,
1
,
2
,
3
,
5
,
8
};
static
const
int
vals
[]
=
{
1
,
1
,
2
,
3
,
5
,
8
};
...
@@ -6911,84 +6910,6 @@ TEST(ArgsTest, ExplainsMatchResultWithInnerExplanation) {
...
@@ -6911,84 +6910,6 @@ TEST(ArgsTest, ExplainsMatchResultWithInnerExplanation) {
Explain
(
m
,
std
::
make_tuple
(
'\0'
,
42
,
43
)));
Explain
(
m
,
std
::
make_tuple
(
'\0'
,
42
,
43
)));
}
}
class
PredicateFormatterFromMatcherTest
:
public
::
testing
::
Test
{
protected
:
enum
Behavior
{
kInitialSuccess
,
kAlwaysFail
,
kFlaky
};
// A matcher that can return different results when used multiple times on the
// same input. No real matcher should do this; but this lets us test that we
// detect such behavior and fail appropriately.
class
MockMatcher
:
public
MatcherInterface
<
Behavior
>
{
public
:
bool
MatchAndExplain
(
Behavior
behavior
,
MatchResultListener
*
listener
)
const
override
{
*
listener
<<
"[MatchAndExplain]"
;
switch
(
behavior
)
{
case
kInitialSuccess
:
// The first call to MatchAndExplain should use a "not interested"
// listener; so this is expected to return |true|. There should be no
// subsequent calls.
return
!
listener
->
IsInterested
();
case
kAlwaysFail
:
return
false
;
case
kFlaky
:
// The first call to MatchAndExplain should use a "not interested"
// listener; so this will return |false|. Subsequent calls should have
// an "interested" listener; so this will return |true|, thus
// simulating a flaky matcher.
return
listener
->
IsInterested
();
}
}
void
DescribeTo
(
ostream
*
os
)
const
override
{
*
os
<<
"[DescribeTo]"
;
}
void
DescribeNegationTo
(
ostream
*
os
)
const
override
{
*
os
<<
"[DescribeNegationTo]"
;
}
};
AssertionResult
RunPredicateFormatter
(
Behavior
behavior
)
{
auto
matcher
=
MakeMatcher
(
new
MockMatcher
);
PredicateFormatterFromMatcher
<
Matcher
<
Behavior
>>
predicate_formatter
(
matcher
);
return
predicate_formatter
(
"dummy-name"
,
behavior
);
}
const
std
::
string
kMatcherType
=
"testing::gmock_matchers_test::PredicateFormatterFromMatcherTest::"
"Behavior"
;
};
TEST_F
(
PredicateFormatterFromMatcherTest
,
ShortCircuitOnSuccess
)
{
AssertionResult
result
=
RunPredicateFormatter
(
kInitialSuccess
);
EXPECT_TRUE
(
result
);
// Implicit cast to bool.
EXPECT_EQ
(
""
,
result
.
message
());
}
TEST_F
(
PredicateFormatterFromMatcherTest
,
NoShortCircuitOnFailure
)
{
AssertionResult
result
=
RunPredicateFormatter
(
kAlwaysFail
);
EXPECT_FALSE
(
result
);
// Implicit cast to bool.
std
::
string
expect
=
"Value of: dummy-name
\n
Expected: [DescribeTo]
\n
"
" Actual: 1"
+
OfType
(
kMatcherType
)
+
", [MatchAndExplain]"
;
EXPECT_EQ
(
expect
,
result
.
message
());
}
TEST_F
(
PredicateFormatterFromMatcherTest
,
DetectsFlakyShortCircuit
)
{
AssertionResult
result
=
RunPredicateFormatter
(
kFlaky
);
EXPECT_FALSE
(
result
);
// Implicit cast to bool.
std
::
string
expect
=
"Value of: dummy-name
\n
Expected: [DescribeTo]
\n
"
" The matcher failed on the initial attempt; but passed when rerun to "
"generate the explanation.
\n
"
" Actual: 2"
+
OfType
(
kMatcherType
)
+
", [MatchAndExplain]"
;
EXPECT_EQ
(
expect
,
result
.
message
());
}
}
// namespace gmock_matchers_test
}
// namespace gmock_matchers_test
}
// namespace testing
}
// namespace testing
...
...
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