diff --git a/include/helper.h b/include/helper.h index 857fc94..ec91fa2 100644 --- a/include/helper.h +++ b/include/helper.h @@ -7,6 +7,8 @@ #include #include +#include +#include namespace cc::helper { @@ -52,7 +54,7 @@ namespace cc::helper { auto dist1 = std::distance(first1, last1); auto dist2 = std::distance(first2, last2); - if (max_dist < dist1 || max_dist < dist2) throw std::invalid_argument("Distance between iterators does not fit inbetween other " + if (max_dist < dist1 || max_dist < dist2) throw std::invalid_argument("Distance between iterators does not fit in between other " "(Range 1: " + std::to_string(dist1) + "/" + std::to_string(std::distance(first1, end1)) + ", " + "Range 2: " + std::to_string(dist2) + "/" + std::to_string(std::distance(first2, end2)) + ")"); diff --git a/test/common_helper/test_define_test.hpp b/test/common_helper/test_define_test.hpp index 38efb51..89b8a1b 100644 --- a/test/common_helper/test_define_test.hpp +++ b/test/common_helper/test_define_test.hpp @@ -11,11 +11,14 @@ #include #include #include +#include #include "test_ret_val.h" #define TEST_FAIL(msg) ret_val_s { "", ReturnCode::FAILED, msg } -#define TEST_PASS(msg) ret_val_s { "", ReturnCode::PASSED, 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 } template struct quick_test_def; @@ -79,7 +82,7 @@ class test_suite { auto test_arr = expand_test_tuple(_tests, std::make_index_sequence()); int num_failed = 0; - std::cout << "--------------\n"; + std::array, TEST_NR> ret_vals = { { ReturnCode::NOT_EVALUATED } }; for (auto [i, test_ref] : std::ranges::views::enumerate(test_arr)) { const auto& test = test_ref.get(); @@ -96,26 +99,50 @@ class test_suite { ret = ret_val_s(test.name(), ReturnCode::FAILED, ret_exc_str.c_str()); } - std::cout << "Result of Runtime Evaluation of Test \"" << ret.test_name << "\": " << ret.val << "\n" - << "\t" << ret.msg << std::endl; - - if (ret.val != ReturnCode::PASSED) { - --num_failed; + std::cout << "Result of Runtime Evaluation of Test \"" << ret.test_name << "\": " << ret.val; + if (ret.msg != nullptr) { + std::cout << "\n\t" << ret.msg; } + std::cout << std::endl; + + ret_vals[i][0] = ret.val; } if (test.evalFlag() == EvalFlag::CONSTEVAL || test.evalFlag() == EvalFlag::RUNTIME_CONSTEVAL) { - const ret_val_s& ret = test.c_res(); - std::cout << "Result of Consteval Evaluation of Test \"" << ret.test_name << "\": " << ret.val << "\n" - << "\t" << ret.msg << std::endl; - - if (ret.val != ReturnCode::PASSED) { - --num_failed; + const ret_val_s &ret = test.c_res(); + std::cout << "Result of Consteval Evaluation of Test \"" << ret.test_name << "\": " << ret.val; + if (ret.msg != nullptr) { + std::cout << "\n\t" << ret.msg; } - } - } + std::cout << std::endl; - return num_failed; + ret_vals[i][1] = ret.val; + } + + std::cout << "--------------\n"; + } + + auto ret_vals_j = ret_vals | std::ranges::views::join; + auto correct = std::ranges::count_if(ret_vals, [](auto&& e) { + return std::ranges::none_of(e, [](auto&& c) { return c == ReturnCode::FAILED; }) + && std::ranges::any_of(e, [](auto&& c) { return c == ReturnCode::PASSED; }); + }); + auto failed = std::ranges::count_if(ret_vals, [](auto&& e) { + return std::ranges::any_of(e, [](auto&& c) { return c == ReturnCode::FAILED; }); }); + auto full_skipped = std::ranges::count_if(ret_vals, [](auto&& e) { + return std::ranges::all_of(e, [](auto&& c) { return c == ReturnCode::SKIPPED || c == ReturnCode::NOT_EVALUATED; }); }); + auto part_skipped = std::ranges::count_if(ret_vals, [](auto&& e) { + return std::ranges::any_of(e, [](auto&& c) { return c == ReturnCode::SKIPPED; }); }); + + std::size_t num_tests = ret_vals.size(); + + std::cout << "Final Result: " << "\n" + << correct << "/" << num_tests << " tests evaluated correctly" << "\n" + << failed << "/" << num_tests << " tests failed" << "\n" + << full_skipped << "/" << num_tests << " tests skipped" << "\n" + << part_skipped << "/" << num_tests << " tests have been partially skipped" << "\n"; + + return -failed; } private: diff --git a/test/common_helper/test_ret_val.h b/test/common_helper/test_ret_val.h index 61e1544..e3ca2d4 100644 --- a/test/common_helper/test_ret_val.h +++ b/test/common_helper/test_ret_val.h @@ -6,7 +6,7 @@ #include -enum ReturnCode { FAILED = -1, PASSED = 0 }; +enum ReturnCode { FAILED = -1, PASSED = 0, SKIPPED = 1, NOT_EVALUATED = 2 }; struct ret_val_s { const char *test_name = ""; @@ -31,6 +31,10 @@ std::ostream& operator<<(std::ostream& os, const ReturnCode &rc) { return os << "FAILED"; case PASSED: return os << "PASSED"; + case SKIPPED: + return os << "SKIPPED"; + case NOT_EVALUATED: + return os << "NOT EVALUATED"; default: return os; } diff --git a/test/const_vector/const_vector_constructor.test.cpp b/test/const_vector/const_vector_constructor.test.cpp index 65c85ad..2075b69 100644 --- a/test/const_vector/const_vector_constructor.test.cpp +++ b/test/const_vector/const_vector_constructor.test.cpp @@ -1,34 +1,32 @@ #include #include "test_define_test.hpp" -#include "test_util.hpp" #include "test_ret_val.h" constexpr test_suite tests = define_tests("Tests") ("Test Runtime", [](int = 1) constexpr{ - return TEST_PASS("PASS"); + return TEST_PASS(); }, EvalFlag::RUNTIME) ("Test Consteval 1", [](char = 2) constexpr { - return TEST_FAIL("ups"); if (std::is_constant_evaluated()) { - return TEST_PASS("PASS"); + return TEST_PASS(); } else { return TEST_FAIL("FAIL"); } }, EvalFlag::CONSTEVAL) ("Test Consteval", [](char = 2) constexpr { if (std::is_constant_evaluated()) { - return TEST_PASS( "PASS"); + return TEST_SKIP(); } else { return TEST_FAIL("FAIL"); } }, EvalFlag::CONSTEVAL) ("Test Runtime Consteval", [](short = 3) constexpr{ if (std::is_constant_evaluated()) { - return TEST_PASS("PASS Consteval"); + return TEST_SKIP(); } else { - return TEST_PASS("PASS Runtime"); + return TEST_PASS(); } }, EvalFlag::RUNTIME_CONSTEVAL);