-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_test.h
46 lines (38 loc) · 837 Bytes
/
unit_test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#define DEBUG 1
int test_run = 0;
#define MY_TEST(name, ft) printf("%-15s -- ", name); ft();
#define MY_UNIT_TEST(name) void name()
#define ALL_TESTS void run_all_tests(void)
#define RUN_TEST int main()\
{\
setbuf(stdout, NULL);\
run_all_tests();\
fprintf(stdout, "\nTESTS RUN: %d\n", test_run);\
return (0);\
}\
#define UT_ASS(msg, test) test_run++; do { if (!(test)) printf("%s", msg); else printf("."); } while (0);
/*
** HOW TO USE THIS UNIT TEST?
**
** Create a new file:
** #include "u-test.h"
** #include "foo.h"
**
** MY_UNIT_TEST(test_foo)
** {
** UT_ASS("Error", foo == value)
** }
**
** ALL_TESTS
** {
** MY_TEST("foo", test_foo)
** }
**
** RUN_TEST
**
** And, compile with sources... That's it!
*/