test: Add test_run and test_assert macros
test_run and test_assert replaces regular assert with better logging which include the currently running test name. The tests can now also be built without DEBUG.
This commit is contained in:
parent
8610ec4aac
commit
aef19fe383
2 changed files with 96 additions and 73 deletions
23
include/test.h
Normal file
23
include/test.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef _TEST_H
|
||||
#define _TEST_H
|
||||
|
||||
char *__curtestname = "<none>";
|
||||
|
||||
#define test_run(func) \
|
||||
do { \
|
||||
char *orig = __curtestname; \
|
||||
__curtestname = #func; \
|
||||
func(); \
|
||||
__curtestname = orig; \
|
||||
} while (0)
|
||||
|
||||
#define test_assert(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
fprintf(stderr, "%s:%d: %s: test_assert failed: %s\n", __FILE__, __LINE__, \
|
||||
__curtestname, #cond); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue