Change error message of EXPECT_EQ to treat lhs and rhs equivalently.

pull/713/head
Alexey Sokolov 9 years ago
parent ff5ffd457e
commit f364e18837
  1. 4
      googletest/docs/AdvancedGuide.md
  2. 28
      googletest/docs/Primer.md
  3. 204
      googletest/include/gtest/gtest.h
  4. 120
      googletest/src/gtest.cc
  5. 114
      googletest/test/gtest_output_test_golden_lin.txt
  6. 95
      googletest/test/gtest_unittest.cc
  7. 18
      googletest/test/gtest_xml_output_unittest.py

@ -312,8 +312,8 @@ want to learn more, see
| **Fatal assertion** | **Nonfatal assertion** | **Verifies** | | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
|:--------------------|:-----------------------|:-------------| |:--------------------|:-----------------------|:-------------|
| `ASSERT_FLOAT_EQ(`_expected, actual_`);` | `EXPECT_FLOAT_EQ(`_expected, actual_`);` | the two `float` values are almost equal | | `ASSERT_FLOAT_EQ(`_val1, val2_`);` | `EXPECT_FLOAT_EQ(`_val1, val2_`);` | the two `float` values are almost equal |
| `ASSERT_DOUBLE_EQ(`_expected, actual_`);` | `EXPECT_DOUBLE_EQ(`_expected, actual_`);` | the two `double` values are almost equal | | `ASSERT_DOUBLE_EQ(`_val1, val2_`);` | `EXPECT_DOUBLE_EQ(`_val1, val2_`);` | the two `double` values are almost equal |
By "almost equal", we mean the two values are within 4 ULP's from each By "almost equal", we mean the two values are within 4 ULP's from each
other. other.

@ -127,18 +127,14 @@ This section describes assertions that compare two values.
| **Fatal assertion** | **Nonfatal assertion** | **Verifies** | | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
|:--------------------|:-----------------------|:-------------| |:--------------------|:-----------------------|:-------------|
|`ASSERT_EQ(`_expected_`, `_actual_`);`|`EXPECT_EQ(`_expected_`, `_actual_`);`| _expected_ `==` _actual_ | |`ASSERT_EQ(`_val1_`, `_val2_`);`|`EXPECT_EQ(`_val1_`, `_val2_`);`| _val1_ `==` _val2_ |
|`ASSERT_NE(`_val1_`, `_val2_`);` |`EXPECT_NE(`_val1_`, `_val2_`);` | _val1_ `!=` _val2_ | |`ASSERT_NE(`_val1_`, `_val2_`);`|`EXPECT_NE(`_val1_`, `_val2_`);`| _val1_ `!=` _val2_ |
|`ASSERT_LT(`_val1_`, `_val2_`);` |`EXPECT_LT(`_val1_`, `_val2_`);` | _val1_ `<` _val2_ | |`ASSERT_LT(`_val1_`, `_val2_`);`|`EXPECT_LT(`_val1_`, `_val2_`);`| _val1_ `<` _val2_ |
|`ASSERT_LE(`_val1_`, `_val2_`);` |`EXPECT_LE(`_val1_`, `_val2_`);` | _val1_ `<=` _val2_ | |`ASSERT_LE(`_val1_`, `_val2_`);`|`EXPECT_LE(`_val1_`, `_val2_`);`| _val1_ `<=` _val2_ |
|`ASSERT_GT(`_val1_`, `_val2_`);` |`EXPECT_GT(`_val1_`, `_val2_`);` | _val1_ `>` _val2_ | |`ASSERT_GT(`_val1_`, `_val2_`);`|`EXPECT_GT(`_val1_`, `_val2_`);`| _val1_ `>` _val2_ |
|`ASSERT_GE(`_val1_`, `_val2_`);` |`EXPECT_GE(`_val1_`, `_val2_`);` | _val1_ `>=` _val2_ | |`ASSERT_GE(`_val1_`, `_val2_`);`|`EXPECT_GE(`_val1_`, `_val2_`);`| _val1_ `>=` _val2_ |
In the event of a failure, Google Test prints both _val1_ and _val2_ In the event of a failure, Google Test prints both _val1_ and _val2_.
. In `ASSERT_EQ*` and `EXPECT_EQ*` (and all other equality assertions
we'll introduce later), you should put the expression you want to test
in the position of _actual_, and put its expected value in _expected_,
as Google Test's failure messages are optimized for this convention.
Value arguments must be comparable by the assertion's comparison Value arguments must be comparable by the assertion's comparison
operator or you'll get a compiler error. We used to require the operator or you'll get a compiler error. We used to require the
@ -172,6 +168,10 @@ and `wstring`).
_Availability_: Linux, Windows, Mac. _Availability_: Linux, Windows, Mac.
_Historical note_: Before February 2016 `*_EQ` had a convention of calling it as
`ASSERT_EQ(expected, actual)`, so lots of existing code uses this order.
Now `*_EQ` treats both parameters in the same way.
## String Comparison ## ## String Comparison ##
The assertions in this group compare two **C strings**. If you want to compare The assertions in this group compare two **C strings**. If you want to compare
@ -179,9 +179,9 @@ two `string` objects, use `EXPECT_EQ`, `EXPECT_NE`, and etc instead.
| **Fatal assertion** | **Nonfatal assertion** | **Verifies** | | **Fatal assertion** | **Nonfatal assertion** | **Verifies** |
|:--------------------|:-----------------------|:-------------| |:--------------------|:-----------------------|:-------------|
| `ASSERT_STREQ(`_expected\_str_`, `_actual\_str_`);` | `EXPECT_STREQ(`_expected\_str_`, `_actual\_str_`);` | the two C strings have the same content | | `ASSERT_STREQ(`_str1_`, `_str2_`);` | `EXPECT_STREQ(`_str1_`, `_str_2`);` | the two C strings have the same content |
| `ASSERT_STRNE(`_str1_`, `_str2_`);` | `EXPECT_STRNE(`_str1_`, `_str2_`);` | the two C strings have different content | | `ASSERT_STRNE(`_str1_`, `_str2_`);` | `EXPECT_STRNE(`_str1_`, `_str2_`);` | the two C strings have different content |
| `ASSERT_STRCASEEQ(`_expected\_str_`, `_actual\_str_`);`| `EXPECT_STRCASEEQ(`_expected\_str_`, `_actual\_str_`);` | the two C strings have the same content, ignoring case | | `ASSERT_STRCASEEQ(`_str1_`, `_str2_`);`| `EXPECT_STRCASEEQ(`_str1_`, `_str2_`);` | the two C strings have the same content, ignoring case |
| `ASSERT_STRCASENE(`_str1_`, `_str2_`);`| `EXPECT_STRCASENE(`_str1_`, `_str2_`);` | the two C strings have different content, ignoring case | | `ASSERT_STRCASENE(`_str1_`, `_str2_`);`| `EXPECT_STRCASENE(`_str1_`, `_str2_`);` | the two C strings have different content, ignoring case |
Note that "CASE" in an assertion name means that case is ignored. Note that "CASE" in an assertion name means that case is ignored.

