Simplify test framework and improve test script
This commit is contained in:
@@ -4,33 +4,19 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TESTING_BEGIN() \
|
||||
do { \
|
||||
memset(&test_run, 0, sizeof(test_run)); \
|
||||
} while (0)
|
||||
|
||||
#define TESTING_END() \
|
||||
do { \
|
||||
testing_end_msg(); \
|
||||
return 0 == test_run.fail_count ? EXIT_SUCCESS : EXIT_FAILURE; \
|
||||
} while (0)
|
||||
|
||||
#define RUN_TEST(test) \
|
||||
do { \
|
||||
++test_run.test_count; \
|
||||
test(); \
|
||||
} while (0)
|
||||
#define TESTING_BEGIN() fail_count = 0
|
||||
#define TESTING_END() return 0 == fail_count ? EXIT_SUCCESS : EXIT_FAILURE
|
||||
#define RUN_TEST(test) test()
|
||||
|
||||
#define ASSERT_FAIL() \
|
||||
do { \
|
||||
++test_run.fail_count; \
|
||||
++fail_count; \
|
||||
testing_fail_msg(__func__, __FILE__, __LINE__); \
|
||||
return; \
|
||||
} while (0)
|
||||
|
||||
#define ASSERT_TRUE(p) \
|
||||
do { \
|
||||
++test_run.assertion_count; \
|
||||
if (!(p)) \
|
||||
ASSERT_FAIL(); \
|
||||
} while (0)
|
||||
@@ -46,15 +32,8 @@
|
||||
#define ASSERT_LE(x, y) ASSERT_TRUE((y) <= (x))
|
||||
#define ASSERT_MEM_EQUAL(p, q, n) ASSERT_TRUE(memcmp(p, q, n) == 0)
|
||||
|
||||
typedef struct {
|
||||
int test_count;
|
||||
int fail_count;
|
||||
int assertion_count;
|
||||
} test_run_t;
|
||||
|
||||
extern test_run_t test_run;
|
||||
extern int fail_count;
|
||||
|
||||
void testing_fail_msg(const char *func, const char *file, int line);
|
||||
void testing_end_msg(void);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user