added location to asserts and ASSERT_THROWS
This commit is contained in:
parent
f08c2890f1
commit
5fd03b408b
|
|
@ -13,16 +13,22 @@
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
|
#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_FAIL(msg) ret_val_s { "", ReturnCode::FAILED, msg }
|
||||||
#define TEST_PASS() ret_val_s { "", ReturnCode::PASSED, nullptr }
|
#define TEST_PASS() ret_val_s { "", ReturnCode::PASSED, nullptr }
|
||||||
#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(condition) ASSERT_MSG(condition, #condition "" _LOCATION)
|
||||||
#define ASSERT_MSG(condition, msg) { if (!(condition)) return TEST_FAIL(msg); } static_assert(true, "")
|
#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_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<decltype(eq)>()), "Elements in (" #first ", " #last ") and " #eq " differ")
|
#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" _LOCATION)
|
||||||
#define ASSERT_ITER_EQ(first, last, eq) ASSERT_MSG(std::equal(first, last, (eq).begin(), all_eq_arr_arr_test_func<std::iterator_traits<decltype(eq)::iterator>::value_type>()), "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<std::iterator_traits<decltype(eq)::iterator>::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<typename T>
|
template<typename T>
|
||||||
constexpr auto all_eq_arr_elem_test_func(T&& eq) {
|
constexpr auto all_eq_arr_elem_test_func(T&& eq) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue