colla/tests/runner.h
alessandro bason a66e58193f .
2025-06-24 17:47:08 +02:00

41 lines
1,011 B
C

#pragma once
#include "../core.h"
#include "../str.h"
typedef struct unit_test_t unit_test_t;
struct unit_test_t {
strview_t fname;
strview_t name;
void (*fn)(void);
unit_test_t *next;
};
extern unit_test_t *test_head;
extern unit_test_t *test_tail;
extern const char *last_fail_reason;
extern bool last_failed;
void ut_register(const char *file, const char *name, void (*fn)(void));
// #pragma data_seg(".CRT$XCU")
#define INITIALIZER(f) \
static void f(void); \
__declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \
__pragma(comment(linker,"/include:" #f "_")) \
static void f(void)
#define UNIT_TEST(name) \
void ut__test_##name(void); \
INITIALIZER(ut__register_##name) { ut_register(__FILE__, #name, ut__test_##name); } \
void ut__test_##name(void)
#define ASSERT(cond) \
if (!(cond)) { \
last_fail_reason = "assert(" COLLA_STRINGIFY(cond) ") at " COLLA_STRINGIFY(__LINE__); \
last_failed = true; \
return; \
}