2 #include <stdio.h> /* fprintf() */
8 /* check that an expression evaluates to true, continue if the check fails */
9 #define mu_check(exp) \
11 mu_print(MU_CHECK, "\t\t* Checking mu_check(%s)...\n", #exp); \
12 if (exp) ++mutest_passed_checks; \
14 ++mutest_failed_checks; \
15 mutest_case_failed = 1; \
16 mu_print(MU_ERROR, "%s:%d: mu_check(%s) failed, " \
17 "resuming test case\n", __FILE__, \
23 * ensure that an expression evaluates to true, abort the current test
24 * case if the check fails
26 #define mu_ensure(exp) \
28 mu_print(MU_CHECK, "\t\t* Checking mu_ensure(%s)...\n", #exp);\
29 if (exp) ++mutest_passed_checks; \
31 ++mutest_failed_checks; \
32 mutest_case_failed = 1; \
33 mu_print(MU_ERROR, "%s:%d: mu_ensure(%s) failed, " \
34 "aborting test case\n", __FILE__, \
41 * you don't need to pay any attention to what's next, unless you want to do
42 * some customization, of course, in which case, you're encouraged to take
46 /* verbosity level (each level shows all the previous levels too) */
48 MU_QUIET = 0, /* be completely quiet */
49 MU_ERROR, /* shows errors only */
50 MU_SUMMARY, /* shows a summary */
51 MU_SUITE, /* shows test suites progress */
52 MU_CASE, /* shows test cases progress */
53 MU_CHECK /* shows the current running check */
56 /* print a message according to the verbosity level */
57 #define mu_print(level, ...) \
59 if (mutest_verbose_level >= level) { \
60 if (mutest_verbose_level == MU_ERROR) \
61 fprintf(stderr, __VA_ARGS__); \
63 fprintf(stdout, __VA_ARGS__); \
68 * this function implements the test suites execution, you should generate
69 * a module with this function using mkmutest, or take a look to that script
70 * if you want to implement your own customized version */
73 /* macro for running a single initialization function */
75 #define mu_run_init(name) \
79 mu_print(MU_CASE, "\t+ Executing initialization function " \
80 "'" #name "'...\n"); \
82 mu_print(MU_ERROR, "%s:" #name ": initialization " \
83 "function failed (returned %d), " \
84 "skipping test suite...\n", \
85 mutest_suite_name, r); \
86 ++mutest_skipped_suites; \
90 #endif /* mu_run_init */
92 /* macro for running a single test case */
94 #define mu_run_case(name) \
96 mu_print(MU_CASE, "\t* Executing test case '" #name "'...\n");\
97 mutest_case_name = #name; \
100 if (mutest_case_failed) { \
101 ++mutest_failed_cases; \
102 mutest_suite_failed = 1; \
103 } else ++mutest_passed_cases; \
104 mutest_case_failed = 0; \
106 #endif /* mu_run_case */
108 /* macro for running a single termination function */
110 #define mu_run_term(name) \
112 mu_print(MU_CASE, "\t- Executing termination function '" \
117 #endif /* mu_run_term */
120 * mutest exported variables for internal use, do not use directly unless you
121 * know what you're doing.
123 extern const char* mutest_suite_name;
124 extern int mutest_failed_suites;
125 extern int mutest_passed_suites;
126 extern int mutest_skipped_suites;
127 extern int mutest_suite_failed;
129 extern const char* mutest_case_name;
130 extern int mutest_failed_cases;
131 extern int mutest_passed_cases;
132 extern int mutest_case_failed;
134 extern int mutest_failed_checks;
135 extern int mutest_passed_checks;
137 extern int mutest_verbose_level;