Commit 681fed09ea6c24fc8d18d4f0eaabb23ed19681a2

Thomas de Grivel 2023-12-11T20:43:06

fix assert.h

diff --git a/libc3/assert.h b/libc3/assert.h
index 55c8f93..8a419a0 100644
--- a/libc3/assert.h
+++ b/libc3/assert.h
@@ -13,17 +13,22 @@
 #ifndef LIBC3_ASSERT_H
 #define LIBC3_ASSERT_H
 
-#include "types.h"
+#include "env.h"
 #include "io.h"
 
 #ifdef DEBUG
 # define assert(test)                                                  \
   do {                                                                 \
+    sw assert_line = __LINE__;                                         \
     if (! (test)) {                                                    \
+      if (g_c3_env.argv && g_c3_env.argv[0]) {                         \
+        err_write_1(g_c3_env.argv[0]);                                 \
+        err_write_1(": ");                                             \
+      }                                                                \
       err_write_1("assertion failed: ");                               \
       err_write_1(__FILE__);                                           \
       err_write_1(":");                                                \
-      err_write_1(__LINE__);                                           \
+      err_inspect_sw(&assert_line);                                    \
       err_write_1(": ");                                               \
       err_write_1(__func__);                                           \
       err_write_1(": ");                                               \
diff --git a/libc3/io.c b/libc3/io.c
index 2139674..41b6eb7 100644
--- a/libc3/io.c
+++ b/libc3/io.c
@@ -19,30 +19,22 @@
   sw err_inspect_ ## name (type x)                                     \
   {                                                                    \
     sw r;                                                              \
-    sw result = 0;                                                     \
-    if ((r = buf_inspect_ ## name(&g_c3_env.err, x)) < 0)              \
+    r = buf_inspect_ ## name(&g_c3_env.err, x);                        \
+    if (r < 0)                                                         \
       return r;                                                        \
-    result += r;                                                       \
-    if ((r = buf_write_u8(&g_c3_env.err, '\n')) < 0)                   \
-      return r;                                                        \
-    result += r;                                                       \
     buf_flush(&g_c3_env.err);                                          \
-    return result;                                                     \
+    return r;                                                          \
   }
 
 #define DEF_IO_INSPECT(name, type)                                     \
   sw io_inspect_ ## name (type x)                                      \
   {                                                                    \
     sw r;                                                              \
-    sw result = 0;                                                     \
-    if ((r = buf_inspect_ ## name(&g_c3_env.out, x)) < 0)              \
-      return r;                                                        \
-    result += r;                                                       \
-    if ((r = buf_write_u8(&g_c3_env.out, '\n')) < 0)                   \
+    r = buf_inspect_ ## name(&g_c3_env.out, x);                        \
+    if (r < 0)                                                         \
       return r;                                                        \
-    result += r;                                                       \
     buf_flush(&g_c3_env.out);                                          \
-    return result;                                                     \
+    return r;                                                          \
   }
 
 #define DEF_ERR_IO_INSPECT(name, type)                                 \
diff --git a/test/call_test.c b/test/call_test.c
index 7089e3d..218d689 100644
--- a/test/call_test.c
+++ b/test/call_test.c
@@ -27,7 +27,7 @@
   do {                                                                 \
     s_call call;                                                       \
     s_str result;                                                      \
-    call_init_1(&call, (test));                                        \
+    TEST_EQ(call_init_1(&call, (test)), &call);                        \
     TEST_EQ(call_inspect(&call, &result), &result);                    \
     TEST_STRNCMP(result.ptr.p, (test), result.size);                   \
     TEST_EQ(result.size, strlen(test));                                \