Commit d4f112dca9106be7f19c440d30aa1167e89d5a77

Thomas de Grivel 2023-07-30T21:49:52

printf -> fprintf(stderr,

diff --git a/test/test.c b/test/test.c
index 4427bc5..bf606d0 100644
--- a/test/test.c
+++ b/test/test.c
@@ -71,10 +71,10 @@ int test_file_compare (const char *path_a, const char *path_b)
   }
   /* never reached */
  ko:
-  printf("\n%sFiles %s and %s differ line %u.%s",
-         TEST_COLOR_KO,
-         path_a, path_b, lineno,
-         TEST_COLOR_RESET);
+  fprintf(stderr, "\n%sFiles %s and %s differ line %u.%s",
+          TEST_COLOR_KO,
+          path_a, path_b, lineno,
+          TEST_COLOR_RESET);
   test_ko();
   return 1;
  ok:
@@ -134,11 +134,11 @@ void test_ko ()
   g_test_ko++;
   fprintf(stderr, "%sF%s", TEST_COLOR_KO, TEST_COLOR_RESET);
   if (g_test_context)
-    printf("\n%s%s%s", TEST_COLOR_KO, g_test_context,
-           TEST_COLOR_RESET);
+    fprintf(stderr, "\n%s%s%s", TEST_COLOR_KO, g_test_context,
+            TEST_COLOR_RESET);
   g_test_last_ok = 0;
   if (g_test_ko >= TEST_KO_MAX) {
-    printf("\nMaximum number of errors reached, exiting.\n");
+    fprintf(stderr, "\nMaximum number of errors reached, exiting.\n");
     exit(1);
   }
 }
diff --git a/test/test.h b/test/test.h
index 6dedd56..6fdd85d 100644
--- a/test/test.h
+++ b/test/test.h
@@ -27,8 +27,8 @@
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
-      printf("\nAssertion failed in %s:%d %s\n%s\n",                   \
-             __FILE__, __LINE__, __func__, # test);                    \
+      fprintf(stderr, "\nAssertion failed in %s:%d %s\n%s\n",          \
+              __FILE__, __LINE__, __func__, # test);                   \
       return 1;                                                        \
     }                                                                  \
   } while(0)
@@ -58,13 +58,13 @@
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
-      printf("\n%sAssertion failed in %s:%d %s\n"                      \
-             "%s == %s\n"                                              \
-             "Expected %s got %lld.%s\n",                              \
-             TEST_COLOR_KO,                                            \
-             __FILE__, __LINE__, __func__,                             \
-             # test, # expected, # expected, TEST_EQ_tmp,              \
-             TEST_COLOR_RESET);                                        \
+      fprintf(stderr, "\n%sAssertion failed in %s:%d %s\n"             \
+              "%s == %s\n"                                             \
+              "Expected %s got %lld.%s\n",                             \
+              TEST_COLOR_KO,                                           \
+              __FILE__, __LINE__, __func__,                            \
+              # test, # expected, # expected, TEST_EQ_tmp,             \
+              TEST_COLOR_RESET);                                       \
       return 1;                                                        \
     }                                                                  \
   } while (0)
@@ -79,13 +79,13 @@
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
-      printf("\n%sAssertion failed in %s:%d %s\n"                      \
-             "%s == %s\n"                                              \
-             "Expected %s got %.16g.%s\n",                             \
-             TEST_COLOR_KO,                                            \
-             __FILE__, __LINE__, __func__,                             \
-             # test, # expected, # expected, TEST_FLOAT_EQ_tmp,        \
-             TEST_COLOR_RESET);                                        \
+      fprintf(stderr, "\n%sAssertion failed in %s:%d %s\n"             \
+              "%s == %s\n"                                             \
+              "Expected %s got %.16g.%s\n",                            \
+              TEST_COLOR_KO,                                           \
+              __FILE__, __LINE__, __func__,                            \
+              # test, # expected, # expected, TEST_FLOAT_EQ_tmp,       \
+              TEST_COLOR_RESET);                                       \
       return 1;                                                        \
     }                                                                  \
   } while (0)
