From: Leandro Lucarella Date: Fri, 12 Dec 2008 18:23:50 +0000 (-0200) Subject: Reuse checking macros code X-Git-Tag: 1.0~7 X-Git-Url: https://git.llucax.com/software/mutest.git/commitdiff_plain/5b3a1f1593fc57a4dd5b492f9b4cd55e28cb6eaa?ds=inline Reuse checking macros code --- diff --git a/mutest.h b/mutest.h index c84eb15..2fd2004 100644 --- a/mutest.h +++ b/mutest.h @@ -41,37 +41,37 @@ enum { } \ } while (0) +/* print an error message */ +#define mu_printerr(name, action) \ + mu_print(MU_ERROR, __FILE__ ":%d: " name " failed, "\ + action " test case\n", __LINE__); + +/* modify the internal state so a failure gets counted */ +#define mutest_count_err ++mutest_failed_checks; mutest_case_failed = 1; + +/* modify the internal state so a success gets counted */ +#define mutest_count_suc ++mutest_passed_checks; + /* check that an expression evaluates to true, continue if the check fails */ -#define mu_check(exp) \ +#define mu_check_base(exp, name, action, final) \ do { \ - mu_print(MU_CHECK, "\t\t* Checking mu_check(%s)...\n", #exp); \ - if (exp) ++mutest_passed_checks; \ + mu_print(MU_CHECK, "\t\t* Checking " name "(" #exp ")...\n"); \ + if (exp) mutest_count_suc \ else { \ - ++mutest_failed_checks; \ - mutest_case_failed = 1; \ - mu_print(MU_ERROR, "%s:%d: mu_check(%s) failed, " \ - "resuming test case\n", __FILE__, \ - __LINE__, #exp); \ + mutest_count_err \ + mu_printerr(name "(" #exp ")", action); \ + final; \ } \ } while (0) +/* check that an expression evaluates to true, continue if the check fails */ +#define mu_check(exp) mu_check_base(exp, "mu_check", "resuming", continue) + /* * ensure that an expression evaluates to true, abort the current test * case if the check fails */ -#define mu_ensure(exp) \ - do { \ - mu_print(MU_CHECK, "\t\t* Checking mu_ensure(%s)...\n", #exp);\ - if (exp) ++mutest_passed_checks; \ - else { \ - ++mutest_failed_checks; \ - mutest_case_failed = 1; \ - mu_print(MU_ERROR, "%s:%d: mu_ensure(%s) failed, " \ - "aborting test case\n", __FILE__, \ - __LINE__, #exp); \ - return; \ - } \ - } while (0) +#define mu_ensure(exp) mu_check_base(exp, "mu_ensure", "aborting", return) #ifndef MUTEST_PY /* we are using the C implementation */