Commit 83600d6b7a5d0ff82f68b40934b24f978430acd2

Thomas de Grivel 2023-11-26T15:17:58

fix tests

diff --git a/ic3/.ic3_history b/ic3/.ic3_history
new file mode 100644
index 0000000..38a7a99
--- /dev/null
+++ b/ic3/.ic3_history
@@ -0,0 +1,3 @@
+a = (U8) { 1, 2, 3 }
+1
+a = (U8) { 1, 2, 3 }
diff --git a/libc3/array.c b/libc3/array.c
index 0550bb5..ef6d8f1 100644
--- a/libc3/array.c
+++ b/libc3/array.c
@@ -214,7 +214,7 @@ s_array * array_init_copy (s_array *a, const s_array *src)
   }
 #endif
   tmp.dimension = src->dimension;
-  if (! (tmp.dimensions = calloc(src->dimension,
+  if (! (tmp.dimensions = calloc(tmp.dimension,
                                  sizeof(s_array_dimension)))) {
     assert(! "array_init_copy: out of memory: dimensions");
     warnx("array_init_copy: out of memory: dimensions");
@@ -234,7 +234,7 @@ s_array * array_init_copy (s_array *a, const s_array *src)
     i = 0;
     item_size = src->dimensions[src->dimension - 1].item_size;
     while (i < src->count) {
-      if (init_copy(data_src, data_a) != data_a) {
+      if (init_copy(data_a, data_src) != data_a) {
         return NULL;
       }
       data_a += item_size;
diff --git a/libc3/buf.c b/libc3/buf.c
index 8009e5d..bf7526a 100644
--- a/libc3/buf.c
+++ b/libc3/buf.c
@@ -800,6 +800,7 @@ sw buf_u8_to_hex (s_buf *buf, const u8 *x)
     goto restore;
   result += r;
   r = result;
+  goto clean;
  restore:
   buf_save_restore_wpos(buf, &save);
  clean:
diff --git a/libc3/configure b/libc3/configure
index 6b8d613..ddd324c 100755
--- a/libc3/configure
+++ b/libc3/configure
@@ -37,7 +37,7 @@ OBJECTS_DEBUG="$(c2ext .debug.lo "$LO_SOURCES")"
 
 # Common config for all targets
 CPPFLAGS="-I../libffi/include $CPPFLAGS"
-CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
+CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic -fPIC"
 LDFLAGS="--shared -no-undefined ${LDFLAGS}"
 LIBS="${LIBS} -lm -pthread -rpath ${PREFIX}/lib"
 config_asan
diff --git a/libc3/facts.c b/libc3/facts.c
index 0860831..335a6da 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -29,9 +29,6 @@
 #include "set__tag.h"
 #include "skiplist__fact.h"
 #include "tag.h"
-/* debug */
-#include "env.h"
-#include "io.h"
 
 sw facts_open_file_create (s_facts *facts, const s_str *path);
 sw facts_open_log (s_facts *facts, s_buf *buf);
@@ -255,8 +252,6 @@ sw facts_load (s_facts *facts, s_buf *buf, const s_str *path)
       goto ko_fact;
     result += r;
     factp = fact_r(&fact);
-    buf_write_1(&g_c3_env.out, replace ? "replace " : "add ");
-    io_inspect_fact(factp);
     if (replace)
       facts_replace_fact(facts, factp);
     else
@@ -523,6 +518,7 @@ s_tag * facts_ref_tag (s_facts *facts, const s_tag *tag)
   assert(facts);
   assert(tag);
   item = set_add__tag(&facts->tags, tag);
+  assert(item);
   item->usage++;
   return &item->data;
 }
diff --git a/libc3/file.c b/libc3/file.c
index 1f53266..69abecb 100644
--- a/libc3/file.c
+++ b/libc3/file.c
@@ -132,7 +132,6 @@ s_str * file_search (const s_str *suffix, const s_sym *mode,
           (r = buf_write_str(&buf, suffix)) < 0)
         return NULL;
       buf_read_to_str(&buf, &tmp);
-      io_inspect_str(&tmp);
       file_access(&tmp, mode, &access);
       if (access) {
         *dest = tmp;
diff --git a/libc3/hash.c b/libc3/hash.c
index 064a88c..e060f2f 100644
--- a/libc3/hash.c
+++ b/libc3/hash.c
@@ -17,8 +17,6 @@
 #include "hash.h"
 #include "list.h"
 #include "str.h"
-/* debug */
-#include "io.h"
 
 #define HASH_UPDATE_DEF(type)                                          \
   void hash_update_##type (t_hash *hash, type x)                       \
@@ -134,8 +132,6 @@ void hash_update_fact (t_hash *hash, const s_fact *fact)
   assert(fact->subject);
   assert(fact->predicate);
   assert(fact->object);
-  io_puts("hash_update_fact");
-  io_inspect_fact(fact);
   hash_update(hash, type, sizeof(type));
   hash_update_tag(hash, fact->subject);
   hash_update_tag(hash, fact->predicate);
diff --git a/libc3/ident.c b/libc3/ident.c
index 2b6e8ff..eb98e86 100644
--- a/libc3/ident.c
+++ b/libc3/ident.c
@@ -43,6 +43,7 @@ bool ident_first_character_is_reserved (character c)
           character_is_uppercase(c) ||
           character_is_space(c) ||
           c == '"' ||
+          c == '\'' ||
           c == '(' ||
           c == ')' ||
           c == ':' ||
diff --git a/libc3/sym.c b/libc3/sym.c
index c567a05..447b0f2 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -99,7 +99,8 @@ bool sym_has_reserved_characters (const s_sym *sym)
   return false;
 }
 
-const s_sym ** sym_init_copy (const s_sym **sym, const s_sym **src)
+const s_sym ** sym_init_copy (const s_sym **sym,
+                              const s_sym * const *src)
 {
   assert(src);
   assert(sym);
diff --git a/libc3/sym.h b/libc3/sym.h
index 50041d2..348d88c 100644
--- a/libc3/sym.h
+++ b/libc3/sym.h
@@ -33,7 +33,8 @@ const s_sym * sym_1 (const s8 *p);
 
 bool sym_character_is_reserved (character c);
 
-const s_sym ** sym_init_copy (const s_sym **sym, const s_sym **src);
+const s_sym ** sym_init_copy (const s_sym **sym,
+                              const s_sym * const *src);
 
 /** @brief Call when exiting program. */
 void sym_delete_all (void);
diff --git a/libc3/tag.c b/libc3/tag.c
index 3a4bfc2..ef9af3e 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -252,7 +252,7 @@ s_tag * tag_init_copy (s_tag *tag, const s_tag *src)
 {
   assert(tag);
   assert(src);
-  switch (tag->type) {
+  switch (src->type) {
   case TAG_VAR:
     tag_init_var(tag);
     break;
diff --git a/test/buf_inspect_test.c b/test/buf_inspect_test.c
index 3598e71..473a31a 100644
--- a/test/buf_inspect_test.c
+++ b/test/buf_inspect_test.c
@@ -56,8 +56,9 @@
     test_context("buf_inspect_character(" # test ") -> " # expected);  \
     buf_init(&buf, false, sizeof(b), b);                               \
     tmp = (test);                                                      \
-    TEST_EQ(buf_inspect_character_size(&tmp), strlen(expected)); \
+    TEST_EQ(buf_inspect_character_size(&tmp), strlen(expected));       \
     TEST_EQ(buf_inspect_character(&buf, &tmp), strlen(expected));      \
+    TEST_EQ(buf.wpos, strlen(expected));                               \
     TEST_STRNCMP(buf.ptr.ps8, (expected), buf.wpos);                   \
     test_context(NULL);                                                \
   } while (0)
diff --git a/test/libc3_test.c b/test/libc3_test.c
index 077eedb..83b6889 100644
--- a/test/libc3_test.c
+++ b/test/libc3_test.c
@@ -42,7 +42,8 @@ void types_test (void);
 int main (int argc, char **argv)
 {
   test_init(argc, argv);
-  c3_init(NULL, argc, argv);
+  if (! c3_init(NULL, argc, argv))
+    return 1;
   if (test_target("types")) {
     fprintf(stderr, "\ntypes\n");
     types_test();
diff --git a/test/str_test.c b/test/str_test.c
index 630116e..86ffada 100644
--- a/test/str_test.c
+++ b/test/str_test.c
@@ -40,14 +40,15 @@
     test_context(NULL);                                                \
   } while (0)
 
-#define STR_TEST_TO_HEX(test, expected)                                  \
+#define STR_TEST_TO_HEX(test, expected)                                \
   do {                                                                 \
     s_str str;                                                         \
     s_str *test_;                                                      \
-    test_context("str_to_hex(" # test ") -> " # expected);               \
+    test_context("str_to_hex(" # test ") -> " # expected);             \
     test_ = (test);                                                    \
     TEST_EQ(str_to_hex(test_, &str), &str);                            \
-    TEST_STRNCMP(str.ptr.p, (expected), str.size);                       \
+    TEST_EQ(str.size, strlen(expected));                               \
+    TEST_STRNCMP(str.ptr.p, (expected), str.size);                     \
     str_clean(&str);                                                   \
     str_delete(test_);                                                 \
     test_context(NULL);                                                \