Print mismatches for UnorderedElements() of different sizes.
Changes the behavior of UnorderedElements()/UnorderedElementsAreArray() to print items-without-matchers and matchers-without-items in the case where the actual and expected are different sizes. PiperOrigin-RevId: 635451316 Change-Id: I2181bb28a14c14cdb577af9268d403e12e942bea
This commit is contained in:
parent
33af80a883
commit
c8393f8554
@ -236,9 +236,8 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
|
|||||||
os << "{";
|
os << "{";
|
||||||
const char* sep = "";
|
const char* sep = "";
|
||||||
for (Iter it = pairs.begin(); it != pairs.end(); ++it) {
|
for (Iter it = pairs.begin(); it != pairs.end(); ++it) {
|
||||||
os << sep << "\n ("
|
os << sep << "\n (" << "element #" << it->first << ", " << "matcher #"
|
||||||
<< "element #" << it->first << ", "
|
<< it->second << ")";
|
||||||
<< "matcher #" << it->second << ")";
|
|
||||||
sep = ",";
|
sep = ",";
|
||||||
}
|
}
|
||||||
os << "\n}";
|
os << "\n}";
|
||||||
@ -374,20 +373,20 @@ bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
|
const bool is_exact_match_with_size_discrepency =
|
||||||
if (matrix.LhsSize() != matrix.RhsSize()) {
|
match_flags() == UnorderedMatcherRequire::ExactMatch &&
|
||||||
// The element count doesn't match. If the container is empty,
|
matrix.LhsSize() != matrix.RhsSize();
|
||||||
// there's no need to explain anything as Google Mock already
|
if (is_exact_match_with_size_discrepency) {
|
||||||
// prints the empty container. Otherwise we just need to show
|
// The element count doesn't match. If the container is empty,
|
||||||
// how many elements there actually are.
|
// there's no need to explain anything as Google Mock already
|
||||||
if (matrix.LhsSize() != 0 && listener->IsInterested()) {
|
// prints the empty container. Otherwise we just need to show
|
||||||
*listener << "which has " << Elements(matrix.LhsSize());
|
// how many elements there actually are.
|
||||||
}
|
if (matrix.LhsSize() != 0 && listener->IsInterested()) {
|
||||||
return false;
|
*listener << "which has " << Elements(matrix.LhsSize()) << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = true;
|
bool result = !is_exact_match_with_size_discrepency;
|
||||||
::std::vector<char> element_matched(matrix.LhsSize(), 0);
|
::std::vector<char> element_matched(matrix.LhsSize(), 0);
|
||||||
::std::vector<char> matcher_matched(matrix.RhsSize(), 0);
|
::std::vector<char> matcher_matched(matrix.RhsSize(), 0);
|
||||||
|
|
||||||
|
@ -2014,7 +2014,14 @@ TEST_F(UnorderedElementsAreTest, FailMessageCountWrong) {
|
|||||||
StringMatchResultListener listener;
|
StringMatchResultListener listener;
|
||||||
EXPECT_FALSE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3), v, &listener))
|
EXPECT_FALSE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3), v, &listener))
|
||||||
<< listener.str();
|
<< listener.str();
|
||||||
EXPECT_THAT(listener.str(), Eq("which has 1 element"));
|
EXPECT_THAT(listener.str(),
|
||||||
|
Eq("which has 1 element\n"
|
||||||
|
"where the following matchers don't match any elements:\n"
|
||||||
|
"matcher #0: is equal to 1,\n"
|
||||||
|
"matcher #1: is equal to 2,\n"
|
||||||
|
"matcher #2: is equal to 3\n"
|
||||||
|
"and where the following elements don't match any matchers:\n"
|
||||||
|
"element #0: 4"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UnorderedElementsAreTest, FailMessageCountWrongZero) {
|
TEST_F(UnorderedElementsAreTest, FailMessageCountWrongZero) {
|
||||||
@ -2022,7 +2029,11 @@ TEST_F(UnorderedElementsAreTest, FailMessageCountWrongZero) {
|
|||||||
StringMatchResultListener listener;
|
StringMatchResultListener listener;
|
||||||
EXPECT_FALSE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3), v, &listener))
|
EXPECT_FALSE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3), v, &listener))
|
||||||
<< listener.str();
|
<< listener.str();
|
||||||
EXPECT_THAT(listener.str(), Eq(""));
|
EXPECT_THAT(listener.str(),
|
||||||
|
Eq("where the following matchers don't match any elements:\n"
|
||||||
|
"matcher #0: is equal to 1,\n"
|
||||||
|
"matcher #1: is equal to 2,\n"
|
||||||
|
"matcher #2: is equal to 3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedMatchers) {
|
TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedMatchers) {
|
||||||
@ -2438,7 +2449,7 @@ TEST(UnorderedPointwiseTest, RejectsWrongSize) {
|
|||||||
const double lhs[2] = {1, 2};
|
const double lhs[2] = {1, 2};
|
||||||
const int rhs[1] = {0};
|
const int rhs[1] = {0};
|
||||||
EXPECT_THAT(lhs, Not(UnorderedPointwise(Gt(), rhs)));
|
EXPECT_THAT(lhs, Not(UnorderedPointwise(Gt(), rhs)));
|
||||||
EXPECT_EQ("which has 2 elements",
|
EXPECT_EQ("which has 2 elements\n",
|
||||||
Explain(UnorderedPointwise(Gt(), rhs), lhs));
|
Explain(UnorderedPointwise(Gt(), rhs), lhs));
|
||||||
|
|
||||||
const int rhs2[3] = {0, 1, 2};
|
const int rhs2[3] = {0, 1, 2};
|
||||||
|
Loading…
Reference in New Issue
Block a user