@ -1372,39 +1372,38 @@ namespace internal {
// frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers // frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers
// when calling EXPECT_* in a tight loop. // when calling EXPECT_* in a tight loop.
template <typename T1, typename T2> template <typename T1, typename T2>
AssertionResult CmpHelperEQFailure(const char* expected_expression, AssertionResult CmpHelperEQFailure(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
const T1& expected, const T2& actual) { const T1& lhs, const T2& rhs) {
return EqFailure(expected_expression, return EqFailure(lhs_expression,
actual_expression, rhs_expression,
FormatForComparisonFailureMessage(expected, actual), FormatForComparisonFailureMessage(lhs, rhs),
FormatForComparisonFailureMessage(actual, expected), FormatForComparisonFailureMessage(rhs, lhs),
false); false);
} }
// The helper function for {ASSERT|EXPECT}_EQ. // The helper function for {ASSERT|EXPECT}_EQ.
template <typename T1, typename T2> template <typename T1, typename T2>
AssertionResult CmpHelperEQ(const char* expected_expression, AssertionResult CmpHelperEQ(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
const T1& expected, const T1& lhs,
const T2& actual) { const T2& rhs) {
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 /* signed/unsigned mismatch */) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 /* signed/unsigned mismatch */)
if (expected == actual) { if (lhs == rhs) {
return AssertionSuccess(); return AssertionSuccess();
} }
GTEST_DISABLE_MSC_WARNINGS_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()
return CmpHelperEQFailure(expected_expression, actual_expression, expected, return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
actual);
} }
// With this overloaded version, we allow anonymous enums to be used // With this overloaded version, we allow anonymous enums to be used
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
// can be implicitly cast to BiggestInt. // can be implicitly cast to BiggestInt.
GTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression, GTEST_API_ AssertionResult CmpHelperEQ(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
BiggestInt expected, BiggestInt lhs,
BiggestInt actual); BiggestInt rhs);
// The helper class for {ASSERT|EXPECT}_EQ. The template argument // The helper class for {ASSERT|EXPECT}_EQ. The template argument
// lhs_is_null_literal is true iff the first argument to ASSERT_EQ() // lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
@ -1415,12 +1414,11 @@ class EqHelper {
public: public:
// This templatized version is for the general case. // This templatized version is for the general case.
template <typename T1, typename T2> template <typename T1, typename T2>
static AssertionResult Compare(const char* expected_expression, static AssertionResult Compare(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
const T1& expected, const T1& lhs,
const T2& actual) { const T2& rhs) {
return CmpHelperEQ(expected_expression, actual_expression, expected, return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
actual);
} }
// With this overloaded version, we allow anonymous enums to be used // With this overloaded version, we allow anonymous enums to be used
@ -1429,12 +1427,11 @@ class EqHelper {
// //
// Even though its body looks the same as the above version, we // Even though its body looks the same as the above version, we
// cannot merge the two, as it will make anonymous enums unhappy. // cannot merge the two, as it will make anonymous enums unhappy.
static AssertionResult Compare(const char* expected_expression, static AssertionResult Compare(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
BiggestInt expected, BiggestInt lhs,
BiggestInt actual) { BiggestInt rhs) {
return CmpHelperEQ(expected_expression, actual_expression, expected, return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
actual);
} }
}; };
@ -1449,37 +1446,36 @@ class EqHelper<true> {
// EXPECT_EQ(false, a_bool). // EXPECT_EQ(false, a_bool).
template <typename T1, typename T2> template <typename T1, typename T2>
static AssertionResult Compare( static AssertionResult Compare(
const char* expected_expression, const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
const T1& expected, const T1& lhs,
const T2& actual, const T2& rhs,
// The following line prevents this overload from being considered if T2 // The following line prevents this overload from being considered if T2
// is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr) // is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr)
// expands to Compare("", "", NULL, my_ptr), which requires a conversion // expands to Compare("", "", NULL, my_ptr), which requires a conversion
// to match the Secret* in the other overload, which would otherwise make // to match the Secret* in the other overload, which would otherwise make
// this template match better. // this template match better.
typename EnableIf<!is_pointer<T2>::value>::type* = 0) { typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
return CmpHelperEQ(expected_expression, actual_expression, expected, return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
actual);
} }
// This version will be picked when the second argument to ASSERT_EQ() is a // This version will be picked when the second argument to ASSERT_EQ() is a
// pointer, e.g. ASSERT_EQ(NULL, a_pointer). // pointer, e.g. ASSERT_EQ(NULL, a_pointer).
template <typename T> template <typename T>
static AssertionResult Compare( static AssertionResult Compare(
const char* expected_expression, const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
// We used to have a second template parameter instead of Secret*. That // We used to have a second template parameter instead of Secret*. That
// template parameter would deduce to 'long', making this a better match // template parameter would deduce to 'long', making this a better match
// than the first overload even without the first overload's EnableIf. // than the first overload even without the first overload's EnableIf.
// Unfortunately, gcc with -Wconversion-null warns when "passing NULL to // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
// non-pointer argument" (even a deduced integral argument), so the old // non-pointer argument" (even a deduced integral argument), so the old
// implementation caused warnings in user code. // implementation caused warnings in user code.
Secret* /* expected (NULL) */, Secret* /* lhs (NULL) */,
T* actual) { T* rhs) {
// We already know that 'expected' is a null pointer. // We already know that 'lhs' is a null pointer.
return CmpHelperEQ(expected_expression, actual_expression, return CmpHelperEQ(lhs_expression, rhs_expression,
static_cast<T*>(NULL), actual); static_cast<T*>(NULL), rhs);
} }
}; };
@ -1538,18 +1534,18 @@ GTEST_IMPL_CMP_HELPER_(GT, >);
// The helper function for {ASSERT|EXPECT}_STREQ. // The helper function for {ASSERT|EXPECT}_STREQ.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression, GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
const char* actual_expression, const char* s2_expression,
const char* expected, const char* s1,
const char* actual); const char* s2);
// The helper function for {ASSERT|EXPECT}_STRCASEEQ. // The helper function for {ASSERT|EXPECT}_STRCASEEQ.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression, GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression,
const char* actual_expression, const char* s2_expression,
const char* expected, const char* s1,
const char* actual); const char* s2);
// The helper function for {ASSERT|EXPECT}_STRNE. // The helper function for {ASSERT|EXPECT}_STRNE.
// //
@ -1571,10 +1567,10 @@ GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
// Helper function for *_STREQ on wide strings. // Helper function for *_STREQ on wide strings.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression, GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
const char* actual_expression, const char* s2_expression,
const wchar_t* expected, const wchar_t* s1,
const wchar_t* actual); const wchar_t* s2);
// Helper function for *_STRNE on wide strings. // Helper function for *_STRNE on wide strings.
// //
@ -1632,28 +1628,28 @@ namespace internal {
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
template <typename RawType> template <typename RawType>
AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression, AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
RawType expected, RawType lhs_value,
RawType actual) { RawType rhs_value) {
const FloatingPoint<RawType> lhs(expected), rhs(actual); const FloatingPoint<RawType> lhs(lhs_value), rhs(rhs_value);
if (lhs.AlmostEquals(rhs)) { if (lhs.AlmostEquals(rhs)) {
return AssertionSuccess(); return AssertionSuccess();
} }
::std::stringstream expected_ss; ::std::stringstream lhs_ss;
expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) lhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
<< expected; << lhs_value;
::std::stringstream actual_ss; ::std::stringstream rhs_ss;
actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) rhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
<< actual; << rhs_value;
return EqFailure(expected_expression, return EqFailure(lhs_expression,
actual_expression, rhs_expression,
StringStreamToString(&expected_ss), StringStreamToString(&lhs_ss),
StringStreamToString(&actual_ss), StringStreamToString(&rhs_ss),
false); false);
} }
@ -1879,12 +1875,12 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// Macros for testing equalities and inequalities. // Macros for testing equalities and inequalities.
// //
// * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual // * {ASSERT|EXPECT}_EQ(v1, v2): Tests that v1 == v2
// * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2 // * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
// * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2 // * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
// * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2 // * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
// * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2 // * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
// * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2 // * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
// //
// When they are not, Google Test prints both the tested expressions and // When they are not, Google Test prints both the tested expressions and
// their actual values. The values must be compatible built-in types, // their actual values. The values must be compatible built-in types,
@ -1906,8 +1902,8 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// are related, not how their content is related. To compare two C // are related, not how their content is related. To compare two C
// strings by content, use {ASSERT|EXPECT}_STR*(). // strings by content, use {ASSERT|EXPECT}_STR*().
// //
// 3. {ASSERT|EXPECT}_EQ(expected, actual) is preferred to // 3. {ASSERT|EXPECT}_EQ(v1, v2) is preferred to
// {ASSERT|EXPECT}_TRUE(expected == actual), as the former tells you // {ASSERT|EXPECT}_TRUE(v1 == v2), as the former tells you
// what the actual value is when it fails, and similarly for the // what the actual value is when it fails, and similarly for the
// other comparisons. // other comparisons.
// //
@ -1923,12 +1919,12 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// ASSERT_LT(i, array_size); // ASSERT_LT(i, array_size);
// ASSERT_GT(records.size(), 0) << "There is no record left."; // ASSERT_GT(records.size(), 0) << "There is no record left.";
#define EXPECT_EQ(expected, actual) \ #define EXPECT_EQ(val1, val2) \
EXPECT_PRED_FORMAT2(::testing::internal:: \ EXPECT_PRED_FORMAT2(::testing::internal:: \
EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \ EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
expected, actual) val1, val2)
#define EXPECT_NE(expected, actual) \ #define EXPECT_NE(val1, val2) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
#define EXPECT_LE(val1, val2) \ #define EXPECT_LE(val1, val2) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
#define EXPECT_LT(val1, val2) \ #define EXPECT_LT(val1, val2) \
@ -1938,10 +1934,10 @@ class TestWithParam : public Test, public WithParamInterface<T> {
#define EXPECT_GT(val1, val2) \ #define EXPECT_GT(val1, val2) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
#define GTEST_ASSERT_EQ(expected, actual) \ #define GTEST_ASSERT_EQ(val1, val2) \
ASSERT_PRED_FORMAT2(::testing::internal:: \ ASSERT_PRED_FORMAT2(::testing::internal:: \
EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \ EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
expected, actual) val1, val2)
#define GTEST_ASSERT_NE(val1, val2) \ #define GTEST_ASSERT_NE(val1, val2) \
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
#define GTEST_ASSERT_LE(val1, val2) \ #define GTEST_ASSERT_LE(val1, val2) \
@ -1996,29 +1992,29 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// //
// These macros evaluate their arguments exactly once. // These macros evaluate their arguments exactly once.
#define EXPECT_STREQ(expected, actual) \ #define EXPECT_STREQ(s1, s2) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
#define EXPECT_STRNE(s1, s2) \ #define EXPECT_STRNE(s1, s2) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
#define EXPECT_STRCASEEQ(expected, actual) \ #define EXPECT_STRCASEEQ(s1, s2) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
#define EXPECT_STRCASENE(s1, s2)\ #define EXPECT_STRCASENE(s1, s2)\
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
#define ASSERT_STREQ(expected, actual) \ #define ASSERT_STREQ(s1, s2) \
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
#define ASSERT_STRNE(s1, s2) \ #define ASSERT_STRNE(s1, s2) \
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
#define ASSERT_STRCASEEQ(expected, actual) \ #define ASSERT_STRCASEEQ(s1, s2) \
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
#define ASSERT_STRCASENE(s1, s2)\ #define ASSERT_STRCASENE(s1, s2)\
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
// Macros for comparing floating-point numbers. // Macros for comparing floating-point numbers.
// //
// * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual): // * {ASSERT|EXPECT}_FLOAT_EQ(val1, val2):
// Tests that two float values are almost equal. // Tests that two float values are almost equal.
// * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual): // * {ASSERT|EXPECT}_DOUBLE_EQ(val1, val2):
// Tests that two double values are almost equal. // Tests that two double values are almost equal.
// * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): // * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
// Tests that v1 and v2 are within the given distance to each other. // Tests that v1 and v2 are within the given distance to each other.
@ -2028,21 +2024,21 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// FloatingPoint template class in gtest-internal.h if you are // FloatingPoint template class in gtest-internal.h if you are
// interested in the implementation details. // interested in the implementation details.
#define EXPECT_FLOAT_EQ(expected, actual)\ #define EXPECT_FLOAT_EQ(val1, val2)\
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
expected, actual) val1, val2)
#define EXPECT_DOUBLE_EQ(expected, actual)\ #define EXPECT_DOUBLE_EQ(val1, val2)\
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
expected, actual) val1, val2)
#define ASSERT_FLOAT_EQ(expected, actual)\ #define ASSERT_FLOAT_EQ(val1, val2)\
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
expected, actual) val1, val2)
#define ASSERT_DOUBLE_EQ(expected, actual)\ #define ASSERT_DOUBLE_EQ(val1, val2)\
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
expected, actual) val1, val2)
#define EXPECT_NEAR(val1, val2, abs_error)\ #define EXPECT_NEAR(val1, val2, abs_error)\
EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \ EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \

