Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 38 lines (26 sloc) 1.769 kb
efc6675 @client9 Remove dependency on libcheck and use minunit, add .gitignore
client9 authored
1 #ifndef MINUNIT_H
2 #define MINUNIT_H
3
4 /* http://www.jera.com/techinfo/jtns/jtn002.html */
5 /* http://stringencoders.googlecode.com/svn/trunk/test/minunit.h */
6
7 #define mu_assert(test) do { if (!(test)) { snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s:%d", __FILE__, __LINE__); return mu_buf; } } while (0)
8
9 #define mu_assert_msg(msg, test) do { if (!(test)) { snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s %s:%d", msg, __FILE__, __LINE__); return mu_buf; } } while (0)
10
11 #define mu_assert_int_equals(lhs, rhs) do { if (lhs != rhs) { snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s:%d", __FILE__, __LINE__); return mu_buf; } } while (0)
12
13 #define mu_assert_str_equals(lhs, rhs) do { if (strcmp(lhs,rhs) != 0) { snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s:%d %s != %s", __FILE__, __LINE__, lhs, rhs); return mu_buf; } } while (0)
14
15 #define mu_assert_str_equals_msg(msg, lhs, rhs) do { if (strcmp(lhs,rhs) != 0) { snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s %s:%d %s != %s", msg, __FILE__, __LINE__, lhs, rhs); return mu_buf; } } while (0)
16
17 #define mu_assert_int_equals_msg(msg, lhs, rhs) do { if (lhs != rhs) { snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s %s:%d", msg, __FILE__, __LINE__); return mu_buf; } } while (0)
18
19 #define mu_run_test(test) do { printf("."); fflush(stdout); char *message = test(); tests_run++; \
20 if (message) return message; } while (0)
21
22 #define UNITTESTS \
23 int main() { \
24 printf("%s ", __FILE__); fflush(stdout); \
25 char *result = all_tests(); \
26 if (result != 0) { \
27 printf("%s\n", result); \
28 } else { \
29 printf("OK (%d tests)\n", tests_run); \
30 } \
31 return result != 0; \
32 }
33
34 int tests_run = 0;
35 char mu_buf[1024];
36
37 #endif
Something went wrong with that request. Please try again.