Skip to content

Commit

Permalink
Clarify the pitfalls of EXPECT_THAT and highlight it's best practices
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 450721917
Change-Id: I34d63a65b7158975abd46a9a14cded75439e7e7f
  • Loading branch information
Abseil Team authored and Copybara-Service committed May 24, 2022
1 parent 8d51dc5 commit 7041051
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions docs/reference/matchers.md
Expand Up @@ -8,9 +8,13 @@ A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or
| `EXPECT_THAT(actual_value, matcher)` | Asserts that `actual_value` matches `matcher`. |
| `ASSERT_THAT(actual_value, matcher)` | The same as `EXPECT_THAT(actual_value, matcher)`, except that it generates a **fatal** failure. |

{: .callout .note}
**Note:** Although equality matching via `EXPECT_THAT(actual_value,
expected_value)` is supported, prefer to make the comparison explicit via
{: .callout .warning}
**WARNING:** Equality matching via `EXPECT_THAT(actual_value, expected_value)`
is supported, however note that implicit conversions can cause surprising
results. For example, `EXPECT_THAT(some_bool, "some string")` will compile and
may pass unintentionally.

**BEST PRACTICE:** Prefer to make the comparison explicit via
`EXPECT_THAT(actual_value, Eq(expected_value))` or `EXPECT_EQ(actual_value,
expected_value)`.

Expand Down

0 comments on commit 7041051

Please sign in to comment.