Include the param names in the generated description of the MATCHER_P matchers.

PiperOrigin-RevId: 418497526
Change-Id: Ie53c3c0810c10a32cbcb941e3ca1ee8fb1ddd9f9
This commit is contained in:
Abseil Team
2021-12-27 08:05:24 -08:00
committed by Copybara-Service
parent d81ae2f0bf
commit 6b74da4757
7 changed files with 83 additions and 65 deletions
+11 -12
View File
@@ -70,24 +70,23 @@ namespace internal {
namespace {
TEST(JoinAsTupleTest, JoinsEmptyTuple) {
EXPECT_EQ("", JoinAsTuple(Strings()));
TEST(JoinAsKeyValueTupleTest, JoinsEmptyTuple) {
EXPECT_EQ("", JoinAsKeyValueTuple({}, Strings()));
}
TEST(JoinAsTupleTest, JoinsOneTuple) {
const char* fields[] = {"1"};
EXPECT_EQ("1", JoinAsTuple(Strings(fields, fields + 1)));
TEST(JoinAsKeyValueTupleTest, JoinsOneTuple) {
EXPECT_EQ("(a: 1)", JoinAsKeyValueTuple({"a"}, {"1"}));
}
TEST(JoinAsTupleTest, JoinsTwoTuple) {
const char* fields[] = {"1", "a"};
EXPECT_EQ("(1, a)", JoinAsTuple(Strings(fields, fields + 2)));
TEST(JoinAsKeyValueTupleTest, JoinsTwoTuple) {
EXPECT_EQ("(a: 1, b: 2)", JoinAsKeyValueTuple({"a", "b"}, {"1", "2"}));
}
TEST(JoinAsTupleTest, JoinsTenTuple) {
const char* fields[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
EXPECT_EQ("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)",
JoinAsTuple(Strings(fields, fields + 10)));
TEST(JoinAsKeyValueTupleTest, JoinsTenTuple) {
EXPECT_EQ(
"(a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10)",
JoinAsKeyValueTuple({"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}));
}
TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
+20 -19
View File
@@ -6439,19 +6439,16 @@ TEST(IsReadableTypeNameTest, ReturnsFalseForLongFunctionTypeNames) {
TEST(FormatMatcherDescriptionTest, WorksForEmptyDescription) {
EXPECT_EQ("is even",
FormatMatcherDescription(false, "IsEven", Strings()));
FormatMatcherDescription(false, "IsEven", {}, Strings()));
EXPECT_EQ("not (is even)",
FormatMatcherDescription(true, "IsEven", Strings()));
FormatMatcherDescription(true, "IsEven", {}, Strings()));
const char* params[] = {"5"};
EXPECT_EQ("equals 5",
FormatMatcherDescription(false, "Equals",
Strings(params, params + 1)));
EXPECT_EQ("equals (a: 5)",
FormatMatcherDescription(false, "Equals", {"a"}, {"5"}));
const char* params2[] = {"5", "8"};
EXPECT_EQ("is in range (5, 8)",
FormatMatcherDescription(false, "IsInRange",
Strings(params2, params2 + 2)));
EXPECT_EQ(
"is in range (a: 5, b: 8)",
FormatMatcherDescription(false, "IsInRange", {"a", "b"}, {"5", "8"}));
}
// Tests PolymorphicMatcher::mutable_impl().
@@ -7810,8 +7807,8 @@ TEST(MatcherPMacroTest, Works) {
EXPECT_TRUE(m.Matches(36));
EXPECT_FALSE(m.Matches(5));
EXPECT_EQ("is greater than 32 and 5", Describe(m));
EXPECT_EQ("not (is greater than 32 and 5)", DescribeNegation(m));
EXPECT_EQ("is greater than 32 and (n: 5)", Describe(m));
EXPECT_EQ("not (is greater than 32 and (n: 5))", DescribeNegation(m));
EXPECT_EQ("", Explain(m, 36));
EXPECT_EQ("", Explain(m, 5));
}
@@ -7822,8 +7819,8 @@ MATCHER_P(_is_Greater_Than32and_, n, "") { return arg > 32 && arg > n; }
TEST(MatcherPMacroTest, GeneratesCorrectDescription) {
const Matcher<int> m = _is_Greater_Than32and_(5);
EXPECT_EQ("is greater than 32 and 5", Describe(m));
EXPECT_EQ("not (is greater than 32 and 5)", DescribeNegation(m));
EXPECT_EQ("is greater than 32 and (n: 5)", Describe(m));
EXPECT_EQ("not (is greater than 32 and (n: 5))", DescribeNegation(m));
EXPECT_EQ("", Explain(m, 36));
EXPECT_EQ("", Explain(m, 5));
}
@@ -7856,7 +7853,8 @@ TEST(MatcherPMacroTest, WorksWhenExplicitlyInstantiatedWithReference) {
// likely it will just annoy the user. If the address is
// interesting, the user should consider passing the parameter by
// pointer instead.
EXPECT_EQ("references uncopyable 1-byte object <31>", Describe(m));
EXPECT_EQ("references uncopyable (variable: 1-byte object <31>)",
Describe(m));
}
// Tests that the body of MATCHER_Pn() can reference the parameter
@@ -7907,8 +7905,10 @@ TEST(MatcherPnMacroTest,
// likely they will just annoy the user. If the addresses are
// interesting, the user should consider passing the parameters by
// pointers instead.
EXPECT_EQ("references any of (1-byte object <31>, 1-byte object <32>)",
Describe(m));
EXPECT_EQ(
"references any of (variable1: 1-byte object <31>, variable2: 1-byte "
"object <32>)",
Describe(m));
}
// Tests that a simple MATCHER_P2() definition works.
@@ -7920,8 +7920,9 @@ TEST(MatcherPnMacroTest, Works) {
EXPECT_TRUE(m.Matches(36L));
EXPECT_FALSE(m.Matches(15L));
EXPECT_EQ("is not in closed range (10, 20)", Describe(m));
EXPECT_EQ("not (is not in closed range (10, 20))", DescribeNegation(m));
EXPECT_EQ("is not in closed range (low: 10, hi: 20)", Describe(m));
EXPECT_EQ("not (is not in closed range (low: 10, hi: 20))",
DescribeNegation(m));
EXPECT_EQ("", Explain(m, 36L));
EXPECT_EQ("", Explain(m, 15L));
}
+1 -1
View File
@@ -291,7 +291,7 @@ Stack trace:
[ RUN ] GMockOutputTest.PrintsMatcher
FILE:#: Failure
Value of: (std::pair<int, bool>(42, true))
Expected: is pair (is >= 48, true)
Expected: is pair (first: is >= 48, second: true)
Actual: (42, true) (of type std::pair<int, bool>)
[ FAILED ] GMockOutputTest.PrintsMatcher
[ FAILED ] GMockOutputTest.UnexpectedCall