From 0d4b15c26659cbd2ae2efa0a4077da44137dc0fc Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 24 Jul 2024 16:07:20 +0200 Subject: [PATCH] added asserts with number --- test/common_helper/test.hpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/common_helper/test.hpp b/test/common_helper/test.hpp index 6b89ad4..f3d8a30 100644 --- a/test/common_helper/test.hpp +++ b/test/common_helper/test.hpp @@ -29,6 +29,17 @@ #define TEST_PASS_MSG_TYPE(msg, type_hint) ret_val_s { "", ReturnCode::PASSED, msg, to_type_hint_str::value } #define TEST_SKIP_TYPE(type_hint) ret_val_s { "", ReturnCode::SKIPPED, nullptr, to_type_hint_str::value } +#define TEST_FAIL_TYPE_NUM(msg, type_hint, num) ret_val_s { "", ReturnCode::FAILED, msg, to_type_hint_str::value, num } +#define TEST_PASS_TYPE_NUM(type_hint, num) ret_val_s { "", ReturnCode::PASSED, nullptr, to_type_hint_str::value, num } +#define TEST_PASS_MSG_TYPE_NUM(msg, type_hint, num) ret_val_s { "", ReturnCode::PASSED, msg, to_type_hint_str::value, num } +#define TEST_SKIP_TYPE_NUM(type_hint, num) ret_val_s { "", ReturnCode::SKIPPED, nullptr, to_type_hint_str::value, num } + +#define ASSERT_TYPE_NUM(condition, type, num) ASSERT_TYPE_NUM_MSG(condition, #condition "" _LOCATION, type, num) +#define ASSERT_TYPE_NUM_MSG(condition, msg, type, num) { if (!(condition)) return TEST_FAIL_TYPE_NUM(msg, type, num); } static_assert(true, "") +#define ASSERT_TYPE_NUM_ALL_EQ(first, last, eq, type, num) ASSERT_TYPE_NUM_MSG(std::all_of(first, last, all_eq_arr_elem_test_func(eq)), "Not all elements in (" #first ", " #last ") equal " #eq "" _LOCATION, type, num) +#define ASSERT_TYPE_NUM_C_ARR_EQ(first, last, eq, type, num) ASSERT_TYPE_NUM_MSG(std::equal(first, last, eq, all_eq_arr_arr_test_func()), "Elements in (" #first ", " #last ") and " #eq " differ" _LOCATION, type, num) +#define ASSERT_TYPE_NUM_ITER_EQ(first, last, eq, type, num) ASSERT_TYPE_NUM_MSG(std::equal(first, last, (eq).begin(), all_eq_arr_arr_test_func::value_type>()), "Elements in (" #first ", " #last ") and " #eq " differ" _LOCATION, type, num) + #define ASSERT_TYPE(condition, type) ASSERT_TYPE_MSG(condition, #condition "" _LOCATION, type) #define ASSERT_TYPE_MSG(condition, msg, type) { if (!(condition)) return TEST_FAIL_TYPE(msg, type); } static_assert(true, "") #define ASSERT_TYPE_ALL_EQ(first, last, eq, type) ASSERT_TYPE_MSG(std::all_of(first, last, all_eq_arr_elem_test_func(eq)), "Not all elements in (" #first ", " #last ") equal " #eq "" _LOCATION, type) @@ -41,7 +52,8 @@ #define ASSERT_C_ARR_EQ(first, last, eq) ASSERT_TYPE_C_ARR_EQ(first, last, eq, std::nullptr_t) #define ASSERT_ITER_EQ(first, last, eq) ASSERT_TYPE_ITER_EQ(first, last, eq, std::nullptr_t) -#define ASSERT_TYPE_THROWS(operation, exception_type, type) if not consteval { try { operation; ASSERT_TYPE_MSG(false, #operation " did not throw " #exception_type _LOCATION, type); } catch (exception_type &e) {} } static_assert(true, "") +#define ASSERT_TYPE_NUM_THROWS(operation, exception_type, type, num) if not consteval { try { operation; ASSERT_TYPE_NUM_MSG(false, #operation " did not throw " #exception_type _LOCATION, type, num); } catch (exception_type &e) {} } static_assert(true, "") +#define ASSERT_TYPE_THROWS(operation, exception_type, type) ASSERT_TYPE_NUM_THROWS(operation, exception_type, type, -1ULL) #define ASSERT_THROWS(operation, exception_type) ASSERT_TYPE_THROWS(operation, exception_type, std::nullptr_t) template @@ -89,6 +101,7 @@ struct ret_val_s { ReturnCode val = ReturnCode::FAILED; const char *msg = ""; const char *type_hint = nullptr; + std::size_t param_nr = -1; }; template @@ -183,6 +196,9 @@ class test_suite { if (ret.type_hint != nullptr) { std::cout << "\n\t" << "with type '" << ret.type_hint << "'"; } + if (ret.param_nr != -1) { + std::cout << "\n\t" << "with parameter param_nr: " << ret.param_nr; + } std::cout << std::endl; ret_vals[i][0] = ret.val; @@ -197,6 +213,9 @@ class test_suite { if (ret.type_hint != nullptr) { std::cout << "\n\t" << "with type '" << ret.type_hint << "'"; } + if (ret.param_nr != -1) { + std::cout << "\n\t" << "with parameter param_nr: " << ret.param_nr; + } std::cout << std::endl; ret_vals[i][1] = ret.val;