@ -1301,41 +1301,41 @@ std::vector<std::string> SplitEscapedString(const std::string& str) {
// and their values, as strings. For example, for ASSERT_EQ(foo, bar) // and their values, as strings. For example, for ASSERT_EQ(foo, bar)
// where foo is 5 and bar is 6, we have: // where foo is 5 and bar is 6, we have:
// //
// expected_expression: "foo" // lhs_expression: "foo"
// actual_expression: "bar" // rhs_expression: "bar"
// expected_value: "5" // lhs_value: "5"
// actual_value: "6" // rhs_value: "6"
// //
// The ignoring_case parameter is true iff the assertion is a // The ignoring_case parameter is true iff the assertion is a
// *_STRCASEEQ*. When it's true, the string " (ignoring case)" will // *_STRCASEEQ*. When it's true, the string "Ignoring case" will
// be inserted into the message. // be inserted into the message.
AssertionResult EqFailure(const char* expected_expression, AssertionResult EqFailure(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
const std::string& expected_value, const std::string& lhs_value,
const std::string& actual_value, const std::string& rhs_value,
bool ignoring_case) { bool ignoring_case) {
Message msg; Message msg;
msg << "Value of: " << actual_expression; msg << " Expected: " << lhs_expression;
if (actual_value != actual_expression) { if (lhs_value != lhs_expression) {
msg << "\n Actual: " << actual_value; msg << "\n Which is: " << lhs_value;
}
msg << "\nTo be equal to: " << rhs_expression;
if (rhs_value != rhs_expression) {
msg << "\n Which is: " << rhs_value;
} }
msg << "\nExpected: " << expected_expression;
if (ignoring_case) { if (ignoring_case) {
msg << " (ignoring case)"; msg << "\nIgnoring case";
}
if (expected_value != expected_expression) {
msg << "\nWhich is: " << expected_value;
} }
if (!expected_value.empty() && !actual_value.empty()) { if (!lhs_value.empty() && !rhs_value.empty()) {
const std::vector<std::string> expected_lines = const std::vector<std::string> lhs_lines =
SplitEscapedString(expected_value); SplitEscapedString(lhs_value);
const std::vector<std::string> actual_lines = const std::vector<std::string> rhs_lines =
SplitEscapedString(actual_value); SplitEscapedString(rhs_value);
if (expected_lines.size() > 1 || actual_lines.size() > 1) { if (lhs_lines.size() > 1 || rhs_lines.size() > 1) {
msg << "\nWith diff:\n" msg << "\nWith diff:\n"
<< edit_distance::CreateUnifiedDiff(expected_lines, actual_lines); << edit_distance::CreateUnifiedDiff(lhs_lines, rhs_lines);
} }
} }
@ -1434,18 +1434,18 @@ namespace internal {
// The helper function for {ASSERT|EXPECT}_EQ with int or enum // The helper function for {ASSERT|EXPECT}_EQ with int or enum
// arguments. // arguments.
AssertionResult CmpHelperEQ(const char* expected_expression, AssertionResult CmpHelperEQ(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
BiggestInt expected, BiggestInt lhs,
BiggestInt actual) { BiggestInt rhs) {
if (expected == actual) { if (lhs == rhs) {
return AssertionSuccess(); return AssertionSuccess();
} }
return EqFailure(expected_expression, return EqFailure(lhs_expression,
actual_expression, rhs_expression,
FormatForComparisonFailureMessage(expected, actual), FormatForComparisonFailureMessage(lhs, rhs),
FormatForComparisonFailureMessage(actual, expected), FormatForComparisonFailureMessage(rhs, lhs),
false); false);
} }
@ -1484,34 +1484,34 @@ GTEST_IMPL_CMP_HELPER_(GT, > )
#undef GTEST_IMPL_CMP_HELPER_ #undef GTEST_IMPL_CMP_HELPER_
// The helper function for {ASSERT|EXPECT}_STREQ. // The helper function for {ASSERT|EXPECT}_STREQ.
AssertionResult CmpHelperSTREQ(const char* expected_expression, AssertionResult CmpHelperSTREQ(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
const char* expected, const char* lhs,
const char* actual) { const char* rhs) {
if (String::CStringEquals(expected, actual)) { if (String::CStringEquals(lhs, rhs)) {
return AssertionSuccess(); return AssertionSuccess();
} }
return EqFailure(expected_expression, return EqFailure(lhs_expression,
actual_expression, rhs_expression,
PrintToString(expected), PrintToString(lhs),
PrintToString(actual), PrintToString(rhs),
false); false);
} }
// The helper function for {ASSERT|EXPECT}_STRCASEEQ. // The helper function for {ASSERT|EXPECT}_STRCASEEQ.
AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression, AssertionResult CmpHelperSTRCASEEQ(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
const char* expected, const char* lhs,
const char* actual) { const char* rhs) {
if (String::CaseInsensitiveCStringEquals(expected, actual)) { if (String::CaseInsensitiveCStringEquals(lhs, rhs)) {
return AssertionSuccess(); return AssertionSuccess();
} }
return EqFailure(expected_expression, return EqFailure(lhs_expression,
actual_expression, rhs_expression,
PrintToString(expected), PrintToString(lhs),
PrintToString(actual), PrintToString(rhs),
true); true);
} }
@ -1866,18 +1866,18 @@ bool String::WideCStringEquals(const wchar_t * lhs, const wchar_t * rhs) {
} }
// Helper function for *_STREQ on wide strings. // Helper function for *_STREQ on wide strings.
AssertionResult CmpHelperSTREQ(const char* expected_expression, AssertionResult CmpHelperSTREQ(const char* lhs_expression,
const char* actual_expression, const char* rhs_expression,
const wchar_t* expected, const wchar_t* lhs,
const wchar_t* actual) { const wchar_t* rhs) {
if (String::WideCStringEquals(expected, actual)) { if (String::WideCStringEquals(lhs, rhs)) {
return AssertionSuccess(); return AssertionSuccess();
} }
return EqFailure(expected_expression, return EqFailure(lhs_expression,
actual_expression, rhs_expression,
PrintToString(expected), PrintToString(lhs),
PrintToString(actual), PrintToString(rhs),
false); false);
} }

@ -5,8 +5,8 @@ Value of: false
Actual: false Actual: false
Expected: true Expected: true
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: 3 Expected: 2
Expected: 2 To be equal to: 3
[==========] Running 66 tests from 29 test cases. [==========] Running 66 tests from 29 test cases.
[----------] Global test environment set-up. [----------] Global test environment set-up.
FooEnvironment::SetUp() called. FooEnvironment::SetUp() called.
@ -34,21 +34,21 @@ BarEnvironment::SetUp() called.
[----------] 2 tests from NonfatalFailureTest [----------] 2 tests from NonfatalFailureTest
[ RUN ] NonfatalFailureTest.EscapesStringOperands [ RUN ] NonfatalFailureTest.EscapesStringOperands
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: actual Expected: kGoldenString
Actual: "actual \"string\"" Which is: "\"Line"
Expected: kGoldenString To be equal to: actual
Which is: "\"Line" Which is: "actual \"string\""
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: actual Expected: golden
Actual: "actual \"string\"" Which is: "\"Line"
Expected: golden To be equal to: actual
Which is: "\"Line" Which is: "actual \"string\""
[ FAILED ] NonfatalFailureTest.EscapesStringOperands [ FAILED ] NonfatalFailureTest.EscapesStringOperands
[ RUN ] NonfatalFailureTest.DiffForLongStrings [ RUN ] NonfatalFailureTest.DiffForLongStrings
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: "Line 2" Expected: golden_str
Expected: golden_str Which is: "\"Line\0 1\"\nLine 2"
Which is: "\"Line\0 1\"\nLine 2" To be equal to: "Line 2"
With diff: With diff:
@@ -1,2 @@ @@ -1,2 @@
-\"Line\0 1\" -\"Line\0 1\"
@ -59,16 +59,16 @@ With diff:
[ RUN ] FatalFailureTest.FatalFailureInSubroutine [ RUN ] FatalFailureTest.FatalFailureInSubroutine
(expecting a failure that x should be 1) (expecting a failure that x should be 1)
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: x Expected: 1
Actual: 2 To be equal to: x
Expected: 1 Which is: 2
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine [ FAILED ] FatalFailureTest.FatalFailureInSubroutine
[ RUN ] FatalFailureTest.FatalFailureInNestedSubroutine [ RUN ] FatalFailureTest.FatalFailureInNestedSubroutine
(expecting a failure that x should be 1) (expecting a failure that x should be 1)
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: x Expected: 1
Actual: 2 To be equal to: x
Expected: 1 Which is: 2
[ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine [ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine
[ RUN ] FatalFailureTest.NonfatalFailureInSubroutine [ RUN ] FatalFailureTest.NonfatalFailureInSubroutine
(expecting a failure on false) (expecting a failure on false)
@ -107,39 +107,39 @@ This failure is expected, and shouldn't have a trace.
[ RUN ] SCOPED_TRACETest.WorksInLoop [ RUN ] SCOPED_TRACETest.WorksInLoop
(expected to fail) (expected to fail)
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: n Expected: 2
Actual: 1 To be equal to: n
Expected: 2 Which is: 1
Google Test trace: Google Test trace:
gtest_output_test_.cc:#: i = 1 gtest_output_test_.cc:#: i = 1
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: n Expected: 1
Actual: 2 To be equal to: n
Expected: 1 Which is: 2
Google Test trace: Google Test trace:
gtest_output_test_.cc:#: i = 2 gtest_output_test_.cc:#: i = 2
[ FAILED ] SCOPED_TRACETest.WorksInLoop [ FAILED ] SCOPED_TRACETest.WorksInLoop
[ RUN ] SCOPED_TRACETest.WorksInSubroutine [ RUN ] SCOPED_TRACETest.WorksInSubroutine
(expected to fail) (expected to fail)
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: n Expected: 2
Actual: 1 To be equal to: n
Expected: 2 Which is: 1
Google Test trace: Google Test trace:
gtest_output_test_.cc:#: n = 1 gtest_output_test_.cc:#: n = 1
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: n Expected: 1
Actual: 2 To be equal to: n
Expected: 1 Which is: 2
Google Test trace: Google Test trace:
gtest_output_test_.cc:#: n = 2 gtest_output_test_.cc:#: n = 2
[ FAILED ] SCOPED_TRACETest.WorksInSubroutine [ FAILED ] SCOPED_TRACETest.WorksInSubroutine
[ RUN ] SCOPED_TRACETest.CanBeNested [ RUN ] SCOPED_TRACETest.CanBeNested
(expected to fail) (expected to fail)
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: n Expected: 1
Actual: 2 To be equal to: n
Expected: 1 Which is: 2
Google Test trace: Google Test trace:
gtest_output_test_.cc:#: n = 2 gtest_output_test_.cc:#: n = 2
gtest_output_test_.cc:#: gtest_output_test_.cc:#:
@ -437,9 +437,9 @@ Expected: 1 fatal failure
[ OK ] TypedTest/0.Success [ OK ] TypedTest/0.Success
[ RUN ] TypedTest/0.Failure [ RUN ] TypedTest/0.Failure
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: TypeParam() Expected: 1
Actual: 0 To be equal to: TypeParam()
Expected: 1 Which is: 0
Expected failure Expected failure
[ FAILED ] TypedTest/0.Failure, where TypeParam = int [ FAILED ] TypedTest/0.Failure, where TypeParam = int
[----------] 2 tests from Unsigned/TypedTestP/0, where TypeParam = unsigned char [----------] 2 tests from Unsigned/TypedTestP/0, where TypeParam = unsigned char
@ -447,10 +447,10 @@ Expected failure
[ OK ] Unsigned/TypedTestP/0.Success [ OK ] Unsigned/TypedTestP/0.Success
[ RUN ] Unsigned/TypedTestP/0.Failure [ RUN ] Unsigned/TypedTestP/0.Failure
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: TypeParam() Expected: 1U
Actual: '\0' Which is: 1
Expected: 1U To be equal to: TypeParam()
Which is: 1 Which is: '\0'
Expected failure Expected failure
[ FAILED ] Unsigned/TypedTestP/0.Failure, where TypeParam = unsigned char [ FAILED ] Unsigned/TypedTestP/0.Failure, where TypeParam = unsigned char
[----------] 2 tests from Unsigned/TypedTestP/1, where TypeParam = unsigned int [----------] 2 tests from Unsigned/TypedTestP/1, where TypeParam = unsigned int
@ -458,10 +458,10 @@ Expected failure
[ OK ] Unsigned/TypedTestP/1.Success [ OK ] Unsigned/TypedTestP/1.Success
[ RUN ] Unsigned/TypedTestP/1.Failure [ RUN ] Unsigned/TypedTestP/1.Failure
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: TypeParam() Expected: 1U
Actual: 0 Which is: 1
Expected: 1U To be equal to: TypeParam()
Which is: 1 Which is: 0
Expected failure Expected failure
[ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int [ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int
[----------] 4 tests from ExpectFailureTest [----------] 4 tests from ExpectFailureTest
@ -597,18 +597,18 @@ Expected non-fatal failure.
[----------] 1 test from PrintingFailingParams/FailingParamTest [----------] 1 test from PrintingFailingParams/FailingParamTest
[ RUN ] PrintingFailingParams/FailingParamTest.Fails/0 [ RUN ] PrintingFailingParams/FailingParamTest.Fails/0
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: GetParam() Expected: 1
Actual: 2 To be equal to: GetParam()
Expected: 1 Which is: 2
[ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2 [ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
[----------] 2 tests from PrintingStrings/ParamTest [----------] 2 tests from PrintingStrings/ParamTest
[ RUN ] PrintingStrings/ParamTest.Success/a [ RUN ] PrintingStrings/ParamTest.Success/a
[ OK ] PrintingStrings/ParamTest.Success/a [ OK ] PrintingStrings/ParamTest.Success/a
[ RUN ] PrintingStrings/ParamTest.Failure/a [ RUN ] PrintingStrings/ParamTest.Failure/a
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: GetParam() Expected: "b"
Actual: "a" To be equal to: GetParam()
Expected: "b" Which is: "a"
Expected failure Expected failure
[ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a" [ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
[----------] Global test environment tear-down [----------] Global test environment tear-down
@ -678,16 +678,16 @@ Expected fatal failure.
[ RUN ] FatalFailureTest.FatalFailureInSubroutine [ RUN ] FatalFailureTest.FatalFailureInSubroutine
(expecting a failure that x should be 1) (expecting a failure that x should be 1)
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: x Expected: 1
Actual: 2 To be equal to: x
Expected: 1 Which is: 2
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine (? ms) [ FAILED ] FatalFailureTest.FatalFailureInSubroutine (? ms)
[ RUN ] FatalFailureTest.FatalFailureInNestedSubroutine [ RUN ] FatalFailureTest.FatalFailureInNestedSubroutine
(expecting a failure that x should be 1) (expecting a failure that x should be 1)
gtest_output_test_.cc:#: Failure gtest_output_test_.cc:#: Failure
Value of: x Expected: 1
Actual: 2 To be equal to: x
Expected: 1 Which is: 2
[ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine (? ms) [ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine (? ms)
[ RUN ] FatalFailureTest.NonfatalFailureInSubroutine [ RUN ] FatalFailureTest.NonfatalFailureInSubroutine
(expecting a failure on false) (expecting a failure on false)

@ -2466,7 +2466,7 @@ TEST(StringAssertionTest, ASSERT_STRCASEEQ) {
ASSERT_STRCASEEQ("", ""); ASSERT_STRCASEEQ("", "");
EXPECT_FATAL_FAILURE(ASSERT_STRCASEEQ("Hi", "hi2"), EXPECT_FATAL_FAILURE(ASSERT_STRCASEEQ("Hi", "hi2"),
"(ignoring case)"); "Ignoring case");
} }
// Tests ASSERT_STRCASENE. // Tests ASSERT_STRCASENE.
@ -3260,7 +3260,7 @@ TEST_F(SingleEvaluationTest, ASSERT_STR) {
// failed EXPECT_STRCASEEQ // failed EXPECT_STRCASEEQ
EXPECT_NONFATAL_FAILURE(EXPECT_STRCASEEQ(p1_++, p2_++), EXPECT_NONFATAL_FAILURE(EXPECT_STRCASEEQ(p1_++, p2_++),
"ignoring case"); "Ignoring case");
EXPECT_EQ(s1_ + 2, p1_); EXPECT_EQ(s1_ + 2, p1_);
EXPECT_EQ(s2_ + 2, p2_); EXPECT_EQ(s2_ + 2, p2_);
} }
@ -3528,35 +3528,35 @@ TEST(AssertionTest, EqFailure) {
EqFailure("foo", "bar", foo_val, bar_val, false) EqFailure("foo", "bar", foo_val, bar_val, false)
.failure_message()); .failure_message());
EXPECT_STREQ( EXPECT_STREQ(
"Value of: bar\n" " Expected: foo\n"
" Actual: 6\n" " Which is: 5\n"
"Expected: foo\n" "To be equal to: bar\n"
"Which is: 5", " Which is: 6",
msg1.c_str()); msg1.c_str());
const std::string msg2( const std::string msg2(
EqFailure("foo", "6", foo_val, bar_val, false) EqFailure("foo", "6", foo_val, bar_val, false)
.failure_message()); .failure_message());
EXPECT_STREQ( EXPECT_STREQ(
"Value of: 6\n" " Expected: foo\n"
"Expected: foo\n" " Which is: 5\n"
"Which is: 5", "To be equal to: 6",
msg2.c_str()); msg2.c_str());
const std::string msg3( const std::string msg3(
EqFailure("5", "bar", foo_val, bar_val, false) EqFailure("5", "bar", foo_val, bar_val, false)
.failure_message()); .failure_message());
EXPECT_STREQ( EXPECT_STREQ(
"Value of: bar\n" " Expected: 5\n"
" Actual: 6\n" "To be equal to: bar\n"
"Expected: 5", " Which is: 6",
msg3.c_str()); msg3.c_str());
const std::string msg4( const std::string msg4(
EqFailure("5", "6", foo_val, bar_val, false).failure_message()); EqFailure("5", "6", foo_val, bar_val, false).failure_message());
EXPECT_STREQ( EXPECT_STREQ(
"Value of: 6\n" " Expected: 5\n"
"Expected: 5", "To be equal to: 6",
msg4.c_str()); msg4.c_str());
const std::string msg5( const std::string msg5(
@ -3564,10 +3564,11 @@ TEST(AssertionTest, EqFailure) {
std::string("\"x\""), std::string("\"y\""), std::string("\"x\""), std::string("\"y\""),
true).failure_message()); true).failure_message());
EXPECT_STREQ( EXPECT_STREQ(
"Value of: bar\n" " Expected: foo\n"
" Actual: \"y\"\n" " Which is: \"x\"\n"
"Expected: foo (ignoring case)\n" "To be equal to: bar\n"
"Which is: \"x\"", " Which is: \"y\"\n"
"Ignoring case",
msg5.c_str()); msg5.c_str());
} }
@ -3579,11 +3580,11 @@ TEST(AssertionTest, EqFailureWithDiff) {
const std::string msg1( const std::string msg1(
EqFailure("left", "right", left, right, false).failure_message()); EqFailure("left", "right", left, right, false).failure_message());
EXPECT_STREQ( EXPECT_STREQ(
"Value of: right\n" " Expected: left\n"
" Actual: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n" " Which is: "
"Expected: left\n"
"Which is: "
"1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n" "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n"
"To be equal to: right\n"
" Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n"
"With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n" "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n"
"@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n", "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
msg1.c_str()); msg1.c_str());
@ -3678,9 +3679,9 @@ TEST(ExpectTest, ASSERT_EQ_Double) {
TEST(AssertionTest, ASSERT_EQ) { TEST(AssertionTest, ASSERT_EQ) {
ASSERT_EQ(5, 2 + 3); ASSERT_EQ(5, 2 + 3);
EXPECT_FATAL_FAILURE(ASSERT_EQ(5, 2*3), EXPECT_FATAL_FAILURE(ASSERT_EQ(5, 2*3),
"Value of: 2*3\n" " Expected: 5\n"
" Actual: 6\n" "To be equal to: 2*3\n"
"Expected: 5"); " Which is: 6");
} }
// Tests ASSERT_EQ(NULL, pointer). // Tests ASSERT_EQ(NULL, pointer).
@ -3697,7 +3698,7 @@ TEST(AssertionTest, ASSERT_EQ_NULL) {
// A failure. // A failure.
static int n = 0; static int n = 0;
EXPECT_FATAL_FAILURE(ASSERT_EQ(NULL, &n), EXPECT_FATAL_FAILURE(ASSERT_EQ(NULL, &n),
"Value of: &n\n"); "To be equal to: &n\n");
} }
#endif // GTEST_CAN_COMPARE_NULL #endif // GTEST_CAN_COMPARE_NULL
@ -3812,7 +3813,7 @@ void TestEq1(int x) {
// Tests calling a test subroutine that's not part of a fixture. // Tests calling a test subroutine that's not part of a fixture.
TEST(AssertionTest, NonFixtureSubroutine) { TEST(AssertionTest, NonFixtureSubroutine) {
EXPECT_FATAL_FAILURE(TestEq1(2), EXPECT_FATAL_FAILURE(TestEq1(2),
"Value of: x"); "To be equal to: x");
} }
// An uncopyable class. // An uncopyable class.
@ -3861,7 +3862,7 @@ TEST(AssertionTest, AssertWorksWithUncopyableObject) {
EXPECT_FATAL_FAILURE(TestAssertNonPositive(), EXPECT_FATAL_FAILURE(TestAssertNonPositive(),
"IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1"); "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
EXPECT_FATAL_FAILURE(TestAssertEqualsUncopyable(), EXPECT_FATAL_FAILURE(TestAssertEqualsUncopyable(),
"Value of: y\n Actual: -1\nExpected: x\nWhich is: 5"); "Expected: x\n Which is: 5\nTo be equal to: y\n Which is: -1");
} }
// Tests that uncopyable objects can be used in expects. // Tests that uncopyable objects can be used in expects.
@ -3873,7 +3874,7 @@ TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
"IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1"); "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
EXPECT_EQ(x, x); EXPECT_EQ(x, x);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(x, y), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(x, y),
"Value of: y\n Actual: -1\nExpected: x\nWhich is: 5"); "Expected: x\n Which is: 5\nTo be equal to: y\n Which is: -1");
} }
enum NamedEnum { enum NamedEnum {
@ -3885,7 +3886,7 @@ TEST(AssertionTest, NamedEnum) {
EXPECT_EQ(kE1, kE1); EXPECT_EQ(kE1, kE1);
EXPECT_LT(kE1, kE2); EXPECT_LT(kE1, kE2);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(kE1, kE2), "Which is: 0"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(kE1, kE2), "Which is: 0");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(kE1, kE2), "Actual: 1"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(kE1, kE2), "Which is: 1");
} }
// The version of gcc used in XCode 2.2 has a bug and doesn't allow // The version of gcc used in XCode 2.2 has a bug and doesn't allow
@ -3949,9 +3950,9 @@ TEST(AssertionTest, AnonymousEnum) {
// ICE's in C++Builder. // ICE's in C++Builder.
EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseB), EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseB),
"Value of: kCaseB"); "To be equal to: kCaseB");
EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC),
"Actual: 42"); "Which is: 42");
# endif # endif
EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC),
@ -4389,9 +4390,9 @@ TEST(ExpectTest, ExpectFalseWithAssertionResult) {
TEST(ExpectTest, EXPECT_EQ) { TEST(ExpectTest, EXPECT_EQ) {
EXPECT_EQ(5, 2 + 3); EXPECT_EQ(5, 2 + 3);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2*3), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2*3),
"Value of: 2*3\n" " Expected: 5\n"
" Actual: 6\n" "To be equal to: 2*3\n"
"Expected: 5"); " Which is: 6");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2 - 3), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2 - 3),
"2 - 3"); "2 - 3");
} }
@ -4422,7 +4423,7 @@ TEST(ExpectTest, EXPECT_EQ_NULL) {
// A failure. // A failure.
int n = 0; int n = 0;
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(NULL, &n), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(NULL, &n),
"Value of: &n\n"); "To be equal to: &n\n");
} }
#endif // GTEST_CAN_COMPARE_NULL #endif // GTEST_CAN_COMPARE_NULL
@ -4538,7 +4539,7 @@ TEST(ExpectTest, EXPECT_ANY_THROW) {
TEST(ExpectTest, ExpectPrecedence) { TEST(ExpectTest, ExpectPrecedence) {
EXPECT_EQ(1 < 2, true); EXPECT_EQ(1 < 2, true);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(true, true && false), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(true, true && false),
"Value of: true && false"); "To be equal to: true && false");
} }
@ -4685,7 +4686,7 @@ TEST(EqAssertionTest, Bool) {
EXPECT_FATAL_FAILURE({ EXPECT_FATAL_FAILURE({
bool false_value = false; bool false_value = false;
ASSERT_EQ(false_value, true); ASSERT_EQ(false_value, true);
}, "Value of: true"); }, "To be equal to: true");
} }
// Tests using int values in {EXPECT|ASSERT}_EQ. // Tests using int values in {EXPECT|ASSERT}_EQ.
@ -4719,10 +4720,10 @@ TEST(EqAssertionTest, WideChar) {
EXPECT_EQ(L'b', L'b'); EXPECT_EQ(L'b', L'b');
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(L'\0', L'x'), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(L'\0', L'x'),
"Value of: L'x'\n" " Expected: L'\0'\n"
" Actual: L'x' (120, 0x78)\n" " Which is: L'\0' (0, 0x0)\n"
"Expected: L'\0'\n" "To be equal to: L'x'\n"
"Which is: L'\0' (0, 0x0)"); " Which is: L'x' (120, 0x78)");
static wchar_t wchar; static wchar_t wchar;
wchar = L'b'; wchar = L'b';
@ -4730,7 +4731,7 @@ TEST(EqAssertionTest, WideChar) {
"wchar"); "wchar");
wchar = 0x8119; wchar = 0x8119;
EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<wchar_t>(0x8120), wchar), EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<wchar_t>(0x8120), wchar),
"Value of: wchar"); "To be equal to: wchar");
} }
// Tests using ::std::string values in {EXPECT|ASSERT}_EQ. // Tests using ::std::string values in {EXPECT|ASSERT}_EQ.
@ -4759,8 +4760,8 @@ TEST(EqAssertionTest, StdString) {
static ::std::string str3(str1); static ::std::string str3(str1);
str3.at(2) = '\0'; str3.at(2) = '\0';
EXPECT_FATAL_FAILURE(ASSERT_EQ(str1, str3), EXPECT_FATAL_FAILURE(ASSERT_EQ(str1, str3),
"Value of: str3\n" "To be equal to: str3\n"
" Actual: \"A \\0 in the middle\""); " Which is: \"A \\0 in the middle\"");
} }
#if GTEST_HAS_STD_WSTRING #if GTEST_HAS_STD_WSTRING
@ -4880,7 +4881,7 @@ TEST(EqAssertionTest, CharPointer) {
ASSERT_EQ(p1, p1); ASSERT_EQ(p1, p1);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2),
"Value of: p2"); "To be equal to: p2");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2),
"p2"); "p2");
EXPECT_FATAL_FAILURE(ASSERT_EQ(reinterpret_cast<char*>(0x1234), EXPECT_FATAL_FAILURE(ASSERT_EQ(reinterpret_cast<char*>(0x1234),
@ -4902,7 +4903,7 @@ TEST(EqAssertionTest, WideCharPointer) {
EXPECT_EQ(p0, p0); EXPECT_EQ(p0, p0);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2),
"Value of: p2"); "To be equal to: p2");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2),
"p2"); "p2");
void* pv3 = (void*)0x1234; // NOLINT void* pv3 = (void*)0x1234; // NOLINT

