fix(test): improve testing macros
This commit is contained in:
parent
945343daa0
commit
edbe9ba3b8
1 changed files with 15 additions and 14 deletions
29
test.c
29
test.c
|
|
@ -5,21 +5,22 @@
|
|||
|
||||
#include "ds.h"
|
||||
|
||||
#define test(name, tests) do { \
|
||||
const char *_test_name = name; \
|
||||
int _tests_passed = 0; \
|
||||
int _tests = 0; \
|
||||
tests \
|
||||
_tests_passed += _tests; \
|
||||
printf("%s: %d/%d tests passed\n", name, _tests_passed, _tests); \
|
||||
} while (0)
|
||||
#define test(name, tests) do { \
|
||||
const char *_test_name = name; \
|
||||
int _tests_passed = 0; \
|
||||
int _tests = 0; \
|
||||
tests \
|
||||
_tests_passed += _tests; \
|
||||
printf("%s: %d/%d tests passed\n", name, _tests_passed, _tests); \
|
||||
} while (0)
|
||||
|
||||
#define it(message, test) do { \
|
||||
_tests++; \
|
||||
if (!(test)) { \
|
||||
printf("%s %s FAILED\n", _test_name, message); \
|
||||
_tests_passed--; \
|
||||
} \
|
||||
#define it(message, test) do { \
|
||||
_tests++; \
|
||||
if (!(test)) { \
|
||||
printf("%s %s FAILED @ %s:%d\n", _test_name, message, __FILE__, __LINE__); \
|
||||
printf(" -> test condition: (%s)\n", #test); \
|
||||
_tests_passed--; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue