Commit b73296f519b18b27b5c17832b177ea9e09bfd9cb

Thomas de Grivel 2023-04-13T09:24:21

wip tests

diff --git a/test/test.c b/test/test.c
index 55045aa..4427bc5 100644
--- a/test/test.c
+++ b/test/test.c
@@ -21,6 +21,9 @@
 
 #define TEST_KO_MAX     10
 
+long         g_test_assert_count = 0;
+long         g_test_assert_ko = 0;
+long         g_test_assert_ok = 0;
 const char  *g_test_case_name = NULL;
 const char  *g_test_context = NULL;
 long         g_test_count = 0;
@@ -125,6 +128,8 @@ void test_init (int argc, char **argv)
 
 void test_ko ()
 {
+  g_test_assert_count++;
+  g_test_assert_ko++;
   g_test_count++;
   g_test_ko++;
   fprintf(stderr, "%sF%s", TEST_COLOR_KO, TEST_COLOR_RESET);
diff --git a/test/test.h b/test/test.h
index 76f1855..6dedd56 100644
--- a/test/test.h
+++ b/test/test.h
@@ -22,12 +22,14 @@
 #define TEST_ASSERT(test)                                              \
   do {                                                                 \
     if (test) {                                                        \
-      test_ok();                                                       \
+      g_test_assert_count++;                                           \
+      g_test_assert_ok++;                                              \
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
       printf("\nAssertion failed in %s:%d %s\n%s\n",                   \
              __FILE__, __LINE__, __func__, # test);                    \
+      return 1;                                                        \
     }                                                                  \
   } while(0)
 
@@ -37,6 +39,7 @@
     g_test_case_name = # name;                                         \
 
 #define TEST_CASE_END(name)                                            \
+    test_ok();                                                         \
     return 0;                                                          \
   }
 
@@ -50,7 +53,8 @@
   do {                                                                 \
     long long signed TEST_EQ_tmp = (long long signed) (test);          \
     if (TEST_EQ_tmp == (long long signed) (expected)) {                \
-      test_ok();                                                       \
+      g_test_assert_count++;                                           \
+      g_test_assert_ok++;                                              \
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
@@ -61,14 +65,18 @@
              __FILE__, __LINE__, __func__,                             \
              # test, # expected, # expected, TEST_EQ_tmp,              \
              TEST_COLOR_RESET);                                        \
+      return 1;                                                        \
     }                                                                  \
   } while (0)
 
 #define TEST_FLOAT_EQ(test, expected)                                  \
   do {                                                                 \
     float TEST_FLOAT_EQ_tmp = (float) (test);                          \
-    if (fabsf(TEST_FLOAT_EQ_tmp - (float) (expected)) <= FLT_EPSILON)  \
-      test_ok();                                                       \
+    if (fabsf(TEST_FLOAT_EQ_tmp - (float) (expected)) <=               \
+        FLT_EPSILON) {                                                 \
+      g_test_assert_count++;                                           \
+      g_test_assert_ok++;                                              \
+    }                                                                  \
     else {                                                             \
       test_ko();                                                       \
       printf("\n%sAssertion failed in %s:%d %s\n"                      \
@@ -78,6 +86,7 @@
              __FILE__, __LINE__, __func__,                             \
              # test, # expected, # expected, TEST_FLOAT_EQ_tmp,        \
              TEST_COLOR_RESET);                                        \
+      return 1;                                                        \
     }                                                                  \
   } while (0)
 
@@ -87,8 +96,10 @@
     if (fabsf(TEST_FLOAT_EQ2_tmp -                                     \
               (float) (expected1)) <= FLT_EPSILON ||                   \
         fabsf(TEST_FLOAT_EQ2_tmp -                                     \
-              (float) (expected2)) <= FLT_EPSILON)                     \
-      test_ok();                                                       \
+              (float) (expected2)) <= FLT_EPSILON) {                   \
+      g_test_assert_count++;                                           \
+      g_test_assert_ok++;                                              \
+    }                                                                  \
     else {                                                             \
       test_ko();                                                       \
       printf("\n%sAssertion failed in %s:%d %s\n"                      \
@@ -98,14 +109,17 @@
              __FILE__, __LINE__, __func__,                             \
              # test, # expected1, # expected1, TEST_FLOAT_EQ2_tmp,     \
              TEST_COLOR_RESET);                                        \
+      return 1;                                                        \
     }                                                                  \
   } while (0)
 
 #define TEST_DOUBLE_EQ(test, expected)                                 \
   do {                                                                 \
     f64 TEST_DOUBLE_EQ_tmp = (double) (test);                          \
-    if (fabs(TEST_DOUBLE_EQ_tmp - (expected)) <= DBL_EPSILON)          \
-      test_ok();                                                       \
+    if (fabs(TEST_DOUBLE_EQ_tmp - (expected)) <= DBL_EPSILON) {        \
+      g_test_assert_count++;                                           \
+      g_test_assert_ok++;                                              \
+    }                                                                  \
     else {                                                             \
       test_ko();                                                       \
       printf("\n%sAssertion failed in %s:%d %s\n"                      \
@@ -115,6 +129,7 @@
              __FILE__, __LINE__, __func__,                             \
              # test, # expected, # expected, TEST_DOUBLE_EQ_tmp,       \
              TEST_COLOR_RESET);                                        \
+      return 1;                                                        \
     }                                                                  \
   } while (0)
 
@@ -122,7 +137,8 @@
   do {                                                                 \
     sw TEST_STR_COMPARE_tmp = str_compare(a, b);                       \
     if (TEST_STR_COMPARE_tmp == expected) {                            \
-      test_ok();                                                       \
+      g_test_assert_count++;                                           \
+      g_test_assert_ok++;                                              \
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
@@ -133,6 +149,7 @@
              __FILE__, __LINE__, __func__,                             \
              # a, # b, # expected, # expected, TEST_STR_COMPARE_tmp,   \
              TEST_COLOR_RESET);                                        \
+      return 1;                                                        \
     }                                                                  \
   } while (0)
 
@@ -140,7 +157,8 @@
   do {                                                                 \
     const char *TEST_STRNCMP_tmp = (test);                             \
     if (strncmp(TEST_STRNCMP_tmp, (result), (bytes)) == 0) {           \
-      test_ok();                                                       \
+      g_test_assert_count++;                                           \
+      g_test_assert_ok++;                                              \
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
@@ -153,15 +171,19 @@
              # result);                                                \
       fwrite(TEST_STRNCMP_tmp, (bytes), 1, stdout);                    \
       printf("\".%s\n", TEST_COLOR_RESET);                             \
+      return 1;                                                        \
     }                                                                  \
   } while (0)
 
+extern long         g_test_assert_count;
+extern long         g_test_assert_ko;
+extern long         g_test_assert_ok;
+extern const char  *g_test_case_name;
 extern long         g_test_count;
 extern long         g_test_ko;
 extern long         g_test_last_ok;
 extern long         g_test_ok;
 extern const char **g_test_targets;
-extern const char  *g_test_case_name;
 
 void test_clean ();
 void test_context (const char *context);