-
Notifications
You must be signed in to change notification settings - Fork 7
/
MinUnit.h
37 lines (29 loc) · 1002 Bytes
/
MinUnit.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
// Modification of Zed Shaw's unit testing macros from "Learn C The Hard Way"
// http://c.learncodethehardway.org/book/ex30.html
#undef NDEBUG
#ifndef _MINUNIT_H
#define _MINUNIT_H
#include "Debug.h"
/*! \file MinUnit.h
\brief A simple unit testing framework.
*/
#define mu_suite_start() int message = 0
#define mu_assert(test, message) if (!(test)) { slsm_log_err(message); return message; }
#define mu_run_test(test) slsm_debug("\n-----%s", " " #test); \
message = test(); tests_run++; if (message) return message;
#define RUN_TESTS(name) int main(int argc, char *argv[]) {\
argc = 1; \
slsm_debug("----- RUNNING: %s", argv[0]);\
printf("----\nRUNNING: %s\n", argv[0]);\
int result = name();\
if (result != 0) {\
printf("FAILED: %d\n", result);\
}\
else {\
printf("ALL TESTS PASSED\n");\
}\
printf("Tests run: %d\n", tests_run);\
exit(result != 0);\
}
int tests_run;
#endif /* _MINUNIT_H */