Fix unit test failure on a compiler where internal::GetTypeName<int>() returns a different string ("i") than just "int" specified in the unit tests.

This commit is contained in:
Muhammad Hilman Beyri 2020-02-09 15:21:01 -05:00
parent 41b5f149ab
commit c9e75580d3

View File

@ -3018,13 +3018,13 @@ TEST(MatcherAssertionTest, WorksWhenMatcherIsNotSatisfied) {
EXPECT_FATAL_FAILURE(ASSERT_THAT(n, Gt(10)),
"Value of: n\n"
"Expected: is > 10\n"
" Actual: 5" + OfType("unsigned short"));
" Actual: 5" + OfType(internal::GetTypeName<unsigned short>()));
n = 0;
EXPECT_NONFATAL_FAILURE(
EXPECT_THAT(n, AllOf(Le(7), Ge(5))),
"Value of: n\n"
"Expected: (is <= 7) and (is >= 5)\n"
" Actual: 0" + OfType("unsigned short"));
" Actual: 0" + OfType(internal::GetTypeName<unsigned short>()));
}
// Tests that ASSERT_THAT() and EXPECT_THAT() work when the argument
@ -3040,7 +3040,7 @@ TEST(MatcherAssertionTest, WorksForByRefArguments) {
"Expected: does not reference the variable @");
// Tests the "Actual" part.
EXPECT_FATAL_FAILURE(ASSERT_THAT(n, Not(Ref(n))),
"Actual: 0" + OfType("int") + ", which is located @");
"Actual: 0" + OfType(internal::GetTypeName<int>()) + ", which is located @");
}
// Tests that ASSERT_THAT() and EXPECT_THAT() work when the matcher is
@ -3060,7 +3060,7 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
EXPECT_NONFATAL_FAILURE(EXPECT_THAT(5, is_greater_than_5),
"Value of: 5\n"
"Expected: is > 5\n"
" Actual: 5" + OfType("int"));
" Actual: 5" + OfType(internal::GetTypeName<int>()));
}
// Tests floating-point matchers.
@ -3703,14 +3703,14 @@ TEST(PointeeTest, CanExplainMatchResult) {
const Matcher<long*> m2 = Pointee(GreaterThan(1)); // NOLINT
long n = 3; // NOLINT
EXPECT_EQ("which points to 3" + OfType("long") + ", which is 2 more than 1",
EXPECT_EQ("which points to 3" + OfType(internal::GetTypeName<long>()) + ", which is 2 more than 1",
Explain(m2, &n));
}
TEST(PointeeTest, AlwaysExplainsPointee) {
const Matcher<int*> m = Pointee(0);
int n = 42;
EXPECT_EQ("which points to 42" + OfType("int"), Explain(m, &n));
EXPECT_EQ("which points to 42" + OfType(internal::GetTypeName<int>()), Explain(m, &n));
}
// An uncopyable class.
@ -3869,11 +3869,11 @@ TEST(FieldTest, CanExplainMatchResult) {
AStruct a;
a.x = 1;
EXPECT_EQ("whose given field is 1" + OfType("int"), Explain(m, a));
EXPECT_EQ("whose given field is 1" + OfType(internal::GetTypeName<int>()), Explain(m, a));
m = Field(&AStruct::x, GreaterThan(0));
EXPECT_EQ(
"whose given field is 1" + OfType("int") + ", which is 1 more than 0",
"whose given field is 1" + OfType(internal::GetTypeName<int>()) + ", which is 1 more than 0",
Explain(m, a));
}
@ -3882,10 +3882,10 @@ TEST(FieldTest, CanExplainMatchResultWithFieldName) {
AStruct a;
a.x = 1;
EXPECT_EQ("whose field `field_name` is 1" + OfType("int"), Explain(m, a));
EXPECT_EQ("whose field `field_name` is 1" + OfType(internal::GetTypeName<int>()), Explain(m, a));
m = Field("field_name", &AStruct::x, GreaterThan(0));
EXPECT_EQ("whose field `field_name` is 1" + OfType("int") +
EXPECT_EQ("whose field `field_name` is 1" + OfType(internal::GetTypeName<int>()) +
", which is 1 more than 0",
Explain(m, a));
}
@ -3962,11 +3962,11 @@ TEST(FieldForPointerTest, CanExplainMatchResult) {
AStruct a;
a.x = 1;
EXPECT_EQ("", Explain(m, static_cast<const AStruct*>(nullptr)));
EXPECT_EQ("which points to an object whose given field is 1" + OfType("int"),
EXPECT_EQ("which points to an object whose given field is 1" + OfType(internal::GetTypeName<int>()),
Explain(m, &a));
m = Field(&AStruct::x, GreaterThan(0));
EXPECT_EQ("which points to an object whose given field is 1" + OfType("int") +
EXPECT_EQ("which points to an object whose given field is 1" + OfType(internal::GetTypeName<int>()) +
", which is 1 more than 0", Explain(m, &a));
}
@ -3977,12 +3977,12 @@ TEST(FieldForPointerTest, CanExplainMatchResultWithFieldName) {
a.x = 1;
EXPECT_EQ("", Explain(m, static_cast<const AStruct*>(nullptr)));
EXPECT_EQ(
"which points to an object whose field `field_name` is 1" + OfType("int"),
"which points to an object whose field `field_name` is 1" + OfType(internal::GetTypeName<int>()),
Explain(m, &a));
m = Field("field_name", &AStruct::x, GreaterThan(0));
EXPECT_EQ("which points to an object whose field `field_name` is 1" +
OfType("int") + ", which is 1 more than 0",
OfType(internal::GetTypeName<int>()) + ", which is 1 more than 0",
Explain(m, &a));
}
@ -4155,11 +4155,11 @@ TEST(PropertyTest, CanExplainMatchResult) {
AClass a;
a.set_n(1);
EXPECT_EQ("whose given property is 1" + OfType("int"), Explain(m, a));
EXPECT_EQ("whose given property is 1" + OfType(internal::GetTypeName<int>()), Explain(m, a));
m = Property(&AClass::n, GreaterThan(0));
EXPECT_EQ(
"whose given property is 1" + OfType("int") + ", which is 1 more than 0",
"whose given property is 1" + OfType(internal::GetTypeName<int>()) + ", which is 1 more than 0",
Explain(m, a));
}
@ -4168,10 +4168,10 @@ TEST(PropertyTest, CanExplainMatchResultWithPropertyName) {
AClass a;
a.set_n(1);
EXPECT_EQ("whose property `fancy_name` is 1" + OfType("int"), Explain(m, a));
EXPECT_EQ("whose property `fancy_name` is 1" + OfType(internal::GetTypeName<int>()), Explain(m, a));
m = Property("fancy_name", &AClass::n, GreaterThan(0));
EXPECT_EQ("whose property `fancy_name` is 1" + OfType("int") +
EXPECT_EQ("whose property `fancy_name` is 1" + OfType(internal::GetTypeName<int>()) +
", which is 1 more than 0",
Explain(m, a));
}
@ -4259,12 +4259,12 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) {
a.set_n(1);
EXPECT_EQ("", Explain(m, static_cast<const AClass*>(nullptr)));
EXPECT_EQ(
"which points to an object whose given property is 1" + OfType("int"),
"which points to an object whose given property is 1" + OfType(internal::GetTypeName<int>()),
Explain(m, &a));
m = Property(&AClass::n, GreaterThan(0));
EXPECT_EQ("which points to an object whose given property is 1" +
OfType("int") + ", which is 1 more than 0",
OfType(internal::GetTypeName<int>()) + ", which is 1 more than 0",
Explain(m, &a));
}
@ -4275,12 +4275,12 @@ TEST(PropertyForPointerTest, CanExplainMatchResultWithPropertyName) {
a.set_n(1);
EXPECT_EQ("", Explain(m, static_cast<const AClass*>(nullptr)));
EXPECT_EQ("which points to an object whose property `fancy_name` is 1" +
OfType("int"),
OfType(internal::GetTypeName<int>()),
Explain(m, &a));
m = Property("fancy_name", &AClass::n, GreaterThan(0));
EXPECT_EQ("which points to an object whose property `fancy_name` is 1" +
OfType("int") + ", which is 1 more than 0",
OfType(internal::GetTypeName<int>()) + ", which is 1 more than 0",
Explain(m, &a));
}
@ -4314,11 +4314,11 @@ int IntFunction(int input) { return input == 42 ? 80 : 90; }
TEST(ResultOfTest, CanExplainMatchResult) {
Matcher<int> matcher = ResultOf(&IntFunction, Ge(85));
EXPECT_EQ("which is mapped by the given callable to 90" + OfType("int"),
EXPECT_EQ("which is mapped by the given callable to 90" + OfType(internal::GetTypeName<int>()),
Explain(matcher, 36));
matcher = ResultOf(&IntFunction, GreaterThan(85));
EXPECT_EQ("which is mapped by the given callable to 90" + OfType("int") +
EXPECT_EQ("which is mapped by the given callable to 90" + OfType(internal::GetTypeName<int>()) +
", which is 5 more than 85", Explain(matcher, 36));
}