Commit c30526f7 authored by Bennett Magy's avatar Bennett Magy Committed by Facebook GitHub Bot

Add CO_TEST_P

Summary:
Copied TEST_P def from https://github.com/google/googletest/blob/master/googletest/include/gtest/gtest-param-test.h

Implemented `TestBody()` as `blockingWait(co_TestBody())`. User is responsible for delivering impl of `co_TestBody()`.

Reviewed By: yfeldblum

Differential Revision: D29124282

fbshipit-source-id: ca8e9b874903b84ab529e7eefa6a2b7f72793b9b
parent a7b4818a
......@@ -95,6 +95,42 @@
test_fixture, \
::testing::internal::GetTypeId<test_fixture>())
#define CO_TEST_P(test_suite_name, test_name) \
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
: public test_suite_name { \
public: \
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
void TestBody() override; \
folly::coro::Task<void> co_TestBody(); \
\
private: \
static int AddToRegistry() { \
::testing::UnitTest::GetInstance() \
->parameterized_test_registry() \
.GetTestSuitePatternHolder<test_suite_name>( \
GTEST_STRINGIFY_(test_suite_name), \
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
->AddTestPattern( \
GTEST_STRINGIFY_(test_suite_name), \
GTEST_STRINGIFY_(test_name), \
new ::testing::internal::TestMetaFactory<GTEST_TEST_CLASS_NAME_( \
test_suite_name, test_name)>(), \
::testing::internal::CodeLocation(__FILE__, __LINE__)); \
return 0; \
} \
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
GTEST_DISALLOW_COPY_AND_ASSIGN_( \
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)); \
}; \
int GTEST_TEST_CLASS_NAME_( \
test_suite_name, test_name)::gtest_registering_dummy_ = \
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::AddToRegistry(); \
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()
/**
* Coroutine versions of GTests's Assertion predicate macros. Use these in place
* of ASSERT_* in CO_TEST or coroutine functions.
......
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/portability/GTest.h>
#include <folly/experimental/coro/GtestHelpers.h>
using namespace ::testing;
namespace {
folly::coro::Task<int> co_getInt(int x) {
co_return x;
}
struct GtestHelpersMultiplicationTestParam {
int x;
int y;
int expectedProduct;
};
} // namespace
class GtestHelpersMultiplicationTest
: public TestWithParam<GtestHelpersMultiplicationTestParam> {};
CO_TEST_P(GtestHelpersMultiplicationTest, BasicTest) {
const auto& param = GetParam();
int product = (co_await co_getInt(param.x)) * (co_await co_getInt(param.y));
EXPECT_EQ(product, param.expectedProduct);
}
INSTANTIATE_TEST_CASE_P(
GtestHelpersMultiplicationTest,
GtestHelpersMultiplicationTest,
ValuesIn(std::vector<GtestHelpersMultiplicationTestParam>{
{1, 1, 1},
{1, 2, 2},
{2, 2, 4},
{-1, -6, 6},
}));
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