]> git.llucax.com Git - software/mutest.git/blob - py/mutest.h
Add dynamic Python implementation
[software/mutest.git] / py / mutest.h
1
2 #include <stdio.h> /* printf(), fprintf() */
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 /* this increments when the "API" changes */
9 int mutest_api_version = 1;
10
11 int mutest_passed_count;
12 int mutest_failed_count;
13 void mutest_reset_counters() {
14         mutest_passed_count = 0;
15         mutest_failed_count = 0;
16 }
17
18 /*
19  * Verbose level:
20  * 0: quiet
21  * 1: errors
22  * 2: summary
23  * 3: suites
24  * 4: cases
25  * 5: checks
26  */
27 int mutest_verbose_level = 1;
28 void mutest_set_verbose_level(int val) {
29         mutest_verbose_level = val;
30 }
31
32 #define mu_check(exp) \
33         do { \
34                 if (exp) { \
35                         ++mutest_passed_count; \
36                         if (mutest_verbose_level >= 5) \
37                                 printf("%s:%d: mu_check(%s) passed\n", \
38                                         __FILE__, __LINE__, #exp); \
39                 } else { \
40                         ++mutest_failed_count; \
41                         if (mutest_verbose_level) \
42                                 fprintf(stderr, "%s:%d: mu_check(%s) " \
43                                         "failed, resuming test case\n", \
44                                         __FILE__, __LINE__, #exp); \
45                 } \
46         } while (0)
47
48 #define mu_ensure(exp) \
49         do { \
50                 if (exp) { \
51                         ++mutest_passed_count; \
52                         if (mutest_verbose_level >=5) \
53                                 printf("%s:%d: mu_ensure(%s) passed\n", \
54                                         __FILE__, __LINE__, #exp); \
55                 } else { \
56                         ++mutest_failed_count; \
57                         if (mutest_verbose_level) \
58                                 fprintf(stderr, "%s:%d: mu_ensure(%s) " \
59                                         "failed, aborting test case\n", \
60                                         __FILE__, __LINE__, #exp); \
61                         return; \
62                 } \
63         } while (0)
64
65 #ifdef __cplusplus
66 }
67 #endif
68