@@ -102,13 +102,13 @@
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
-      printf("\n%sAssertion failed in %s:%d %s\n"                      \
-             "%s == %s\n"                                              \
-             "Expected %s got %.16g.%s\n",                             \
-             TEST_COLOR_KO,                                            \
-             __FILE__, __LINE__, __func__,                             \
-             # test, # expected1, # expected1, TEST_FLOAT_EQ2_tmp,     \
-             TEST_COLOR_RESET);                                        \
+      fprintf(stderr, "\n%sAssertion failed in %s:%d %s\n"             \
+              "%s == %s\n"                                             \
+              "Expected %s got %.16g.%s\n",                            \
+              TEST_COLOR_KO,                                           \
+              __FILE__, __LINE__, __func__,                            \
+              # test, # expected1, # expected1, TEST_FLOAT_EQ2_tmp,    \
+              TEST_COLOR_RESET);                                       \
       return 1;                                                        \
     }                                                                  \
   } while (0)
@@ -122,13 +122,13 @@
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
-      printf("\n%sAssertion failed in %s:%d %s\n"                      \
-             "%s == %s\n"                                              \
-             "Expected %s got %lf.%s\n",                               \
-             TEST_COLOR_KO,                                            \
-             __FILE__, __LINE__, __func__,                             \
-             # test, # expected, # expected, TEST_DOUBLE_EQ_tmp,       \
-             TEST_COLOR_RESET);                                        \
+      fprintf(stderr, "\n%sAssertion failed in %s:%d %s\n"             \
+              "%s == %s\n"                                             \
+              "Expected %s got %lf.%s\n",                              \
+              TEST_COLOR_KO,                                           \
+              __FILE__, __LINE__, __func__,                            \
+              # test, # expected, # expected, TEST_DOUBLE_EQ_tmp,      \
+              TEST_COLOR_RESET);                                       \
       return 1;                                                        \
     }                                                                  \
   } while (0)
@@ -142,13 +142,13 @@
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
-      printf("\n%sAssertion failed in %s:%d %s\n"                      \
-             "str_compare(%s, %s) == %s\n"                             \
-             "Expected %s got %ld.%s\n",                               \
-             TEST_COLOR_KO,                                            \
-             __FILE__, __LINE__, __func__,                             \
-             # a, # b, # expected, # expected, TEST_STR_COMPARE_tmp,   \
-             TEST_COLOR_RESET);                                        \
+      fprintf(stderr, "\n%sAssertion failed in %s:%d %s\n"             \
+              "str_compare(%s, %s) == %s\n"                            \
+              "Expected %s got %ld.%s\n",                              \
+              TEST_COLOR_KO,                                           \
+              __FILE__, __LINE__, __func__,                            \
+              # a, # b, # expected, # expected, TEST_STR_COMPARE_tmp,  \
+              TEST_COLOR_RESET);                                       \
       return 1;                                                        \
     }                                                                  \
   } while (0)
@@ -162,15 +162,15 @@
     }                                                                  \
     else {                                                             \
       test_ko();                                                       \
-      printf("\n%sAssertion failed in %s:%d %s\n"                      \
-             "strncmp(%s, %s, %ld) == 0\n",                            \
-             TEST_COLOR_KO,                                            \
-             __FILE__, __LINE__, __func__,                             \
-             # test, # result, (long) (bytes));                        \
-      printf("Expected %s got \"",                                     \
-             # result);                                                \
-      fwrite(TEST_STRNCMP_tmp, (bytes), 1, stdout);                    \
-      printf("\".%s\n", TEST_COLOR_RESET);                             \
+      fprintf(stderr, "\n%sAssertion failed in %s:%d %s\n"             \
+              "strncmp(%s, %s, %ld) == 0\n",                           \
+              TEST_COLOR_KO,                                           \
+              __FILE__, __LINE__, __func__,                            \
+              # test, # result, (long) (bytes));                       \
+      fprintf(stderr, "Expected %s got \"",                            \
+              # result);                                               \
+      fwrite(TEST_STRNCMP_tmp, (bytes), 1, stderr);                    \
+      fprintf(stderr, "\".%s\n", TEST_COLOR_RESET);                    \
       return 1;                                                        \
     }                                                                  \
   } while (0)