diff --git a/test/common_helper/test.hpp b/test/common_helper/test.hpp index ac199ec..271b3f0 100644 --- a/test/common_helper/test.hpp +++ b/test/common_helper/test.hpp @@ -13,16 +13,22 @@ #include #include +#define _EXPAND_STR(s) #s +#define _EXPAND_MACRO(s) _EXPAND_STR(s) +#define _LOCATION " (at " _EXPAND_MACRO(__FILE__) ":" _EXPAND_MACRO(__LINE__) ")" + #define TEST_FAIL(msg) ret_val_s { "", ReturnCode::FAILED, msg } #define TEST_PASS() ret_val_s { "", ReturnCode::PASSED, nullptr } #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(condition) ASSERT_MSG(condition, #condition "" _LOCATION) #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).begin(), all_eq_arr_arr_test_func::value_type>()), "Elements in (" #first ", " #last ") and " #eq " differ") +#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 "" _LOCATION) +#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" _LOCATION) +#define ASSERT_ITER_EQ(first, last, eq) ASSERT_MSG(std::equal(first, last, (eq).begin(), all_eq_arr_arr_test_func::value_type>()), "Elements in (" #first ", " #last ") and " #eq " differ" _LOCATION) + +#define ASSERT_THROWS(operation, exception_type) if not consteval { try { operation; ASSERT_MSG(false, #operation " did not throw " #exception_type _LOCATION); } catch (exception_type &e) {} } static_assert(true, "") template constexpr auto all_eq_arr_elem_test_func(T&& eq) {