gmio/tests/utest_lib.h

47 lines
1.4 KiB
C
Raw Normal View History

2014-01-30 01:33:49 +08:00
/* Adapted from minunit
* See : http://www.jera.com/techinfo/jtns/jtn002.html
* http://c.learncodethehardway.org/book/ex30.html
*/
#ifndef UTEST_LIB_H
#define UTEST_LIB_H
#include <stdio.h>
#include <stdlib.h>
2014-11-21 18:41:52 +08:00
#define UTEST_SUITE_START() const char* message = NULL
2014-01-30 01:33:49 +08:00
#define UTEST_ASSERT(test) if (!(test))\
{ printf(" ERROR : %s (line = %i, file = %s)", #test, __LINE__, __FILE__);\
return #test; }
#define UTEST_ASSERT_MSG(test, message) if (!(test))\
{ printf(message); return message; }
#define UTEST_RUN(test) printf("\n-----%s", " " #test); \
message = test();\
tests_run++;\
if (message) return message;
2014-01-30 07:26:30 +08:00
#define UTEST_MAIN(name) \
int main(int argc, char *argv[]) {\
2015-03-03 17:35:36 +08:00
const char *result = NULL; \
\
2015-03-04 00:10:10 +08:00
(void)argc; \
2015-03-03 17:35:36 +08:00
printf("----\nRUNNING: %s\n", argv[0]);\
result = name();\
if (result != NULL) {\
printf("\n\nFAILED: %s\n", result);\
}\
else {\
printf("\n\nALL TESTS PASSED\n");\
}\
printf("Tests run: %d\n", tests_run);\
exit(result != NULL);\
2014-01-30 07:26:30 +08:00
}
2014-01-30 01:33:49 +08:00
static int tests_run;
#endif /* UTEST_LIB_H */