diff --git a/test/common_helper/test_ret_val.h b/test/common_helper/test_ret_val.h index 7764a93..97dc71f 100644 --- a/test/common_helper/test_ret_val.h +++ b/test/common_helper/test_ret_val.h @@ -11,24 +11,6 @@ enum ReturnCode { FAILED = -1, PASSED = 0 }; -/*struct test_ret_val { - struct ret_val_s : public cc::const_list_node { - ReturnCode val = FAILED; - const char *msg = ""; - }; - - cc::const_list list; - - constexpr test_ret_val() = default; - constexpr test_ret_val(const test_ret_val& other) = delete; - constexpr test_ret_val(test_ret_val&& other) = default; - - constexpr test_ret_val& operator=(const test_ret_val& other) = delete; - constexpr test_ret_val& operator=(test_ret_val&& other) = default; - - constexpr operator bool() const { return std::all_of(list.cbegin(), list.cend(), [](auto e){ return !static_cast(e.val); }); } -};*/ - struct ret_val_s { const char *test_name = ""; ReturnCode val = FAILED; @@ -36,6 +18,14 @@ struct ret_val_s { }; template -using ret_val = std::array; +struct ret_val { + const char * name; + std::array vals; + + [[nodiscard]] constexpr inline std::size_t size() const { return vals.size(); } + + constexpr inline ret_val_s& operator[](std::size_t i) { return vals[i]; } + constexpr inline const ret_val_s& operator[](std::size_t i) const { return vals[i]; } +}; #endif //CONST_CONTAINER_TEST_RETURN_VAL_H_ diff --git a/test/common_helper/test_util.hpp b/test/common_helper/test_util.hpp index 897810e..00a8270 100644 --- a/test/common_helper/test_util.hpp +++ b/test/common_helper/test_util.hpp @@ -21,18 +21,19 @@ struct TestStruct { constexpr bool operator==(const TestStruct &other) const { return x == other.x && c == other.c && std::string_view(s) == other.s; } }; -template -consteval auto consteval_caller(F &func) { - return func(); +template + requires (std::invocable) +consteval auto consteval_caller(F &func, Args... args) { + return func(args...); } template -constexpr auto run_tests(TestFuncs... tests) { +constexpr auto run_tests(const char *name, TestFuncs... tests) { constexpr std::size_t num_tests = sizeof...(tests); std::array test_arr = { tests... }; - ret_val ret; + ret_val ret { .name = name }; for (std::size_t i = 0; i < test_arr.size(); ++i) { ret[i] = test_arr[i](); } @@ -42,7 +43,11 @@ constexpr auto run_tests(TestFuncs... tests) { template void report(const ret_val& ret_val) { - + + std::cout << "-----------------------------------------" << "\n"; + std::cout << "Report for test: \"" << ret_val.name << "\"\n"; + std::cout << "-----------------------------------------" << "\n"; + for (std::size_t i = 0; i < ret_val.size(); ++i) { std::cout << "Result of Test \"" << ret_val[i].test_name << "\" (number: " << i << "): " << (ret_val[i].val == ReturnCode::PASSED ? "PASSED" : "FAILED") << "\n" diff --git a/test/const_vector/const_vector_constructor.test.cpp b/test/const_vector/const_vector_constructor.test.cpp index 8cdc09d..44bdbb0 100644 --- a/test/const_vector/const_vector_constructor.test.cpp +++ b/test/const_vector/const_vector_constructor.test.cpp @@ -3,11 +3,13 @@ #include +#include "test_util.hpp" #include "test_ret_val.h" -constexpr auto test_func() { +constexpr auto test_func(const char *name) { - auto ret_val = run_tests([](){ + auto ret_val = run_tests(name, + [](){ return TEST_PASS("Test1", "PASS"); }); @@ -17,11 +19,12 @@ constexpr auto test_func() { } int main() { - auto ret = test_func(); + auto ret = test_func("Test 1"); - auto cret = consteval_caller(); + auto cret = consteval_caller(test_func, "Consteval Test"); report(ret); + report(cret); return 0; } \ No newline at end of file