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"
|
#include "ds.h"
|
||||||
|
|
||||||
#define test(name, tests) do { \
|
#define test(name, tests) do { \
|
||||||
const char *_test_name = name; \
|
const char *_test_name = name; \
|
||||||
int _tests_passed = 0; \
|
int _tests_passed = 0; \
|
||||||
int _tests = 0; \
|
int _tests = 0; \
|
||||||
tests \
|
tests \
|
||||||
_tests_passed += _tests; \
|
_tests_passed += _tests; \
|
||||||
printf("%s: %d/%d tests passed\n", name, _tests_passed, _tests); \
|
printf("%s: %d/%d tests passed\n", name, _tests_passed, _tests); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define it(message, test) do { \
|
#define it(message, test) do { \
|
||||||
_tests++; \
|
_tests++; \
|
||||||
if (!(test)) { \
|
if (!(test)) { \
|
||||||
printf("%s %s FAILED\n", _test_name, message); \
|
printf("%s %s FAILED @ %s:%d\n", _test_name, message, __FILE__, __LINE__); \
|
||||||
_tests_passed--; \
|
printf(" -> test condition: (%s)\n", #test); \
|
||||||
} \
|
_tests_passed--; \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue