5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TESTING_GTEST_WITH_GTEST_CONSTEXPR_TEST_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TESTING_GTEST_WITH_GTEST_CONSTEXPR_TEST_HPP_
11#include <gtest/gtest.h>
15#include "arene/base/stdlib_choice/integral_constant.hpp"
31template <
class TestTag>
40 static_assert((
test_impl(TestTag{}),
true),
"test body not invocable in a constant expression");
49template <
class TestTag,
bool RunInConstexpr>
62template <
class TestTag>
89#define TESTCASE_TYPE_NAME(testsuite, testcase) testsuite##_##testcase
95#define TESTCASE_TAG_NAME(testsuite, testcase) testsuite##_##testcase##_tag
120#define CONSTEXPR_TEST(testsuite, testcase) \
121 class TESTCASE_TYPE_NAME(testsuite, testcase); \
123 class TESTCASE_TAG_NAME(testsuite, testcase) { \
124 static ::testing::TestInfo const* const test_info_; \
128 ::testing::TestInfo const* const TESTCASE_TAG_NAME(testsuite, testcase)::test_info_ = ::testing::RegisterTest( \
129 ARENE_STRINGIZE(testsuite), \
130 ARENE_STRINGIZE(testcase), \
136 return static_cast<::testing::Test*>( \
137 new ::arene::base::testing::internal::constexpr_test<TESTCASE_TAG_NAME(testsuite, testcase)>{} \
142 constexpr void test_impl(TESTCASE_TAG_NAME(testsuite, testcase))
175#define CONDITIONALLY_CONSTEXPR_TEST(testsuite, testcase, ...) \
176 class TESTCASE_TYPE_NAME(testsuite, testcase); \
178 class TESTCASE_TAG_NAME(testsuite, testcase) { \
179 static ::testing::TestInfo const* const test_info_; \
183 ::testing::TestInfo const* const TESTCASE_TAG_NAME(testsuite, testcase)::test_info_ = ::testing::RegisterTest( \
184 ARENE_STRINGIZE(testsuite), \
185 ARENE_STRINGIZE(testcase), \
191 return static_cast<::testing::Test*>( \
192 new ::arene::base::testing::internal:: \
193 conditionally_constexpr_test<TESTCASE_TAG_NAME(testsuite, testcase), (__VA_ARGS__)>{} \
202 constexpr void test_impl(TESTCASE_TAG_NAME(testsuite, testcase))
228#define CONSTEXPR_TYPED_TEST(testsuite, testcase) \
229 class TESTCASE_TYPE_NAME(testsuite, testcase); \
231 class TESTCASE_TAG_NAME(testsuite, testcase) {}; \
233 TYPED_TEST(testsuite, testcase) { \
234 using ::arene::base::testing::internal::test_impl; \
235 using tag_type = TESTCASE_TAG_NAME(testsuite, testcase); \
236 static_assert((test_impl<TypeParam>(tag_type{}), true), "test body not invocable in a constant expression"); \
237 test_impl<TypeParam>(tag_type{}); \
240 template <class TypeParam> \
241 constexpr void test_impl(TESTCASE_TAG_NAME(testsuite, testcase))
278#define CONDITIONALLY_CONSTEXPR_TYPED_TEST(testsuite, testcase, ...) \
279 class TESTCASE_TYPE_NAME(testsuite, testcase); \
281 class TESTCASE_TAG_NAME(testsuite, testcase) {}; \
283 template <class TypeParam> \
285 maybe_do_test_in_constexpr(TESTCASE_TAG_NAME(testsuite, testcase) tag, std::integral_constant<bool, true>) { \
286 using ::arene::base::testing::internal::test_impl; \
288 static_cast<void>(std::integral_constant<bool, (test_impl<TypeParam>(tag), true)>{}); \
291 template <class TypeParam> \
293 maybe_do_test_in_constexpr(TESTCASE_TAG_NAME(testsuite, testcase), std::integral_constant<bool, false>) {} \
295 TYPED_TEST(testsuite, testcase) { \
296 using ::arene::base::testing::internal::test_impl; \
297 using tag_type = TESTCASE_TAG_NAME(testsuite, testcase); \
300 test_impl<TypeParam>(tag_type{}); \
301 maybe_do_test_in_constexpr<TypeParam>(tag_type{}, std::integral_constant<bool, (__VA_ARGS__)>{}); \
304 template <class TypeParam> \
305 constexpr void test_impl(TESTCASE_TAG_NAME(testsuite, testcase))
333#define CONDITIONAL_CONSTEXPR_TYPED_TEST(testsuite, testcase, ...) \
334 class TESTCASE_TYPE_NAME(testsuite, testcase); \
336 class TESTCASE_TAG_NAME(testsuite, testcase) {}; \
338 template <class TypeParam> \
339 constexpr void maybe_do_test(TESTCASE_TAG_NAME(testsuite, testcase) tag, std::integral_constant<bool, true>) { \
340 using ::arene::base::testing::internal::test_impl; \
343 static_cast<void>(std::integral_constant<bool, (test_impl<TypeParam>(tag), true)>{}); \
344 test_impl<TypeParam>(tag); \
347 template <class TypeParam> \
348 constexpr void maybe_do_test(TESTCASE_TAG_NAME(testsuite, testcase), std::integral_constant<bool, false>) { \
349 GTEST_SKIP() << "Disabled by condition: " << ARENE_STRINGIZE(__VA_ARGS__); \
352 TYPED_TEST(testsuite, testcase) { \
353 using tag_type = TESTCASE_TAG_NAME(testsuite, testcase); \
354 maybe_do_test<TypeParam>(tag_type{}, std::integral_constant<bool, (__VA_ARGS__)>{}); \
357 template <class TypeParam> \
358 constexpr void test_impl(TESTCASE_TAG_NAME(testsuite, testcase))
373#define CONSTEXPR_ASSERT(...) \
374 if (not(__VA_ARGS__)) { \
385#define CONSTEXPR_ASSERT_FALSE(...) CONSTEXPR_ASSERT(!(__VA_ARGS__))
394#define CONSTEXPR_ASSERT_EQ(lhs, rhs) CONSTEXPR_ASSERT(((lhs) == (rhs)))
auto TestBody() -> void override
Definition constexpr_test.hpp:65
GoogleTest test type used to conditionally invoke tests at compile-time.
Definition constexpr_test.hpp:50
auto TestBody() -> void override
Definition constexpr_test.hpp:52
GoogleTest test type used invoke tests at compile-time.
Definition constexpr_test.hpp:32
auto TestBody() -> void override
test implementation function
Definition constexpr_test.hpp:39
A helper class to represent a compile-time constant with the specified type and value....
Definition integral_constant.hpp:23
Definition constexpr_test.hpp:21
void test_impl()=delete
dummy function declaration to allow unqualified lookup
Definition customization.hpp:31
Definition accumulate.hpp:37
Definition accumulate.hpp:36