// Minimal assertion harness for the host tests. No dependencies, prints the // failing expression with file:line, and exits non-zero on any failure so // tests/run_tests.sh is usable as a gate. #pragma once #include #include static int g_checks = 0; static int g_failures = 0; static const char *g_section = "unset"; #define CASE(name) (g_section = (name)) #define CHECK(cond) \ do { \ g_checks++; \ if (!(cond)) { \ g_failures++; \ std::printf(" FAIL %s:%d [%s] %s\n", __FILE__, __LINE__, \ g_section, #cond); \ } \ } while (0) #define CHECK_EQ(actual, expected) \ do { \ g_checks++; \ const long long _a = (long long)(actual), _e = (long long)(expected); \ if (_a != _e) { \ g_failures++; \ std::printf(" FAIL %s:%d [%s] %s == %s : got %lld, want %lld\n", __FILE__, \ __LINE__, g_section, #actual, #expected, _a, _e); \ } \ } while (0) #define CHECK_STR(actual, expected) \ do { \ g_checks++; \ if (std::strcmp((actual), (expected)) != 0) { \ g_failures++; \ std::printf(" FAIL %s:%d [%s] %s == %s : got \"%s\", want \"%s\"\n", \ __FILE__, __LINE__, g_section, #actual, #expected, (actual), \ (expected)); \ } \ } while (0) static int report(const char *suite) { std::printf("%-24s %3d checks, %d failures\n", suite, g_checks, g_failures); return g_failures == 0 ? 0 : 1; }