updated return value
This commit is contained in:
parent
690aa93af9
commit
2e3f1dc43d
|
|
@ -13,7 +13,9 @@
|
|||
#include <tuple>
|
||||
|
||||
#include "test_ret_val.h"
|
||||
#include "CompileOptional.h"
|
||||
|
||||
#define TEST_FAIL(msg) ret_val_s { "", ReturnCode::FAILED, msg }
|
||||
#define TEST_PASS(msg) ret_val_s { "", ReturnCode::PASSED, msg }
|
||||
|
||||
template<typename Suite>
|
||||
struct quick_test_def;
|
||||
|
|
@ -45,7 +47,11 @@ class test_definition_impl : public test_definition {
|
|||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr ret_val_s evaluate() const override { return std::apply(_func, _args); }
|
||||
[[nodiscard]] constexpr ret_val_s evaluate() const override {
|
||||
ret_val_s r = std::apply(_func, _args);
|
||||
r.test_name = _name;
|
||||
return r;
|
||||
}
|
||||
|
||||
[[nodiscard]] const char *name() const override { return _name; }
|
||||
[[nodiscard]] EvalFlag evalFlag() const override { return _evalFlag; }
|
||||
|
|
@ -71,6 +77,7 @@ class test_suite {
|
|||
int run() const {
|
||||
|
||||
auto test_arr = expand_test_tuple(_tests, std::make_index_sequence<TEST_NR>());
|
||||
int num_failed = 0;
|
||||
|
||||
std::cout << "--------------\n";
|
||||
|
||||
|
|
@ -91,16 +98,24 @@ class test_suite {
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return num_failed;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -6,9 +6,6 @@
|
|||
|
||||
#include <const_list.h>
|
||||
|
||||
#define TEST_FAIL(name, msg) ret_val_s { name, ReturnCode::FAILED, msg }
|
||||
#define TEST_PASS(name, msg) ret_val_s { name, ReturnCode::PASSED, msg }
|
||||
|
||||
enum ReturnCode { FAILED = -1, PASSED = 0 };
|
||||
|
||||
struct ret_val_s {
|
||||
|
|
|
|||
|
|
@ -7,34 +7,31 @@
|
|||
constexpr test_suite tests = define_tests("Tests")
|
||||
("Test Runtime", [](int = 1) constexpr{
|
||||
|
||||
return TEST_PASS("Test Runtime", "PASS");
|
||||
return TEST_PASS("PASS");
|
||||
}, EvalFlag::RUNTIME)
|
||||
("Test Consteval 1", [](char = 2) constexpr {
|
||||
return TEST_FAIL("ups");
|
||||
if (std::is_constant_evaluated()) {
|
||||
return TEST_PASS("Test Consteval", "PASS");
|
||||
return TEST_PASS("PASS");
|
||||
} else {
|
||||
return TEST_FAIL("Test Consteval", "FAIL");
|
||||
return TEST_FAIL("FAIL");
|
||||
}
|
||||
}, EvalFlag::CONSTEVAL)
|
||||
("Test Consteval", [](char = 2) constexpr {
|
||||
//std::cout << "";
|
||||
if (std::is_constant_evaluated()) {
|
||||
return TEST_PASS("Test Consteval", "PASS");
|
||||
return TEST_PASS( "PASS");
|
||||
} else {
|
||||
return TEST_FAIL("Test Consteval", "FAIL");
|
||||
return TEST_FAIL("FAIL");
|
||||
}
|
||||
}, EvalFlag::CONSTEVAL)
|
||||
("Test Runtime Consteval", [](short = 3) constexpr{
|
||||
if (std::is_constant_evaluated()) {
|
||||
return TEST_PASS("Test Consteval Runtime", "PASS Consteval");
|
||||
return TEST_PASS("PASS Consteval");
|
||||
} else {
|
||||
return TEST_PASS("Test Consteval", "PASS Runtime");
|
||||
return TEST_PASS("PASS Runtime");
|
||||
}
|
||||
}, EvalFlag::RUNTIME_CONSTEVAL);
|
||||
|
||||
int main() {
|
||||
|
||||
tests.run();
|
||||
|
||||
return 0;
|
||||
return tests.run();
|
||||
}
|
||||
Loading…
Reference in New Issue