added check whether consteval results are valid
This commit is contained in:
parent
fd849ecfa4
commit
fb22b54960
|
|
@ -124,7 +124,7 @@ inline std::ostream& operator<<(std::ostream& os, ReturnCode rc);
|
|||
struct ret_val_s {
|
||||
const char *test_name = "";
|
||||
ReturnCode val = ReturnCode::FAILED;
|
||||
const char *msg = "";
|
||||
const char *msg = nullptr;
|
||||
const char *type_hint = nullptr;
|
||||
std::size_t param_nr = -1;
|
||||
};
|
||||
|
|
@ -183,6 +183,26 @@ class test_definition_impl : public test_definition {
|
|||
ret_val_s _c_res;
|
||||
};
|
||||
|
||||
class _has_been_const_evaluated_test : public test_definition {
|
||||
public:
|
||||
constexpr _has_been_const_evaluated_test()
|
||||
: _res(_name, ReturnCode::FAILED, "Could not be evaluated at compile time") {
|
||||
if consteval {
|
||||
_res = ret_val_s { _name, ReturnCode::PASSED };
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr ret_val_s evaluate() const override { return _res; }
|
||||
|
||||
[[nodiscard]] const char *name() const override { return _name; }
|
||||
[[nodiscard]] EvalFlag evalFlag() const override { return EvalFlag::CONSTEVAL; }
|
||||
[[nodiscard]] const ret_val_s &c_res() const override { return _res; }
|
||||
|
||||
private:
|
||||
const char *_name = "Constant evaluation check";
|
||||
ret_val_s _res;
|
||||
};
|
||||
|
||||
template<typename ...TestDefs>
|
||||
requires (sizeof...(TestDefs) == 0 || (std::derived_from<TestDefs, test_definition> && ...))
|
||||
class test_suite {
|
||||
|
|
@ -190,7 +210,8 @@ class test_suite {
|
|||
public:
|
||||
static constexpr std::size_t TEST_NR = sizeof...(TestDefs);
|
||||
|
||||
constexpr test_suite(const char *name, std::tuple<TestDefs...> tests) : _name(name), _tests(tests) {}
|
||||
constexpr test_suite(const char *name, std::tuple<TestDefs...> tests)
|
||||
: _name(name), _tests(tests), _c_test(_has_been_const_evaluated_test()) {}
|
||||
|
||||
int run() const {
|
||||
|
||||
|
|
@ -267,7 +288,8 @@ class test_suite {
|
|||
<< 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";
|
||||
<< part_skipped << "/" << num_tests << " tests have been partially skipped" << "\n"
|
||||
<< (_c_test.c_res().val == ReturnCode::PASSED ? "Results of constant evaluation are valid" : "---Results of constant evaluation are invalid---") << "\n";
|
||||
|
||||
return -failed;
|
||||
}
|
||||
|
|
@ -275,6 +297,7 @@ class test_suite {
|
|||
private:
|
||||
const char *_name;
|
||||
std::tuple<TestDefs...> _tests;
|
||||
_has_been_const_evaluated_test _c_test;
|
||||
|
||||
template<std::size_t ...Is>
|
||||
static constexpr auto expand_test_tuple(const auto &tests, std::index_sequence<Is...>) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue