Skip to content

Commit 7041051

Browse files
Abseil Teamcopybara-github
Abseil Team
authored andcommitted
Clarify the pitfalls of EXPECT_THAT and highlight it's best practices
PiperOrigin-RevId: 450721917 Change-Id: I34d63a65b7158975abd46a9a14cded75439e7e7f
1 parent 8d51dc5 commit 7041051

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

docs/reference/matchers.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or
88
| `EXPECT_THAT(actual_value, matcher)` | Asserts that `actual_value` matches `matcher`. |
99
| `ASSERT_THAT(actual_value, matcher)` | The same as `EXPECT_THAT(actual_value, matcher)`, except that it generates a **fatal** failure. |
1010

11-
{: .callout .note}
12-
**Note:** Although equality matching via `EXPECT_THAT(actual_value,
13-
expected_value)` is supported, prefer to make the comparison explicit via
11+
{: .callout .warning}
12+
**WARNING:** Equality matching via `EXPECT_THAT(actual_value, expected_value)`
13+
is supported, however note that implicit conversions can cause surprising
14+
results. For example, `EXPECT_THAT(some_bool, "some string")` will compile and
15+
may pass unintentionally.
16+
17+
**BEST PRACTICE:** Prefer to make the comparison explicit via
1418
`EXPECT_THAT(actual_value, Eq(expected_value))` or `EXPECT_EQ(actual_value,
1519
expected_value)`.
1620

0 commit comments

Comments
 (0)