const_container/test/common_helper/test_util.hpp

55 lines
1.2 KiB
C++

//
// Created by Patrick Maschek on 14/03/2024.
//
#ifndef CONST_CONTAINER_TEST_UTIL_H_
#define CONST_CONTAINER_TEST_UTIL_H_
#include <concepts>
#include <iostream>
#include <string_view>
#include "test_ret_val.h"
#define TEST(ret_val, ret_code, msg_success, msg_fail)
struct TestStruct {
int x = 0;
char c = 0;
const char * s = "This is a string";
constexpr bool operator==(const TestStruct &other) const { return x == other.x && c == other.c && std::string_view(s) == other.s; }
};
template<std::invocable F>
consteval auto consteval_caller(F &func) {
return func();
}
template<std::invocable ...TestFuncs>
constexpr auto run_tests(TestFuncs... tests) {
constexpr std::size_t num_tests = sizeof...(tests);
std::array test_arr = { tests... };
ret_val<num_tests> ret;
for (std::size_t i = 0; i < test_arr.size(); ++i) {
ret[i] = test_arr[i]();
}
return ret;
};
template<std::size_t Nr>
void report(const ret_val<Nr>& ret_val) {
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"
<< "\t" << ret_val[i].msg << "\n";
}
}
#endif //CONST_CONTAINER_TEST_UTIL_H_