diff options
author | Abseil Team <absl-team@google.com> | 2022-05-24 17:57:10 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-05-24 17:57:53 (GMT) |
commit | 704105148860d6b90b009681b221a76575e5c88c (patch) | |
tree | 5703bed695d2850081ef302fac5e5b216beb7839 /docs | |
parent | 8d51dc50eb7e7698427fed81b85edad0e032112e (diff) | |
download | googletest-704105148860d6b90b009681b221a76575e5c88c.zip googletest-704105148860d6b90b009681b221a76575e5c88c.tar.gz googletest-704105148860d6b90b009681b221a76575e5c88c.tar.bz2 |
Clarify the pitfalls of EXPECT_THAT and highlight it's best practices
PiperOrigin-RevId: 450721917
Change-Id: I34d63a65b7158975abd46a9a14cded75439e7e7f
Diffstat (limited to 'docs')
-rw-r--r-- | docs/reference/matchers.md | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/docs/reference/matchers.md b/docs/reference/matchers.md index 0f57db4..9fb1592 100644 --- a/docs/reference/matchers.md +++ b/docs/reference/matchers.md @@ -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)`. |