added asserts to test

This commit is contained in:
cyborg1811m 2024-06-18 21:38:20 +02:00
parent 40d4608477
commit 6dfaeccae2
1 changed files with 23 additions and 0 deletions

View File

@ -18,6 +18,29 @@
#define TEST_PASS_MSG(msg) ret_val_s { "", ReturnCode::PASSED, msg } #define TEST_PASS_MSG(msg) ret_val_s { "", ReturnCode::PASSED, msg }
#define TEST_SKIP() ret_val_s { "", ReturnCode::SKIPPED, nullptr } #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<decltype(eq)>()), "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<std::iterator_traits<decltype(eq)>::value_type>()), "Elements in (" #first ", " #last ") and " #eq " differ")
template<typename T>
constexpr auto all_eq_arr_elem_test_func(T&& eq) {
return [=] (auto&& e) constexpr { return e == eq; };
}
template<const char *>
constexpr auto all_eq_arr_elem_test_func(const char* eq) {
return [=] (auto&& e) constexpr { return std::string_view(e) == eq; };
}
template<typename T>
constexpr auto all_eq_arr_arr_test_func() {
return [] (auto&& a, auto&& b) constexpr { return a == b; };
}
template<const char *>
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 EvalFlag { RUNTIME, CONSTEVAL, RUNTIME_CONSTEVAL };
enum class ReturnCode { FAILED = -1, PASSED = 0, SKIPPED = 1, NOT_EVALUATED = 2 }; enum class ReturnCode { FAILED = -1, PASSED = 0, SKIPPED = 1, NOT_EVALUATED = 2 };