updated ASSERT to accept context
This commit is contained in:
parent
e767f5b012
commit
0fdff1e1c3
|
|
@ -24,40 +24,15 @@ constexpr auto make_copy(auto& value) -> std::remove_cvref_t<decltype(value)> {
|
|||
|
||||
#define ADD_TYPE_HINT(type) template <> constexpr const char* const to_type_hint_str::value<type> = #type
|
||||
|
||||
#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 TEST_SKIP_MSG(msg) ret_val_s { "", ReturnCode::SKIPPED, msg}
|
||||
#define TEST_FAIL(msg, ...) _ret_val_from_ctx<__VA_ARGS__>(ReturnCode::FAILED, msg)
|
||||
#define TEST_PASS(...) _ret_val_from_ctx<__VA_ARGS__>(ReturnCode::PASSED)
|
||||
#define TEST_PASS_MSG(msg, ...) _ret_val_from_ctx<__VA_ARGS__>(ReturnCode::PASSED, msg)
|
||||
#define TEST_SKIP(...) _ret_val_from_ctx<__VA_ARGS__>(ReturnCode::SKIPPED)
|
||||
#define TEST_SKIP_MSG(msg, ...) _ret_val_from_ctx<__VA_ARGS__>(ReturnCode::SKIPPED, msg)
|
||||
|
||||
#define TEST_FAIL_TYPE(msg, type_hint) ret_val_s { "", ReturnCode::FAILED, msg, to_type_hint_str::value<type_hint> }
|
||||
#define TEST_PASS_TYPE(type_hint) ret_val_s { "", ReturnCode::PASSED, nullptr, to_type_hint_str::value<type_hint> }
|
||||
#define TEST_PASS_MSG_TYPE(msg, type_hint) ret_val_s { "", ReturnCode::PASSED, msg, to_type_hint_str::value<type_hint> }
|
||||
#define TEST_SKIP_TYPE(type_hint) ret_val_s { "", ReturnCode::SKIPPED, nullptr, to_type_hint_str::value<type_hint> }
|
||||
|
||||
#define TEST_FAIL_TYPE_NUM(msg, type_hint, num) ret_val_s { "", ReturnCode::FAILED, msg, to_type_hint_str::value<type_hint>, num }
|
||||
#define TEST_PASS_TYPE_NUM(type_hint, num) ret_val_s { "", ReturnCode::PASSED, nullptr, to_type_hint_str::value<type_hint>, num }
|
||||
#define TEST_PASS_MSG_TYPE_NUM(msg, type_hint, num) ret_val_s { "", ReturnCode::PASSED, msg, to_type_hint_str::value<type_hint>, num }
|
||||
#define TEST_SKIP_TYPE_NUM(type_hint, num) ret_val_s { "", ReturnCode::SKIPPED, nullptr, to_type_hint_str::value<type_hint>, 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(all_eq_to(first, last, 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(equal_to(first, last, eq), "Elements in (" #first ", " #last ") and " #eq " differ" _LOCATION, type, num)
|
||||
|
||||
#define ASSERT_TYPE(condition, type) ASSERT_TYPE_NUM(condition, type, -1ULL)
|
||||
#define ASSERT_TYPE_MSG(condition, msg, type) ASSERT_TYPE_NUM_MSG(condition, msg, type -1ULL)
|
||||
#define ASSERT_TYPE_ALL_EQ(first, last, eq, type) ASSERT_TYPE_NUM_ALL_EQ(first, last, eq, type, -1ULL)
|
||||
#define ASSERT_TYPE_C_ARR_EQ(first, last, eq, type) ASSERT_TYPE_NUM_C_ARR_EQ(first, last, eq, type, -1ULL)
|
||||
|
||||
#define ASSERT(condition) ASSERT_TYPE(condition, std::nullptr_t)
|
||||
#define ASSERT_MSG(condition, msg) ASSERT_TYPE_MSG(condition, msg, std::nullptr_t)
|
||||
#define ASSERT_ALL_EQ(first, last, eq) ASSERT_TYPE_ALL_EQ(first, last, eq, std::nullptr_t)
|
||||
#define ASSERT_C_ARR_EQ(first, last, eq) ASSERT_TYPE_C_ARR_EQ(first, last, eq, std::nullptr_t)
|
||||
|
||||
#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)
|
||||
#define ASSERT(condition, ...) ASSERT_MSG((condition), nullptr, __VA_ARGS__)
|
||||
#define ASSERT_MSG(condition, msg, ...) { if (!(condition)) return _ret_val_from_ctx<__VA_ARGS__>(ReturnCode::FAILED, msg); } static_assert(true, "")
|
||||
#define ASSERT_THROWS(operation, exception_type, ...) if not consteval { try { operation; ASSERT_MSG(false, #operation " did not throw " #exception_type _LOCATION, __VA_ARGS__); } catch (exception_type &e) {} } static_assert(true, "")
|
||||
|
||||
template<typename T>
|
||||
concept StringLike = std::is_convertible_v<T, std::string_view>;
|
||||
|
|
@ -118,6 +93,9 @@ struct to_type_hint_str {
|
|||
static constexpr const char *value = nullptr;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
constexpr const char *to_type_hint_str_v = to_type_hint_str::value<T>;
|
||||
|
||||
ADD_TYPE_HINT(bool);
|
||||
ADD_TYPE_HINT(int);
|
||||
ADD_TYPE_HINT(char);
|
||||
|
|
@ -286,6 +264,27 @@ constexpr void get_test_param() {
|
|||
#define CONTEXT_PARAM(type, name, ...) template<> template<> constexpr type test_context_params<CONTEXT(__VA_ARGS__)>::value< #name >
|
||||
#define CONTEXT_PARAM_ARR(type, name, ...) template<> template<> constexpr type test_context_params<CONTEXT(__VA_ARGS__)>::value< #name >[]
|
||||
|
||||
template<typename ctx>
|
||||
requires std::is_same_v<ctx, ctx_tn<typename ctx::type, ctx::nr>>
|
||||
constexpr ret_val_s _ret_val_from_ctx(ReturnCode ret, const char *msg = nullptr) {
|
||||
return ret_val_s {"", ret, msg, to_type_hint_str_v<typename ctx::type>, ctx::nr };
|
||||
}
|
||||
template<typename ctx>
|
||||
requires std::is_same_v<ctx, ctx_t<typename ctx::type>>
|
||||
constexpr ret_val_s _ret_val_from_ctx(ReturnCode ret, const char *msg = nullptr) {
|
||||
return ret_val_s {"", ret, msg, to_type_hint_str_v<typename ctx::type> };
|
||||
}
|
||||
template<typename ctx>
|
||||
requires std::is_same_v<ctx, ctx_n<ctx::nr>>
|
||||
constexpr ret_val_s _ret_val_from_ctx(ReturnCode ret, const char *msg = nullptr) {
|
||||
return ret_val_s {"", ret, msg, nullptr, ctx::nr };
|
||||
}
|
||||
template<typename ctx = void>
|
||||
constexpr ret_val_s _ret_val_from_ctx(ReturnCode ret, const char *msg = nullptr) {
|
||||
return ret_val_s {"", ret, msg };
|
||||
}
|
||||
|
||||
|
||||
|
||||
class test_definition {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ constexpr test_suite tests = define_tests("Assignment")
|
|||
|
||||
v1 = original;
|
||||
v2 = original;
|
||||
ASSERT_TYPE_NUM_THROWS((too_small = original), std::invalid_argument, T, N);
|
||||
ASSERT_THROWS((too_small = original), std::invalid_argument, ctx);
|
||||
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v1, get_test_param<ctx, "arr">()), T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v2, get_test_param<ctx, "arr">()), T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(original, get_test_param<ctx, "arr">()), T, N);
|
||||
ASSERT(std::ranges::equal(v1, get_test_param<ctx, "arr">()), ctx);
|
||||
ASSERT(std::ranges::equal(v2, get_test_param<ctx, "arr">()), ctx);
|
||||
ASSERT(std::ranges::equal(original, get_test_param<ctx, "arr">()), ctx);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
|
@ -43,10 +43,10 @@ constexpr test_suite tests = define_tests("Assignment")
|
|||
|
||||
v1 = force_move(original1);
|
||||
v2 = force_move(original2);
|
||||
ASSERT_TYPE_NUM_THROWS((too_small = force_move(original3)), std::invalid_argument, T, N);
|
||||
ASSERT_THROWS((too_small = force_move(original3)), std::invalid_argument, ctx);
|
||||
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v1, get_test_param<ctx, "arr">()), T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v2, get_test_param<ctx, "arr">()), T, N);
|
||||
ASSERT(std::ranges::equal(v1, get_test_param<ctx, "arr">()), ctx);
|
||||
ASSERT(std::ranges::equal(v2, get_test_param<ctx, "arr">()), ctx);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
|
@ -66,11 +66,11 @@ constexpr test_suite tests = define_tests("Assignment")
|
|||
|
||||
v1 = arr;
|
||||
v2 = arr;
|
||||
ASSERT_TYPE_NUM_THROWS((too_small = arr), std::invalid_argument, T, N);
|
||||
ASSERT_THROWS((too_small = arr), std::invalid_argument, ctx);
|
||||
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v1, get_test_param<ctx, "arr">()), T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v2, get_test_param<ctx, "arr">()), T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(arr, get_test_param<ctx, "arr">()), T, N);
|
||||
ASSERT(std::ranges::equal(v1, get_test_param<ctx, "arr">()), ctx);
|
||||
ASSERT(std::ranges::equal(v2, get_test_param<ctx, "arr">()), ctx);
|
||||
ASSERT(std::ranges::equal(arr, get_test_param<ctx, "arr">()), ctx);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
|
@ -87,10 +87,10 @@ constexpr test_suite tests = define_tests("Assignment")
|
|||
|
||||
v1 = get_test_param<ctx, "ilist">();
|
||||
v2 = get_test_param<ctx, "ilist">();
|
||||
ASSERT_TYPE_NUM_THROWS((too_small = get_test_param<ctx, "ilist">()), std::invalid_argument, T, N);
|
||||
ASSERT_THROWS((too_small = get_test_param<ctx, "ilist">()), std::invalid_argument, ctx);
|
||||
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v1, get_test_param<ctx, "ilist">()), T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v2, get_test_param<ctx, "ilist">()), T, N);
|
||||
ASSERT(std::ranges::equal(v1, get_test_param<ctx, "ilist">()), ctx);
|
||||
ASSERT(std::ranges::equal(v2, get_test_param<ctx, "ilist">()), ctx);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
|
@ -113,12 +113,12 @@ constexpr test_suite tests = define_tests("Assignment")
|
|||
v1.assign(count1, value);
|
||||
v2.assign(count2, value);
|
||||
|
||||
ASSERT_TYPE_NUM(v1.size() == count1, T, N);
|
||||
ASSERT_TYPE_NUM(v2.size() == count2, T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::all_of(v1, [value](auto&& e) { return e == value; }), T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::all_of(v1, [value](auto&& e) { return e == value; }), T, N);
|
||||
ASSERT(v1.size() == count1, ctx);
|
||||
ASSERT(v2.size() == count2, ctx);
|
||||
ASSERT(std::ranges::all_of(v1, [value](auto&& e) { return e == value; }), ctx);
|
||||
ASSERT(std::ranges::all_of(v1, [value](auto&& e) { return e == value; }), ctx);
|
||||
|
||||
ASSERT_TYPE_NUM((value == get_test_param<ctx, "value">()), T, N);
|
||||
ASSERT((value == get_test_param<ctx, "value">()), ctx);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char*, TestObj);
|
||||
|
|
@ -140,14 +140,14 @@ constexpr test_suite tests = define_tests("Assignment")
|
|||
v2.assign(std::begin(get_test_param<ctx, "arr">()), std::end(get_test_param<ctx, "arr">()));
|
||||
v3.assign(container.begin(), container.end());
|
||||
|
||||
ASSERT_TYPE_NUM_THROWS(
|
||||
ASSERT_THROWS(
|
||||
(too_small.assign(std::begin(get_test_param<ctx, "arr">()),
|
||||
std::end(get_test_param<ctx, "arr">()))), std::invalid_argument, T, N);
|
||||
std::end(get_test_param<ctx, "arr">()))), std::invalid_argument, ctx);
|
||||
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v1, get_test_param<ctx, "arr">()), T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v2, get_test_param<ctx, "arr">()), T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v3, container), T, N);
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(container, get_test_param<ctx, "ilist">()), T, N);
|
||||
ASSERT(std::ranges::equal(v1, get_test_param<ctx, "arr">()), ctx);
|
||||
ASSERT(std::ranges::equal(v2, get_test_param<ctx, "arr">()), ctx);
|
||||
ASSERT(std::ranges::equal(v3, container), ctx);
|
||||
ASSERT(std::ranges::equal(container, get_test_param<ctx, "ilist">()), ctx);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
|
@ -163,9 +163,9 @@ constexpr test_suite tests = define_tests("Assignment")
|
|||
|
||||
v.assign(get_test_param<ctx, "ilist">());
|
||||
|
||||
ASSERT_TYPE_NUM(std::ranges::equal(v, get_test_param<ctx, "ilist">()), T, N);
|
||||
ASSERT(std::ranges::equal(v, get_test_param<ctx, "ilist">()), ctx);
|
||||
|
||||
ASSERT_TYPE_NUM_THROWS(too_small.assign(get_test_param<ctx, "ilist">()), std::invalid_argument, T, N);
|
||||
ASSERT_THROWS(too_small.assign(get_test_param<ctx, "ilist">()), std::invalid_argument, ctx);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
|
|
|||
Loading…
Reference in New Issue