#pragma once #include #include #include #include #include "common.hpp" #include "result.hpp" const uint64_t MAX_TESTS = 1024 * 1024; static void (*tests[MAX_TESTS])() = {0}; const char* add_test(void (*fun)(void)) { for (uint64_t i = 0; i < MAX_TESTS; ++i) { if (tests[i] == 0) { tests[i] = fun; break; } } return 0; } bool run_tests() { for (uint64_t i = 0; i < MAX_TESTS; ++i) { if (tests[i] == 0) break; tests[i](); } return true; } #define CONCAT_IMPL(x, y) x##y #define MACRO_CONCAT(x, y) CONCAT_IMPL(x, y) #define TEST_CASE_IMPL(ID, ...) \ static void ID(); \ static const char* MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ add_test(&ID); \ void ID() #define TEST_CASE(fun_) TEST_CASE_IMPL(MACRO_CONCAT(fun_, _COUNTER_)) Result to_value(Value& val) { return val.copy(); } Result to_value(const Value& val) { return val.copy(); } template requires std::derived_from Result to_value(T& val) { return val.copy(); } template requires(!std::derived_from && !std::is_fundamental::value) Result to_value(T& val) { return Value::create(val); } template requires(!std::derived_from && std::is_fundamental::value) Result to_value(T val) { return Value::create(val); } #define ASSERT_EQUALS(lhs, rhs) \ do { \ auto lv = DIEX(to_value(lhs)); \ auto rv = DIEX(to_value(rhs)); \ short c = DIEX(lv.cmp(rv)); \ if (c != 0) { \ fprintf(stderr, "Values not equal at %s:%d\n", __FILE__, __LINE__); \ debug_print(lv); \ debug_print(rv); \ exit(EXIT_FAILURE); \ } \ } while (0) int main() { return run_tests() ? 0 : 1; }