@ -64,20 +64,20 @@ EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
</testsuite> </testsuite>
<testsuite name="FailedTest" tests="1" failures="1" disabled="0" errors="0" time="*"> <testsuite name="FailedTest" tests="1" failures="1" disabled="0" errors="0" time="*">
<testcase name="Fails" status="run" time="*" classname="FailedTest"> <testcase name="Fails" status="run" time="*" classname="FailedTest">
<failure message="gtest_xml_output_unittest_.cc:*&#x0A;Value of: 2&#x0A;Expected: 1" type=""><![CDATA[gtest_xml_output_unittest_.cc:* <failure message="gtest_xml_output_unittest_.cc:*&#x0A; Expected: 1&#x0A;To be equal to: 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
Value of: 2 Expected: 1
Expected: 1%(stack)s]]></failure> To be equal to: 2%(stack)s]]></failure>
</testcase> </testcase>
</testsuite> </testsuite>
<testsuite name="MixedResultTest" tests="3" failures="1" disabled="1" errors="0" time="*"> <testsuite name="MixedResultTest" tests="3" failures="1" disabled="1" errors="0" time="*">
<testcase name="Succeeds" status="run" time="*" classname="MixedResultTest"/> <testcase name="Succeeds" status="run" time="*" classname="MixedResultTest"/>
<testcase name="Fails" status="run" time="*" classname="MixedResultTest"> <testcase name="Fails" status="run" time="*" classname="MixedResultTest">
<failure message="gtest_xml_output_unittest_.cc:*&#x0A;Value of: 2&#x0A;Expected: 1" type=""><![CDATA[gtest_xml_output_unittest_.cc:* <failure message="gtest_xml_output_unittest_.cc:*&#x0A; Expected: 1&#x0A;To be equal to: 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
Value of: 2 Expected: 1
Expected: 1%(stack)s]]></failure> To be equal to: 2%(stack)s]]></failure>
<failure message="gtest_xml_output_unittest_.cc:*&#x0A;Value of: 3&#x0A;Expected: 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:* <failure message="gtest_xml_output_unittest_.cc:*&#x0A; Expected: 2&#x0A;To be equal to: 3" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
Value of: 3 Expected: 2
Expected: 2%(stack)s]]></failure> To be equal to: 3%(stack)s]]></failure>
</testcase> </testcase>
<testcase name="DISABLED_test" status="notrun" time="*" classname="MixedResultTest"/> <testcase name="DISABLED_test" status="notrun" time="*" classname="MixedResultTest"/>
</testsuite> </testsuite>

Loading…
Cancel
Save