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 test case */
75 #define mu_run_case(name) \
77 mu_print(MU_CASE, "\t- executing test case \"" #name "\"\n"); \
79 mutest_case_name = #name; \
81 if (mutest_case_failed) { \
82 ++mutest_failed_cases; \
83 mutest_suite_failed = 1; \
84 } else ++mutest_passed_cases; \
85 mutest_case_failed = 0; \
87 #endif /* mu_run_case */
90 * mutest exported variables for internal use, do not use directly unless you
91 * know what you're doing.
93 extern const char* mutest_suite_name;
94 extern int mutest_failed_suites;
95 extern int mutest_passed_suites;
96 extern int mutest_suite_failed;
98 extern const char* mutest_case_name;
99 extern int mutest_failed_cases;
100 extern int mutest_passed_cases;
101 extern int mutest_case_failed;
103 extern int mutest_failed_checks;
104 extern int mutest_passed_checks;
106 extern int mutest_verbose_level;