Repos
C++
1013 B32 lines Opens in site
Directory
Raw
Download
#pragma once
// Spec: SPEC.md NFR-TEST-01. Minimal dependency-free test harness (no framework, fewer moving parts).
#include <functional>
#include <string>
#include <vector>
namespace dp::test {
struct Case {
std::string name;
std::function<void()> fn;
};
std::vector<Case>& registry();
void fail(const char* file, int line, const std::string& expr);
int g_failures_for_main();
struct Registrar {
Registrar(const char* name, std::function<void()> fn) { registry().push_back({name, std::move(fn)}); }
};
} // namespace dp::test
#define DP_TEST(name) \
static void dp_test_##name(); \
static ::dp::test::Registrar dp_registrar_##name(#name, dp_test_##name); \
static void dp_test_##name()
#define CHECK(expr) \
do { if (!(expr)) ::dp::test::fail(__FILE__, __LINE__, #expr); } while (0)
#define CHECK_EQ(a, b) \
do { if (!((a) == (b))) ::dp::test::fail(__FILE__, __LINE__, #a " == " #b); } while (0)