Commit f364e188 by Alexey Sokolov

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

parent ff5ffd45
...@@ -312,8 +312,8 @@ want to learn more, see ...@@ -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. ...@@ -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`). ...@@ -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. ...@@ -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.
......
...@@ -1301,41 +1301,41 @@ std::vector<std::string> SplitEscapedString(const std::string& str) { ...@@ -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 { ...@@ -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, > ) ...@@ -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) { ...@@ -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 ...@@ -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. ...@@ -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: ...@@ -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. ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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. ...@@ -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. ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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"?> ...@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment