]> git.llucax.com Git - software/mutest.git/commitdiff
Reuse checking macros code
authorLeandro Lucarella <llucarella@integratech.com.ar>
Fri, 12 Dec 2008 18:23:50 +0000 (16:23 -0200)
committerLeandro Lucarella <llucax@gmail.com>
Fri, 12 Dec 2008 21:08:27 +0000 (19:08 -0200)
mutest.h

index c84eb1562c49b924ca763ef5424ae9175694c23b..2fd200458858536e3d4581f4d69b086230ce69d8 100644 (file)
--- a/mutest.h
+++ b/mutest.h
@@ -41,37 +41,37 @@ enum {
                } \
        } while (0)
 
                } \
        } 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 */
 /* 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 { \
        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 { \
                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)
 
                } \
        } 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
  */
 /*
  * 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 */
 
 
 #ifndef MUTEST_PY /* we are using the C implementation */