.
This commit is contained in:
parent
524ec0d1ce
commit
61c1060a98
16 changed files with 5043 additions and 31 deletions
45
tests/runner.h
Normal file
45
tests/runner.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include "../colla.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")
|
||||
|
||||
#if COLLA_WIN
|
||||
#define INITIALIZER(f) \
|
||||
static void f(void); \
|
||||
__declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \
|
||||
__pragma(comment(linker,"/include:" #f "_")) \
|
||||
static void f(void)
|
||||
#else
|
||||
#define INITIALIZER(f) \
|
||||
__attribute__((constructor)) static void f(void)
|
||||
#endif
|
||||
|
||||
#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; \
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue