浏览代码

Modify unit test, so a breakpoint can be set into ASSERT

bel 10 年之前
父节点
当前提交
d6df859085
共有 1 个文件被更改,包括 10 次插入8 次删除
  1. 10 8
      test/unit_test.c

+ 10 - 8
test/unit_test.c

@@ -39,20 +39,22 @@
 static int s_total_tests = 0;
 static int s_failed_tests = 0;
 
-#define FAIL(str, line) do {                     \
-    printf("Fail on line %d: [%s]\n", line, str);   \
-    s_failed_tests++; \
-} while (0)
+void check_func(int condition, const char * cond_txt, unsigned line)
+{
+    ++s_total_tests;
+    if (!condition) {
+        printf("Fail on line %d: [%s]\n", line, cond_txt);
+        ++s_failed_tests;
+    }
+}
 
 #define ASSERT(expr) do { \
-    s_total_tests++; \
-    if (!(expr)) FAIL(#expr, __LINE__); \
+   check_func(expr, #expr, __LINE__); \
 } while (0)
 
 #define REQUIRE(expr) do { \
-    s_total_tests++; \
+   check_func(expr, #expr, __LINE__); \
     if (!(expr)) { \
-        FAIL(#expr, __LINE__); \
         exit(EXIT_FAILURE); \
     } \
 } while (0)