From c9e75580d3992699c179b4b1a7a6f73db4a89104 Mon Sep 17 00:00:00 2001 From: Muhammad Hilman Beyri Date: Sun, 9 Feb 2020 15:21:01 -0500 Subject: [PATCH] Fix unit test failure on a compiler where internal::GetTypeName() returns a different string ("i") than just "int" specified in the unit tests. --- googlemock/test/gmock-matchers_test.cc | 48 +++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 2bcbe5cf..3cf41a2a 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -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())); 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())); } // 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()) + ", 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())); } // Tests floating-point matchers. @@ -3703,14 +3703,14 @@ TEST(PointeeTest, CanExplainMatchResult) { const Matcher 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()) + ", which is 2 more than 1", Explain(m2, &n)); } TEST(PointeeTest, AlwaysExplainsPointee) { const Matcher 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()), 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()), 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()) + ", 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()), 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()) + ", 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(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()), 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()) + ", 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(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()), 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()) + ", 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()), 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()) + ", 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()), 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()) + ", 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(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()), 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()) + ", 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(nullptr))); EXPECT_EQ("which points to an object whose property `fancy_name` is 1" + - OfType("int"), + OfType(internal::GetTypeName()), 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()) + ", 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 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()), 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()) + ", which is 5 more than 85", Explain(matcher, 36)); }