Commit 229610b6 authored by Robert Quitt's avatar Robert Quitt Committed by Facebook GitHub Bot

Fix CO_TEST_F to use updated googletest API

Summary:
The new version of googletest has a different internal API for registering test suites. This diff updates `CO_TEST_` to match the new version of googletest. I created this diff by copying the new version of `GTEST_TEST_` and adding the coroutine `co_TestBody`, just like in the old version of `CO_TEST_`.

~~There is a problem that I'd like reviewer's feedback on: how do we cleanly make the switch over to the new version of `CO_TEST_`? This change is tied to a specific version of googletest.~~

~~I have 2 ideas so far:~~

~~(Plan 1) Land this diff stacked on top of D25585021, so that we don't have to manage two versions at once.~~ Not possible

(Plan 2) Have two versions of `CO_TEST_` at the same time, but select which one to use based on a preprocessor macro defined in gtest.

Reviewed By: yfeldblum

Differential Revision: D26365504

fbshipit-source-id: 196c2277c7942163951f5781b334d0bff5c34de8
parent af8e836f
......@@ -32,35 +32,87 @@
* Note that you cannot use ASSERT macros in coro tests. See below for
* CO_ASSERT_*.
*/
// clang-format off
#define CO_TEST_(test_case_name, test_name, parent_class, parent_id)\
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
public:\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
private:\
void TestBody() override;\
folly::coro::Task<void> co_TestBody();\
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
};\
\
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
::test_info_ = /* NOLINT */ \
::testing::internal::MakeAndRegisterTestInfo(\
GTEST_STRINGIFY_TOKEN_(test_case_name), \
GTEST_STRINGIFY_TOKEN_(test_name), NULL, NULL, \
::testing::internal::CodeLocation(__FILE__, __LINE__), /* NOLINT */ \
(parent_id), \
parent_class::SetUpTestCase, \
parent_class::TearDownTestCase, \
new ::testing::internal::TestFactoryImpl< /* NOLINT */ \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() {\
folly::coro::blockingWait(co_TestBody());\
}\
folly::coro::Task<void> GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::co_TestBody()
// clang-format on
#define CO_TEST_MASTER_(test_case_name, test_name, parent_class, parent_id) \
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
: public parent_class { \
public: \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
\
private: \
void TestBody() override; \
folly::coro::Task<void> co_TestBody(); \
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
GTEST_DISALLOW_COPY_AND_ASSIGN_( \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
}; \
\
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_( \
test_case_name, test_name)::test_info_ = \
::testing::internal::MakeAndRegisterTestInfo( \
GTEST_STRINGIFY_TOKEN_(test_case_name), \
GTEST_STRINGIFY_TOKEN_(test_name), \
NULL, \
NULL, \
::testing::internal::CodeLocation(__FILE__, __LINE__), \
(parent_id), \
parent_class::SetUpTestCase, \
parent_class::TearDownTestCase, \
new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
test_case_name, test_name)>); \
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() { \
folly::coro::blockingWait(co_TestBody()); \
} \
folly::coro::Task<void> GTEST_TEST_CLASS_NAME_( \
test_case_name, test_name)::co_TestBody()
#define CO_TEST_20201023_(test_suite_name, test_name, parent_class, parent_id) \
static_assert( \
sizeof(GTEST_STRINGIFY_(test_suite_name)) > 1, \
"test_suite_name must not be empty"); \
static_assert( \
sizeof(GTEST_STRINGIFY_(test_name)) > 1, "test_name must not be empty"); \
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
: public parent_class { \
public: \
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() = default; \
~GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() override = default; \
GTEST_DISALLOW_COPY_AND_ASSIGN_( \
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)); \
GTEST_DISALLOW_MOVE_AND_ASSIGN_( \
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)); \
\
private: \
void TestBody() override; \
folly::coro::Task<void> co_TestBody(); \
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
}; \
\
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_( \
test_suite_name, test_name)::test_info_ = \
::testing::internal::MakeAndRegisterTestInfo( \
#test_suite_name, \
#test_name, \
nullptr, \
nullptr, \
::testing::internal::CodeLocation(__FILE__, __LINE__), \
(parent_id), \
::testing::internal::SuiteApiResolver< \
parent_class>::GetSetUpCaseOrSuite(__FILE__, __LINE__), \
::testing::internal::SuiteApiResolver< \
parent_class>::GetTearDownCaseOrSuite(__FILE__, __LINE__), \
new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
test_suite_name, test_name)>); \
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody() { \
folly::coro::blockingWait(co_TestBody()); \
} \
folly::coro::Task<void> GTEST_TEST_CLASS_NAME_( \
test_suite_name, test_name)::co_TestBody()
#if defined(TYPED_TEST_SUITE)
#define CO_TEST_ CO_TEST_20201023_
#else
#define CO_TEST_ CO_TEST_MASTER_
#endif
/**
* TEST() for coro tests.
......
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