Commit bb47922f authored by Francesco Zoffoli's avatar Francesco Zoffoli Committed by Facebook GitHub Bot

Support CO_ASSERT_THAT

Summary:
`ASSERT_THAT` is defined in gmock, this adds the equivalent for coroutine code to GmockHelper.

The implementation depends on the inclusion of GtestHelper, but to avoid forcing anyone that includes GmockHelper to also include GtestHelper I didn't add it in the file.

Would it be preferable to include the needed header?

Reviewed By: yfeldblum

Differential Revision: D29067561

fbshipit-source-id: 26aa6021efe55aa03dd7cf064563a732e47e39a1
parent 68a78d99
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <type_traits> #include <type_traits>
#include <folly/experimental/coro/Coroutine.h> #include <folly/experimental/coro/Coroutine.h>
#include <folly/experimental/coro/GtestHelpers.h>
#include <folly/experimental/coro/Result.h> #include <folly/experimental/coro/Result.h>
#include <folly/experimental/coro/Task.h> #include <folly/experimental/coro/Task.h>
#include <folly/portability/GMock.h> #include <folly/portability/GMock.h>
...@@ -230,4 +231,8 @@ auto CoThrow(Ex&& e) { ...@@ -230,4 +231,8 @@ auto CoThrow(Ex&& e) {
} // namespace coro } // namespace coro
} // namespace folly } // namespace folly
#define CO_ASSERT_THAT(value, matcher) \
CO_ASSERT_PRED_FORMAT1( \
::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
#endif // FOLLY_HAS_COROUTINES #endif // FOLLY_HAS_COROUTINES
...@@ -137,6 +137,9 @@ ...@@ -137,6 +137,9 @@
*/ */
#define CO_GTEST_FATAL_FAILURE_(message) \ #define CO_GTEST_FATAL_FAILURE_(message) \
co_return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure) co_return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
#define CO_ASSERT_PRED_FORMAT1(pred_format, v1) \
GTEST_PRED_FORMAT1_(pred_format, v1, CO_GTEST_FATAL_FAILURE_)
#define CO_ASSERT_PRED_FORMAT2(pred_format, v1, v2) \ #define CO_ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
GTEST_PRED_FORMAT2_(pred_format, v1, v2, CO_GTEST_FATAL_FAILURE_) GTEST_PRED_FORMAT2_(pred_format, v1, v2, CO_GTEST_FATAL_FAILURE_)
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <gtest/gtest-death-test.h> #include <gtest/gtest-death-test.h>
#include <folly/experimental/coro/GmockHelpers.h> #include <folly/experimental/coro/GmockHelpers.h>
#include <folly/experimental/coro/GtestHelpers.h>
#include <folly/experimental/coro/BlockingWait.h> #include <folly/experimental/coro/BlockingWait.h>
#include <folly/experimental/coro/Task.h> #include <folly/experimental/coro/Task.h>
...@@ -174,4 +175,8 @@ TEST(CoroLambdaGtest, CoThrowTest) { ...@@ -174,4 +175,8 @@ TEST(CoroLambdaGtest, CoThrowTest) {
EXPECT_THROW(folly::coro::blockingWait(mock.getString()), std::runtime_error); EXPECT_THROW(folly::coro::blockingWait(mock.getString()), std::runtime_error);
} }
CO_TEST(CoAssertThat, CoAssertThat) {
CO_ASSERT_THAT(1, Gt(0));
}
#endif // FOLLY_HAS_COROUTINES #endif // FOLLY_HAS_COROUTINES
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