diff --git a/test/common_helper/test.hpp b/test/common_helper/test.hpp index f91c431..fc126c1 100644 --- a/test/common_helper/test.hpp +++ b/test/common_helper/test.hpp @@ -18,6 +18,29 @@ #define TEST_PASS_MSG(msg) ret_val_s { "", ReturnCode::PASSED, msg } #define TEST_SKIP() ret_val_s { "", ReturnCode::SKIPPED, nullptr } +#define ASSERT(condition) ASSERT_MSG(condition, #condition) +#define ASSERT_MSG(condition, msg) { if (!(condition)) return TEST_FAIL(msg); } static_assert(true, "") +#define ASSERT_ALL_EQ(first, last, eq) ASSERT_MSG(std::all_of(first, last, all_eq_arr_elem_test_func(eq)), "Not all elements in (" #first ", " #last ") equal " #eq) +#define ASSERT_C_ARR_EQ(first, last, eq) ASSERT_MSG(std::equal(first, last, eq, all_eq_arr_arr_test_func()), "Elements in (" #first ", " #last ") and " #eq " differ") +#define ASSERT_ITER_EQ(first, last, eq) ASSERT_MSG(std::equal(first, last, eq, all_eq_arr_arr_test_func::value_type>()), "Elements in (" #first ", " #last ") and " #eq " differ") + +template +constexpr auto all_eq_arr_elem_test_func(T&& eq) { + return [=] (auto&& e) constexpr { return e == eq; }; +} +template +constexpr auto all_eq_arr_elem_test_func(const char* eq) { + return [=] (auto&& e) constexpr { return std::string_view(e) == eq; }; +} + +template +constexpr auto all_eq_arr_arr_test_func() { + return [] (auto&& a, auto&& b) constexpr { return a == b; }; +} +template +constexpr auto all_eq_arr_arr_test_func() { + return [] (auto&& a, auto&& b) constexpr { return std::string_view(a) == b; }; +} enum class EvalFlag { RUNTIME, CONSTEVAL, RUNTIME_CONSTEVAL }; enum class ReturnCode { FAILED = -1, PASSED = 0, SKIPPED = 1, NOT_EVALUATED = 2 };