{"thread":{"id":"62816","subject":"[PATCH 0/4] t/unit-tests: convert unit-tests to use clar","startedAt":"2025-01-16T10:49:20Z","lastAt":"2025-01-20T10:22:09Z","messageCount":24,"participants":["Seyi Kuforiji","Patrick Steinhardt","Junio C Hamano","Karthik Nayak"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"510679","messageId":"20250116104911.77405-1-kuforiji98@gmail.com","threadId":"62816","inReplyTo":null,"subject":"[PATCH 0/4] t/unit-tests: convert unit-tests to use clar","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-16T10:49:07Z","receivedAt":"2025-01-16T10:49:20Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Hello,\n\nThis small patch series transitions the existing unit test files to the\nClar testing framework. This change is part of our ongoing effort to\nstandardize our testing approach and enhance maintainability.\n\nThanks\nSeyi\n\nMentored-by: Patrick Steinhardt ps@pks.im\nSigned-off-by: Seyi Kuforiji kuforiji98@gmail.com\n\nSeyi Kuforiji (4):\n  t/unit-tests: handle dashes in test suite filenames\n  t/unit-tests: convert mem-pool test to use clar test framework\n  t/unit-tests: adapt priority queue test to use clar test framework\n  t/unit-tests: convert reftable tree test to use clar test framework\n\n Makefile                            |  6 +-\n t/meson.build                       |  6 +-\n t/unit-tests/generate-clar-decls.sh |  1 +\n t/unit-tests/t-mem-pool.c           | 31 ----------\n t/unit-tests/t-prio-queue.c         | 91 ----------------------------\n t/unit-tests/t-reftable-tree.c      | 86 --------------------------\n t/unit-tests/u-mem-pool.c           | 26 ++++++++\n t/unit-tests/u-prio-queue.c         | 94 +++++++++++++++++++++++++++++\n t/unit-tests/u-reftable-tree.c      | 78 ++++++++++++++++++++++++\n 9 files changed, 205 insertions(+), 214 deletions(-)\n delete mode 100644 t/unit-tests/t-mem-pool.c\n delete mode 100644 t/unit-tests/t-prio-queue.c\n delete mode 100644 t/unit-tests/t-reftable-tree.c\n create mode 100644 t/unit-tests/u-mem-pool.c\n create mode 100644 t/unit-tests/u-prio-queue.c\n create mode 100644 t/unit-tests/u-reftable-tree.c\n\n-- \n2.34.1\n\n"},{"id":"510680","messageId":"20250116104911.77405-2-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250116104911.77405-1-kuforiji98@gmail.com","subject":"[PATCH 1/4] t/unit-tests: handle dashes in test suite filenames","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-16T10:49:08Z","receivedAt":"2025-01-16T10:49:24Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Adapt script to translate dashes (`-`) in test suite filenames to\nunderscores (`_`) to ensure proper extraction of test function names.\n`generate-clar-decls.sh` does not pick up dashes in filenames such as\n`u-mem-pool.c`, which prevents the scripts from being run. This will be\nused by subsequent commits which follows the same construct.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n t/unit-tests/generate-clar-decls.sh | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/t/unit-tests/generate-clar-decls.sh b/t/unit-tests/generate-clar-decls.sh\nindex 3b315c64b3..abf6a2ea2a 100755\n--- a/t/unit-tests/generate-clar-decls.sh\n+++ b/t/unit-tests/generate-clar-decls.sh\n@@ -14,6 +14,7 @@ do\n \tsuite_name=$(basename \"$suite\")\n \tsuite_name=${suite_name%.c}\n \tsuite_name=${suite_name#u-}\n+\tsuite_name=$(echo \"$suite_name\" | tr '-' '_')\n \tsed -ne \"s/^\\(void test_${suite_name}__[a-zA-Z_0-9][a-zA-Z_0-9]*(void)\\)$/extern \\1;/p\" \"$suite\" ||\n \texit 1\n done >\"$OUTPUT\"\n-- \n2.34.1\n\n"},{"id":"510681","messageId":"20250116104911.77405-3-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250116104911.77405-1-kuforiji98@gmail.com","subject":"[PATCH 2/4] t/unit-tests: convert mem-pool test to use clar test framework","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-16T10:49:09Z","receivedAt":"2025-01-16T10:49:29Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Adapt the mem-pool test script to use clar framework by using clar\nassertions where necessary. Following the consensus to convert the\nunit-tests scripts found in the t/unit-tests folder to clar driven by\nPatrick Steinhardt. Test functions are created as a standalone to test\ndifferent test cases.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                  |  2 +-\n t/meson.build             |  2 +-\n t/unit-tests/t-mem-pool.c | 31 -------------------------------\n t/unit-tests/u-mem-pool.c | 26 ++++++++++++++++++++++++++\n 4 files changed, 28 insertions(+), 33 deletions(-)\n delete mode 100644 t/unit-tests/t-mem-pool.c\n create mode 100644 t/unit-tests/u-mem-pool.c\n\ndiff --git a/Makefile b/Makefile\nindex 97e8385b66..49ada4169d 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1338,6 +1338,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/%\n THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%\n \n CLAR_TEST_SUITES += u-ctype\n+CLAR_TEST_SUITES += u-mem-pool\n CLAR_TEST_SUITES += u-strvec\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n@@ -1347,7 +1348,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o\n UNIT_TEST_PROGRAMS += t-example-decorate\n UNIT_TEST_PROGRAMS += t-hash\n UNIT_TEST_PROGRAMS += t-hashmap\n-UNIT_TEST_PROGRAMS += t-mem-pool\n UNIT_TEST_PROGRAMS += t-oid-array\n UNIT_TEST_PROGRAMS += t-oidmap\n UNIT_TEST_PROGRAMS += t-oidtree\ndiff --git a/t/meson.build b/t/meson.build\nindex 602ebfe6a2..ffe951f9be 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -1,5 +1,6 @@\n clar_test_suites = [\n   'unit-tests/u-ctype.c',\n+  'unit-tests/u-mem-pool.c',\n   'unit-tests/u-strvec.c',\n ]\n \n@@ -43,7 +44,6 @@ unit_test_programs = [\n   'unit-tests/t-example-decorate.c',\n   'unit-tests/t-hash.c',\n   'unit-tests/t-hashmap.c',\n-  'unit-tests/t-mem-pool.c',\n   'unit-tests/t-oid-array.c',\n   'unit-tests/t-oidmap.c',\n   'unit-tests/t-oidtree.c',\ndiff --git a/t/unit-tests/t-mem-pool.c b/t/unit-tests/t-mem-pool.c\ndeleted file mode 100644\nindex fe500c704b..0000000000\n--- a/t/unit-tests/t-mem-pool.c\n+++ /dev/null\n@@ -1,31 +0,0 @@\n-#include \"test-lib.h\"\n-#include \"mem-pool.h\"\n-\n-static void setup_static(void (*f)(struct mem_pool *), size_t block_alloc)\n-{\n-\tstruct mem_pool pool = { .block_alloc = block_alloc };\n-\tf(&pool);\n-\tmem_pool_discard(&pool, 0);\n-}\n-\n-static void t_calloc_100(struct mem_pool *pool)\n-{\n-\tsize_t size = 100;\n-\tchar *buffer = mem_pool_calloc(pool, 1, size);\n-\tfor (size_t i = 0; i < size; i++)\n-\t\tcheck_int(buffer[i], ==, 0);\n-\tif (!check(pool->mp_block != NULL))\n-\t\treturn;\n-\tcheck(pool->mp_block->next_free != NULL);\n-\tcheck(pool->mp_block->end != NULL);\n-}\n-\n-int cmd_main(int argc UNUSED, const char **argv UNUSED)\n-{\n-\tTEST(setup_static(t_calloc_100, 1024 * 1024),\n-\t     \"mem_pool_calloc returns 100 zeroed bytes with big block\");\n-\tTEST(setup_static(t_calloc_100, 1),\n-\t     \"mem_pool_calloc returns 100 zeroed bytes with tiny block\");\n-\n-\treturn test_done();\n-}\ndiff --git a/t/unit-tests/u-mem-pool.c b/t/unit-tests/u-mem-pool.c\nnew file mode 100644\nindex 0000000000..36e31a3201\n--- /dev/null\n+++ b/t/unit-tests/u-mem-pool.c\n@@ -0,0 +1,26 @@\n+#include \"unit-test.h\"\n+#include \"mem-pool.h\"\n+\n+static void t_calloc_100(size_t block_alloc)\n+{\n+\tstruct mem_pool pool = { .block_alloc = block_alloc };\n+\tsize_t size = 100;\n+\tchar *buffer = mem_pool_calloc(&pool, 1, size);\n+\tfor (size_t i = 0; i < size; i++)\n+\t\tcl_assert_equal_i(0, buffer[i]);\n+\tcl_assert(pool.mp_block != NULL);\n+\tcl_assert(pool.mp_block->next_free != NULL);\n+\tcl_assert(pool.mp_block->end != NULL);\n+\tmem_pool_discard(&pool, 0);\n+}\n+\n+void test_mem_pool__big_block(void)\n+{\n+\tt_calloc_100(1024 * 1024);\n+\n+}\n+\n+void test_mem_pool__tiny_block(void)\n+{\n+\tt_calloc_100(1);\n+}\n-- \n2.34.1\n\n"},{"id":"510682","messageId":"20250116104911.77405-4-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250116104911.77405-1-kuforiji98@gmail.com","subject":"[PATCH 3/4] t/unit-tests: adapt priority queue test to use clar test framework","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-16T10:49:10Z","receivedAt":"2025-01-16T10:49:33Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Convert the prio-queue test script to clar framework by using clar\nassertions where necessary. Following the consensus to convert the\nunit-tests scripts found in the t/unit-tests folder to clar driven by\nPatrick Steinhardt. Test functions are created as a standalone to test\ndifferent cases.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                    |  2 +-\n t/meson.build               |  2 +-\n t/unit-tests/t-prio-queue.c | 91 -----------------------------------\n t/unit-tests/u-prio-queue.c | 94 +++++++++++++++++++++++++++++++++++++\n 4 files changed, 96 insertions(+), 93 deletions(-)\n delete mode 100644 t/unit-tests/t-prio-queue.c\n create mode 100644 t/unit-tests/u-prio-queue.c\n\ndiff --git a/Makefile b/Makefile\nindex 49ada4169d..049f857512 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1339,6 +1339,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%\n \n CLAR_TEST_SUITES += u-ctype\n CLAR_TEST_SUITES += u-mem-pool\n+CLAR_TEST_SUITES += u-prio-queue\n CLAR_TEST_SUITES += u-strvec\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n@@ -1351,7 +1352,6 @@ UNIT_TEST_PROGRAMS += t-hashmap\n UNIT_TEST_PROGRAMS += t-oid-array\n UNIT_TEST_PROGRAMS += t-oidmap\n UNIT_TEST_PROGRAMS += t-oidtree\n-UNIT_TEST_PROGRAMS += t-prio-queue\n UNIT_TEST_PROGRAMS += t-reftable-basics\n UNIT_TEST_PROGRAMS += t-reftable-block\n UNIT_TEST_PROGRAMS += t-reftable-merged\ndiff --git a/t/meson.build b/t/meson.build\nindex ffe951f9be..09232967cd 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -1,6 +1,7 @@\n clar_test_suites = [\n   'unit-tests/u-ctype.c',\n   'unit-tests/u-mem-pool.c',\n+  'unit-tests/u-prio-queue.c',\n   'unit-tests/u-strvec.c',\n ]\n \n@@ -47,7 +48,6 @@ unit_test_programs = [\n   'unit-tests/t-oid-array.c',\n   'unit-tests/t-oidmap.c',\n   'unit-tests/t-oidtree.c',\n-  'unit-tests/t-prio-queue.c',\n   'unit-tests/t-reftable-basics.c',\n   'unit-tests/t-reftable-block.c',\n   'unit-tests/t-reftable-merged.c',\ndiff --git a/t/unit-tests/t-prio-queue.c b/t/unit-tests/t-prio-queue.c\ndeleted file mode 100644\nindex a053635000..0000000000\n--- a/t/unit-tests/t-prio-queue.c\n+++ /dev/null\n@@ -1,91 +0,0 @@\n-#include \"test-lib.h\"\n-#include \"prio-queue.h\"\n-\n-static int intcmp(const void *va, const void *vb, void *data UNUSED)\n-{\n-\tconst int *a = va, *b = vb;\n-\treturn *a - *b;\n-}\n-\n-\n-#define MISSING  -1\n-#define DUMP\t -2\n-#define STACK\t -3\n-#define GET\t -4\n-#define REVERSE  -5\n-\n-static int show(int *v)\n-{\n-\treturn v ? *v : MISSING;\n-}\n-\n-static void test_prio_queue(int *input, size_t input_size,\n-\t\t\t    int *result, size_t result_size)\n-{\n-\tstruct prio_queue pq = { intcmp };\n-\tint j = 0;\n-\n-\tfor (size_t i = 0; i < input_size; i++) {\n-\t\tvoid *peek, *get;\n-\t\tswitch(input[i]) {\n-\t\tcase GET:\n-\t\t\tpeek = prio_queue_peek(&pq);\n-\t\t\tget = prio_queue_get(&pq);\n-\t\t\tif (!check(peek == get))\n-\t\t\t\treturn;\n-\t\t\tif (!check_uint(j, <, result_size))\n-\t\t\t\tbreak;\n-\t\t\tif (!check_int(result[j], ==, show(get)))\n-\t\t\t\ttest_msg(\"      j: %d\", j);\n-\t\t\tj++;\n-\t\t\tbreak;\n-\t\tcase DUMP:\n-\t\t\twhile ((peek = prio_queue_peek(&pq))) {\n-\t\t\t\tget = prio_queue_get(&pq);\n-\t\t\t\tif (!check(peek == get))\n-\t\t\t\t\treturn;\n-\t\t\t\tif (!check_uint(j, <, result_size))\n-\t\t\t\t\tbreak;\n-\t\t\t\tif (!check_int(result[j], ==, show(get)))\n-\t\t\t\t\ttest_msg(\"      j: %d\", j);\n-\t\t\t\tj++;\n-\t\t\t}\n-\t\t\tbreak;\n-\t\tcase STACK:\n-\t\t\tpq.compare = NULL;\n-\t\t\tbreak;\n-\t\tcase REVERSE:\n-\t\t\tprio_queue_reverse(&pq);\n-\t\t\tbreak;\n-\t\tdefault:\n-\t\t\tprio_queue_put(&pq, &input[i]);\n-\t\t\tbreak;\n-\t\t}\n-\t}\n-\tcheck_uint(j, ==, result_size);\n-\tclear_prio_queue(&pq);\n-}\n-\n-#define TEST_INPUT(input, result) \\\n-\ttest_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))\n-\n-int cmd_main(int argc UNUSED, const char **argv UNUSED)\n-{\n-\tTEST(TEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),\n-\t\t\t((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 })),\n-\t     \"prio-queue works for basic input\");\n-\tTEST(TEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }),\n-\t\t\t((int []){ 2, 3, 4, 1, 5, 6 })),\n-\t     \"prio-queue works for mixed put & get commands\");\n-\tTEST(TEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }),\n-\t\t\t((int []){ 1, 2, MISSING, 1, 2, MISSING })),\n-\t     \"prio-queue works when queue is empty\");\n-\tTEST(TEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),\n-\t\t\t((int []){ 3, 2, 6, 4, 5, 1, 8 })),\n-\t     \"prio-queue works when used as a LIFO stack\");\n-\tTEST(TEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),\n-\t\t\t((int []){ 1, 2, 3, 4, 5, 6 })),\n-\t     \"prio-queue works when LIFO stack is reversed\");\n-\n-\treturn test_done();\n-}\ndiff --git a/t/unit-tests/u-prio-queue.c b/t/unit-tests/u-prio-queue.c\nnew file mode 100644\nindex 0000000000..d36a565e6f\n--- /dev/null\n+++ b/t/unit-tests/u-prio-queue.c\n@@ -0,0 +1,94 @@\n+#include \"unit-test.h\"\n+#include \"prio-queue.h\"\n+\n+static int intcmp(const void *va, const void *vb, void *data UNUSED)\n+{\n+\tconst int *a = va, *b = vb;\n+\treturn *a - *b;\n+}\n+\n+\n+#define MISSING  -1\n+#define DUMP\t -2\n+#define STACK\t -3\n+#define GET\t -4\n+#define REVERSE  -5\n+\n+static int show(int *v)\n+{\n+\treturn v ? *v : MISSING;\n+}\n+\n+static void test_prio_queue(int *input, size_t input_size,\n+\t\t\t    int *result, size_t result_size)\n+{\n+\tstruct prio_queue pq = { intcmp };\n+\tsize_t j = 0;\n+\n+\tfor (size_t i = 0; i < input_size; i++) {\n+\t\tvoid *peek, *get;\n+\t\tswitch(input[i]) {\n+\t\tcase GET:\n+\t\t\tpeek = prio_queue_peek(&pq);\n+\t\t\tget = prio_queue_get(&pq);\n+\t\t\tcl_assert(peek == get);\n+\t\t\tcl_assert(j < result_size);\n+\t\t\tcl_assert_equal_i(result[j], show(get));\n+\t\t\tj++;\n+\t\t\tbreak;\n+\t\tcase DUMP:\n+\t\t\twhile ((peek = prio_queue_peek(&pq))) {\n+\t\t\t\tget = prio_queue_get(&pq);\n+\t\t\t\tcl_assert(peek == get);\n+\t\t\t\tcl_assert((size_t)j < result_size);\n+\t\t\t\tcl_assert_equal_i(result[j], show(get));\n+\t\t\t\tj++;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tcase STACK:\n+\t\t\tpq.compare = NULL;\n+\t\t\tbreak;\n+\t\tcase REVERSE:\n+\t\t\tprio_queue_reverse(&pq);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tprio_queue_put(&pq, &input[i]);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tcl_assert_equal_i(j, result_size);\n+\tclear_prio_queue(&pq);\n+}\n+\n+#define TEST_INPUT(input, result) \\\n+\ttest_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))\n+\n+void test_prio_queue__basic(void)\n+{\n+\tTEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),\n+\t\t   ((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 }));\n+}\n+\n+void test_prio_queue__mixed(void)\n+{\n+\tTEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }),\n+\t\t   ((int []){ 2, 3, 4, 1, 5, 6 }));\n+}\n+\n+void test_prio_queue__empty(void)\n+{\n+\tTEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }),\n+\t\t   ((int []){ 1, 2, MISSING, 1, 2, MISSING }));\n+}\n+\n+void test_prio_queue__stack(void)\n+{\n+\tTEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),\n+\t\t   ((int []){ 3, 2, 6, 4, 5, 1, 8 }));\n+}\n+\n+void test_prio_queue__reverse_stack(void)\n+{\n+\tTEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),\n+\t\t   ((int []){ 1, 2, 3, 4, 5, 6 }));\n+}\n-- \n2.34.1\n\n"},{"id":"510683","messageId":"20250116104911.77405-5-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250116104911.77405-1-kuforiji98@gmail.com","subject":"[PATCH 4/4] t/unit-tests: convert reftable tree test to use clar test framework","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-16T10:49:11Z","receivedAt":"2025-01-16T10:49:37Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Adapts reftable tree test script to clar framework by using clar\nassertions where necessary. Following the consensus to convert the\nunit-tests scripts found in the t/unit-tests folder to clar driven by\nPatrick Steinhardt.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                       |  2 +-\n t/meson.build                  |  2 +-\n t/unit-tests/t-reftable-tree.c | 86 ----------------------------------\n t/unit-tests/u-reftable-tree.c | 78 ++++++++++++++++++++++++++++++\n 4 files changed, 80 insertions(+), 88 deletions(-)\n delete mode 100644 t/unit-tests/t-reftable-tree.c\n create mode 100644 t/unit-tests/u-reftable-tree.c\n\ndiff --git a/Makefile b/Makefile\nindex 049f857512..75dbb8e25f 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1340,6 +1340,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%\n CLAR_TEST_SUITES += u-ctype\n CLAR_TEST_SUITES += u-mem-pool\n CLAR_TEST_SUITES += u-prio-queue\n+CLAR_TEST_SUITES += u-reftable-tree\n CLAR_TEST_SUITES += u-strvec\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n@@ -1360,7 +1361,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader\n UNIT_TEST_PROGRAMS += t-reftable-readwrite\n UNIT_TEST_PROGRAMS += t-reftable-record\n UNIT_TEST_PROGRAMS += t-reftable-stack\n-UNIT_TEST_PROGRAMS += t-reftable-tree\n UNIT_TEST_PROGRAMS += t-strbuf\n UNIT_TEST_PROGRAMS += t-strcmp-offset\n UNIT_TEST_PROGRAMS += t-trailer\ndiff --git a/t/meson.build b/t/meson.build\nindex 09232967cd..6dd41216ef 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -2,6 +2,7 @@ clar_test_suites = [\n   'unit-tests/u-ctype.c',\n   'unit-tests/u-mem-pool.c',\n   'unit-tests/u-prio-queue.c',\n+  'unit-tests/u-reftable-tree.c',\n   'unit-tests/u-strvec.c',\n ]\n \n@@ -56,7 +57,6 @@ unit_test_programs = [\n   'unit-tests/t-reftable-readwrite.c',\n   'unit-tests/t-reftable-record.c',\n   'unit-tests/t-reftable-stack.c',\n-  'unit-tests/t-reftable-tree.c',\n   'unit-tests/t-strbuf.c',\n   'unit-tests/t-strcmp-offset.c',\n   'unit-tests/t-trailer.c',\ndiff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c\ndeleted file mode 100644\nindex 79b175a45a..0000000000\n--- a/t/unit-tests/t-reftable-tree.c\n+++ /dev/null\n@@ -1,86 +0,0 @@\n-/*\n-Copyright 2020 Google LLC\n-\n-Use of this source code is governed by a BSD-style\n-license that can be found in the LICENSE file or at\n-https://developers.google.com/open-source/licenses/bsd\n-*/\n-\n-#include \"test-lib.h\"\n-#include \"reftable/tree.h\"\n-\n-static int t_compare(const void *a, const void *b)\n-{\n-\treturn (char *)a - (char *)b;\n-}\n-\n-struct curry {\n-\tvoid **arr;\n-\tsize_t len;\n-};\n-\n-static void store(void *arg, void *key)\n-{\n-\tstruct curry *c = arg;\n-\tc->arr[c->len++] = key;\n-}\n-\n-static void t_tree_search(void)\n-{\n-\tstruct tree_node *root = NULL;\n-\tvoid *values[11] = { 0 };\n-\tstruct tree_node *nodes[11] = { 0 };\n-\tsize_t i = 1;\n-\n-\t/*\n-\t * Pseudo-randomly insert the pointers for elements between\n-\t * values[1] and values[10] (inclusive) in the tree.\n-\t */\n-\tdo {\n-\t\tnodes[i] = tree_insert(&root, &values[i], &t_compare);\n-\t\tcheck(nodes[i] != NULL);\n-\t\ti = (i * 7) % 11;\n-\t} while (i != 1);\n-\n-\tfor (i = 1; i < ARRAY_SIZE(nodes); i++) {\n-\t\tcheck_pointer_eq(&values[i], nodes[i]->key);\n-\t\tcheck_pointer_eq(nodes[i], tree_search(root, &values[i], &t_compare));\n-\t}\n-\n-\tcheck(!tree_search(root, values, t_compare));\n-\ttree_free(root);\n-}\n-\n-static void t_infix_walk(void)\n-{\n-\tstruct tree_node *root = NULL;\n-\tvoid *values[11] = { 0 };\n-\tvoid *out[11] = { 0 };\n-\tstruct curry c = {\n-\t\t.arr = (void **) &out,\n-\t};\n-\tsize_t i = 1;\n-\tsize_t count = 0;\n-\n-\tdo {\n-\t\tstruct tree_node *node = tree_insert(&root, &values[i], t_compare);\n-\t\tcheck(node != NULL);\n-\t\ti = (i * 7) % 11;\n-\t\tcount++;\n-\t} while (i != 1);\n-\n-\tinfix_walk(root, &store, &c);\n-\tfor (i = 1; i < ARRAY_SIZE(values); i++)\n-\t\tcheck_pointer_eq(&values[i], out[i - 1]);\n-\tcheck(!out[i - 1]);\n-\tcheck_int(c.len, ==, count);\n-\ttree_free(root);\n-}\n-\n-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)\n-{\n-\tTEST(t_tree_search(), \"tree_search works\");\n-\tTEST(t_infix_walk(), \"infix_walk works\");\n-\n-\treturn test_done();\n-}\ndiff --git a/t/unit-tests/u-reftable-tree.c b/t/unit-tests/u-reftable-tree.c\nnew file mode 100644\nindex 0000000000..bcf9061071\n--- /dev/null\n+++ b/t/unit-tests/u-reftable-tree.c\n@@ -0,0 +1,78 @@\n+/*\n+Copyright 2020 Google LLC\n+\n+Use of this source code is governed by a BSD-style\n+license that can be found in the LICENSE file or at\n+https://developers.google.com/open-source/licenses/bsd\n+*/\n+\n+#include \"unit-test.h\"\n+#include \"reftable/tree.h\"\n+\n+static int t_compare(const void *a, const void *b)\n+{\n+\treturn (char *)a - (char *)b;\n+}\n+\n+struct curry {\n+\tvoid **arr;\n+\tsize_t len;\n+};\n+\n+static void store(void *arg, void *key)\n+{\n+\tstruct curry *c = arg;\n+\tc->arr[c->len++] = key;\n+}\n+\n+void test_reftable_tree__tree_search(void)\n+{\n+\tstruct tree_node *root = NULL;\n+\tvoid *values[11] = { 0 };\n+\tstruct tree_node *nodes[11] = { 0 };\n+\tsize_t i = 1;\n+\n+\t/*\n+\t * Pseudo-randomly insert the pointers for elements between\n+\t * values[1] and values[10] (inclusive) in the tree.\n+\t */\n+\tdo {\n+\t\tnodes[i] = tree_insert(&root, &values[i], &t_compare);\n+\t\tcl_assert(nodes[i] != NULL);\n+\t\ti = (i * 7) % 11;\n+\t} while (i != 1);\n+\n+\tfor (i = 1; i < ARRAY_SIZE(nodes); i++) {\n+\t\tcl_assert_equal_p(&values[i], nodes[i]->key);\n+\t\tcl_assert_equal_p(nodes[i], tree_search(root, &values[i], &t_compare));\n+\t}\n+\n+\tcl_assert(tree_search(root, values, t_compare) == NULL);\n+\ttree_free(root);\n+}\n+\n+void test_reftable_tree__infix_walk(void)\n+{\n+\tstruct tree_node *root = NULL;\n+\tvoid *values[11] = { 0 };\n+\tvoid *out[11] = { 0 };\n+\tstruct curry c = {\n+\t\t.arr = (void **) &out,\n+\t};\n+\tsize_t i = 1;\n+\tsize_t count = 0;\n+\n+\tdo {\n+\t\tstruct tree_node *node = tree_insert(&root, &values[i], t_compare);\n+\t\tcl_assert(node != NULL);\n+\t\ti = (i * 7) % 11;\n+\t\tcount++;\n+\t} while (i != 1);\n+\n+\tinfix_walk(root, &store, &c);\n+\tfor (i = 1; i < ARRAY_SIZE(values); i++)\n+\t\tcl_assert_equal_p(&values[i], out[i - 1]);\n+\tcl_assert(out[i - 1] == NULL);\n+\tcl_assert_equal_i(c.len, count);\n+\ttree_free(root);\n+}\n-- \n2.34.1\n\n"},{"id":"510694","messageId":"Z4kFwynV3sQ5Plm8@pks.im","threadId":"62816","inReplyTo":"20250116104911.77405-2-kuforiji98@gmail.com","subject":"Re: [PATCH 1/4] t/unit-tests: handle dashes in test suite filenames","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-16T13:12:49Z","receivedAt":"2025-01-16T13:12:54Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jan 16, 2025 at 11:49:08AM +0100, Seyi Kuforiji wrote:\n> Adapt script to translate dashes (`-`) in test suite filenames to\n> underscores (`_`) to ensure proper extraction of test function names.\n> `generate-clar-decls.sh` does not pick up dashes in filenames such as\n> `u-mem-pool.c`, which prevents the scripts from being run. This will be\n> used by subsequent commits which follows the same construct.\n\nNit: it would be nice to provide a bit more context. What might not be\nimmediately be obvious is that the script extracts function signatures\nthat match a specific pattern derived from the unit test file's name,\nso pointing that out would likely help.\n\nAlso note that \"u-mem-pool.c\" is not a script, so saying that these are\ngetting run as scripts is misleading. I'd rather say something like\n\"which prevents the unit tests declared in those suites from being\nexecuted\".\n\nThe change itself looks good to me!\n\nPatrick\n"},{"id":"510695","messageId":"Z4kF1zR9TA8ff2bl@pks.im","threadId":"62816","inReplyTo":"20250116104911.77405-3-kuforiji98@gmail.com","subject":"Re: [PATCH 2/4] t/unit-tests: convert mem-pool test to use clar test framework","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-16T13:12:55Z","receivedAt":"2025-01-16T13:13:04Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jan 16, 2025 at 11:49:09AM +0100, Seyi Kuforiji wrote:\n> Adapt the mem-pool test script to use clar framework by using clar\n> assertions where necessary. Following the consensus to convert the\n> unit-tests scripts found in the t/unit-tests folder to clar driven by\n> Patrick Steinhardt.\n\nI think it's a minor detail that isn't really worth mentioning that I\nwas the one introducing the clar, so I'd leave my name out of it. This\nalso applies to subsequent commit messages.\n\n> diff --git a/t/unit-tests/t-mem-pool.c b/t/unit-tests/t-mem-pool.c\n> deleted file mode 100644\n> index fe500c704b..0000000000\n> --- a/t/unit-tests/t-mem-pool.c\n> +++ /dev/null\n> @@ -1,31 +0,0 @@\n> -#include \"test-lib.h\"\n> -#include \"mem-pool.h\"\n> -\n> -static void setup_static(void (*f)(struct mem_pool *), size_t block_alloc)\n> -{\n> -\tstruct mem_pool pool = { .block_alloc = block_alloc };\n> -\tf(&pool);\n> -\tmem_pool_discard(&pool, 0);\n> -}\n> -\n> -static void t_calloc_100(struct mem_pool *pool)\n> -{\n> -\tsize_t size = 100;\n> -\tchar *buffer = mem_pool_calloc(pool, 1, size);\n> -\tfor (size_t i = 0; i < size; i++)\n> -\t\tcheck_int(buffer[i], ==, 0);\n> -\tif (!check(pool->mp_block != NULL))\n> -\t\treturn;\n> -\tcheck(pool->mp_block->next_free != NULL);\n> -\tcheck(pool->mp_block->end != NULL);\n> -}\n> -\n> -int cmd_main(int argc UNUSED, const char **argv UNUSED)\n> -{\n> -\tTEST(setup_static(t_calloc_100, 1024 * 1024),\n> -\t     \"mem_pool_calloc returns 100 zeroed bytes with big block\");\n> -\tTEST(setup_static(t_calloc_100, 1),\n> -\t     \"mem_pool_calloc returns 100 zeroed bytes with tiny block\");\n> -\n> -\treturn test_done();\n> -}\n\nMh, too bad that Git doesn't render it as a \n\n> diff --git a/t/unit-tests/u-mem-pool.c b/t/unit-tests/u-mem-pool.c\n> new file mode 100644\n> index 0000000000..36e31a3201\n> --- /dev/null\n> +++ b/t/unit-tests/u-mem-pool.c\n> @@ -0,0 +1,26 @@\n> +#include \"unit-test.h\"\n> +#include \"mem-pool.h\"\n> +\n> +static void t_calloc_100(size_t block_alloc)\n\nCan we maybe give this a more descriptive name? Something like\n`test_many_pool_allocations()` maybe?\n\n> +{\n> +\tstruct mem_pool pool = { .block_alloc = block_alloc };\n> +\tsize_t size = 100;\n> +\tchar *buffer = mem_pool_calloc(&pool, 1, size);\n> +\tfor (size_t i = 0; i < size; i++)\n> +\t\tcl_assert_equal_i(0, buffer[i]);\n> +\tcl_assert(pool.mp_block != NULL);\n> +\tcl_assert(pool.mp_block->next_free != NULL);\n> +\tcl_assert(pool.mp_block->end != NULL);\n> +\tmem_pool_discard(&pool, 0);\n> +}\n> +\n> +void test_mem_pool__big_block(void)\n> +{\n> +\tt_calloc_100(1024 * 1024);\n> +\n\nThere is a needless empty line here.\n\nOther than that the changes look good to me.\n\nPatrick\n"},{"id":"510696","messageId":"Z4kF3pqipEZ5WAzH@pks.im","threadId":"62816","inReplyTo":"20250116104911.77405-4-kuforiji98@gmail.com","subject":"Re: [PATCH 3/4] t/unit-tests: adapt priority queue test to use clar test framework","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-16T13:13:02Z","receivedAt":"2025-01-16T13:13:05Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jan 16, 2025 at 11:49:10AM +0100, Seyi Kuforiji wrote:\n> diff --git a/t/unit-tests/t-prio-queue.c b/t/unit-tests/t-prio-queue.c\n> deleted file mode 100644\n> index a053635000..0000000000\n> --- a/t/unit-tests/t-prio-queue.c\n> +++ /dev/null\n\nHm. A bit surprising that Git decides to not render this as a rename, as\nmost of `test_prio_queue()` is unchanged.\n\n> diff --git a/t/unit-tests/u-prio-queue.c b/t/unit-tests/u-prio-queue.c\n> new file mode 100644\n> index 0000000000..d36a565e6f\n> --- /dev/null\n> +++ b/t/unit-tests/u-prio-queue.c\n> @@ -0,0 +1,94 @@\n> +#include \"unit-test.h\"\n> +#include \"prio-queue.h\"\n> +\n> +static int intcmp(const void *va, const void *vb, void *data UNUSED)\n> +{\n> +\tconst int *a = va, *b = vb;\n> +\treturn *a - *b;\n> +}\n> +\n> +\n> +#define MISSING  -1\n> +#define DUMP\t -2\n> +#define STACK\t -3\n> +#define GET\t -4\n> +#define REVERSE  -5\n> +\n> +static int show(int *v)\n> +{\n> +\treturn v ? *v : MISSING;\n> +}\n> +\n> +static void test_prio_queue(int *input, size_t input_size,\n> +\t\t\t    int *result, size_t result_size)\n> +{\n> +\tstruct prio_queue pq = { intcmp };\n> +\tsize_t j = 0;\n\nThis is a `size_t` now, which is different compared to before. Might be\nworthwhile to point out why you did this in the commit message.\n\n> +\tfor (size_t i = 0; i < input_size; i++) {\n> +\t\tvoid *peek, *get;\n> +\t\tswitch(input[i]) {\n> +\t\tcase GET:\n> +\t\t\tpeek = prio_queue_peek(&pq);\n> +\t\t\tget = prio_queue_get(&pq);\n> +\t\t\tcl_assert(peek == get);\n> +\t\t\tcl_assert(j < result_size);\n> +\t\t\tcl_assert_equal_i(result[j], show(get));\n> +\t\t\tj++;\n> +\t\t\tbreak;\n> +\t\tcase DUMP:\n> +\t\t\twhile ((peek = prio_queue_peek(&pq))) {\n> +\t\t\t\tget = prio_queue_get(&pq);\n> +\t\t\t\tcl_assert(peek == get);\n> +\t\t\t\tcl_assert((size_t)j < result_size);\n\nThis here is the reason, to avoid -Wsign-compare. But the cast here\nisn't necessary now that you've adapted `j` to be a `size_t` anyway.\n\n> +\t\t\t\tcl_assert_equal_i(result[j], show(get));\n> +\t\t\t\tj++;\n> +\t\t\t}\n> +\t\t\tbreak;\n> +\t\tcase STACK:\n> +\t\t\tpq.compare = NULL;\n> +\t\t\tbreak;\n> +\t\tcase REVERSE:\n> +\t\t\tprio_queue_reverse(&pq);\n> +\t\t\tbreak;\n> +\t\tdefault:\n> +\t\t\tprio_queue_put(&pq, &input[i]);\n> +\t\t\tbreak;\n> +\t\t}\n> +\t}\n> +\tcl_assert_equal_i(j, result_size);\n> +\tclear_prio_queue(&pq);\n> +}\n> +\n> +#define TEST_INPUT(input, result) \\\n> +\ttest_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))\n> +\n> +void test_prio_queue__basic(void)\n> +{\n> +\tTEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),\n> +\t\t   ((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 }));\n> +}\n> +\n> +void test_prio_queue__mixed(void)\n> +{\n> +\tTEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }),\n> +\t\t   ((int []){ 2, 3, 4, 1, 5, 6 }));\n> +}\n> +\n> +void test_prio_queue__empty(void)\n> +{\n> +\tTEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }),\n> +\t\t   ((int []){ 1, 2, MISSING, 1, 2, MISSING }));\n> +}\n> +\n> +void test_prio_queue__stack(void)\n> +{\n> +\tTEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),\n> +\t\t   ((int []){ 3, 2, 6, 4, 5, 1, 8 }));\n> +}\n> +\n> +void test_prio_queue__reverse_stack(void)\n> +{\n> +\tTEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),\n> +\t\t   ((int []){ 1, 2, 3, 4, 5, 6 }));\n> +}\n\nAll of these look like failthful conversions to me.\n\nPatrick\n"},{"id":"510710","messageId":"20250116161559.91038-1-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250116104911.77405-1-kuforiji98@gmail.com","subject":"[PATCH v2 0/4] t/unit-tests: convert unit-tests to use clar","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-16T16:15:55Z","receivedAt":"2025-01-16T16:16:10Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Hello,\n\nThis small patch series transitions the existing unit test files to the\nClar testing framework. This change is part of our ongoing effort to\nstandardize our testing approach and enhance maintainability.\n\nchanges in v2:\n- Some small fixes were made to the commit messages\n- changes was made to the code format\n\n\nThanks\nSeyi\n\nMentored-by: Patrick Steinhardt ps@pks.im\nSigned-off-by: Seyi Kuforiji kuforiji98@gmail.com\n\nSeyi Kuforiji (4):\n  t/unit-tests: handle dashes in test suite filenames\n  t/unit-tests: convert mem-pool test to use clar test framework\n  t/unit-tests: adapt priority queue test to use clar test framework\n  t/unit-tests: convert reftable tree test to use clar test framework\n\n Makefile                            |  6 +-\n t/meson.build                       |  6 +-\n t/unit-tests/generate-clar-decls.sh |  1 +\n t/unit-tests/t-mem-pool.c           | 31 ----------\n t/unit-tests/t-prio-queue.c         | 91 ----------------------------\n t/unit-tests/t-reftable-tree.c      | 86 --------------------------\n t/unit-tests/u-mem-pool.c           | 25 ++++++++\n t/unit-tests/u-prio-queue.c         | 94 +++++++++++++++++++++++++++++\n t/unit-tests/u-reftable-tree.c      | 78 ++++++++++++++++++++++++\n 9 files changed, 204 insertions(+), 214 deletions(-)\n delete mode 100644 t/unit-tests/t-mem-pool.c\n delete mode 100644 t/unit-tests/t-prio-queue.c\n delete mode 100644 t/unit-tests/t-reftable-tree.c\n create mode 100644 t/unit-tests/u-mem-pool.c\n create mode 100644 t/unit-tests/u-prio-queue.c\n create mode 100644 t/unit-tests/u-reftable-tree.c\n\nRange-diff against v1:\n1:  00bb4d2880 = 1:  00bb4d2880 t/unit-tests: handle dashes in test suite filenames\n2:  59abf45f08 = 2:  59abf45f08 t/unit-tests: convert mem-pool test to use clar test framework\n3:  6e01da141d = 3:  6e01da141d t/unit-tests: adapt priority queue test to use clar test framework\n4:  b397a5f131 = 4:  b397a5f131 t/unit-tests: convert reftable tree test to use clar test framework\n-- \n2.34.1\n\n"},{"id":"510711","messageId":"20250116161559.91038-2-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250116161559.91038-1-kuforiji98@gmail.com","subject":"[PATCH v2 1/4] t/unit-tests: handle dashes in test suite filenames","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-16T16:15:56Z","receivedAt":"2025-01-16T16:16:16Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"The script is designed to extract function signatures that match a\nspecific pattern derived from the unit test file's name.\n`generate-clar-decls.sh` does not pick up dashes in filenames, which\nprevents the scripts from being run.\n\nAdapt script to translate dashes (`-`) in test suite filenames to\nunderscores (`_`) to correctly extract the function signatures and run\nthe corresponding tests. This will be used by subsequent commits which\nfollows the same construct.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n t/unit-tests/generate-clar-decls.sh | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/t/unit-tests/generate-clar-decls.sh b/t/unit-tests/generate-clar-decls.sh\nindex 3b315c64b3..abf6a2ea2a 100755\n--- a/t/unit-tests/generate-clar-decls.sh\n+++ b/t/unit-tests/generate-clar-decls.sh\n@@ -14,6 +14,7 @@ do\n \tsuite_name=$(basename \"$suite\")\n \tsuite_name=${suite_name%.c}\n \tsuite_name=${suite_name#u-}\n+\tsuite_name=$(echo \"$suite_name\" | tr '-' '_')\n \tsed -ne \"s/^\\(void test_${suite_name}__[a-zA-Z_0-9][a-zA-Z_0-9]*(void)\\)$/extern \\1;/p\" \"$suite\" ||\n \texit 1\n done >\"$OUTPUT\"\n-- \n2.34.1\n\n"},{"id":"510712","messageId":"20250116161559.91038-3-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250116161559.91038-1-kuforiji98@gmail.com","subject":"[PATCH v2 2/4] t/unit-tests: convert mem-pool test to use clar test framework","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-16T16:15:57Z","receivedAt":"2025-01-16T16:16:22Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Adapt the mem-pool test script to use clar framework by using clar\nassertions where necessary.Test functions are created as a standalone to\ntest different test cases.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                  |  2 +-\n t/meson.build             |  2 +-\n t/unit-tests/t-mem-pool.c | 31 -------------------------------\n t/unit-tests/u-mem-pool.c | 25 +++++++++++++++++++++++++\n 4 files changed, 27 insertions(+), 33 deletions(-)\n delete mode 100644 t/unit-tests/t-mem-pool.c\n create mode 100644 t/unit-tests/u-mem-pool.c\n\ndiff --git a/Makefile b/Makefile\nindex 97e8385b66..49ada4169d 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1338,6 +1338,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/%\n THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%\n \n CLAR_TEST_SUITES += u-ctype\n+CLAR_TEST_SUITES += u-mem-pool\n CLAR_TEST_SUITES += u-strvec\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n@@ -1347,7 +1348,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o\n UNIT_TEST_PROGRAMS += t-example-decorate\n UNIT_TEST_PROGRAMS += t-hash\n UNIT_TEST_PROGRAMS += t-hashmap\n-UNIT_TEST_PROGRAMS += t-mem-pool\n UNIT_TEST_PROGRAMS += t-oid-array\n UNIT_TEST_PROGRAMS += t-oidmap\n UNIT_TEST_PROGRAMS += t-oidtree\ndiff --git a/t/meson.build b/t/meson.build\nindex 602ebfe6a2..ffe951f9be 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -1,5 +1,6 @@\n clar_test_suites = [\n   'unit-tests/u-ctype.c',\n+  'unit-tests/u-mem-pool.c',\n   'unit-tests/u-strvec.c',\n ]\n \n@@ -43,7 +44,6 @@ unit_test_programs = [\n   'unit-tests/t-example-decorate.c',\n   'unit-tests/t-hash.c',\n   'unit-tests/t-hashmap.c',\n-  'unit-tests/t-mem-pool.c',\n   'unit-tests/t-oid-array.c',\n   'unit-tests/t-oidmap.c',\n   'unit-tests/t-oidtree.c',\ndiff --git a/t/unit-tests/t-mem-pool.c b/t/unit-tests/t-mem-pool.c\ndeleted file mode 100644\nindex fe500c704b..0000000000\n--- a/t/unit-tests/t-mem-pool.c\n+++ /dev/null\n@@ -1,31 +0,0 @@\n-#include \"test-lib.h\"\n-#include \"mem-pool.h\"\n-\n-static void setup_static(void (*f)(struct mem_pool *), size_t block_alloc)\n-{\n-\tstruct mem_pool pool = { .block_alloc = block_alloc };\n-\tf(&pool);\n-\tmem_pool_discard(&pool, 0);\n-}\n-\n-static void t_calloc_100(struct mem_pool *pool)\n-{\n-\tsize_t size = 100;\n-\tchar *buffer = mem_pool_calloc(pool, 1, size);\n-\tfor (size_t i = 0; i < size; i++)\n-\t\tcheck_int(buffer[i], ==, 0);\n-\tif (!check(pool->mp_block != NULL))\n-\t\treturn;\n-\tcheck(pool->mp_block->next_free != NULL);\n-\tcheck(pool->mp_block->end != NULL);\n-}\n-\n-int cmd_main(int argc UNUSED, const char **argv UNUSED)\n-{\n-\tTEST(setup_static(t_calloc_100, 1024 * 1024),\n-\t     \"mem_pool_calloc returns 100 zeroed bytes with big block\");\n-\tTEST(setup_static(t_calloc_100, 1),\n-\t     \"mem_pool_calloc returns 100 zeroed bytes with tiny block\");\n-\n-\treturn test_done();\n-}\ndiff --git a/t/unit-tests/u-mem-pool.c b/t/unit-tests/u-mem-pool.c\nnew file mode 100644\nindex 0000000000..2bc2493b7e\n--- /dev/null\n+++ b/t/unit-tests/u-mem-pool.c\n@@ -0,0 +1,25 @@\n+#include \"unit-test.h\"\n+#include \"mem-pool.h\"\n+\n+static void test_many_pool_allocations(size_t block_alloc)\n+{\n+\tstruct mem_pool pool = { .block_alloc = block_alloc };\n+\tsize_t size = 100;\n+\tchar *buffer = mem_pool_calloc(&pool, 1, size);\n+\tfor (size_t i = 0; i < size; i++)\n+\t\tcl_assert_equal_i(0, buffer[i]);\n+\tcl_assert(pool.mp_block != NULL);\n+\tcl_assert(pool.mp_block->next_free != NULL);\n+\tcl_assert(pool.mp_block->end != NULL);\n+\tmem_pool_discard(&pool, 0);\n+}\n+\n+void test_mem_pool__big_block(void)\n+{\n+\ttest_many_pool_allocations(1024 * 1024);\n+}\n+\n+void test_mem_pool__tiny_block(void)\n+{\n+\ttest_many_pool_allocations(1);\n+}\n-- \n2.34.1\n\n"},{"id":"510713","messageId":"20250116161559.91038-4-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250116161559.91038-1-kuforiji98@gmail.com","subject":"[PATCH v2 3/4] t/unit-tests: adapt priority queue test to use clar test framework","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-16T16:15:58Z","receivedAt":"2025-01-16T16:16:27Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Convert the prio-queue test script to clar framework by using clar\nassertions where necessary. Test functions are created as a standalone\nto test different cases.\n\nupdate the type of the variable `j` from int to `size_t`, this ensures\ncompatibility with the type used for result_size, which is also size_t,\npreventing a potential warning or error caused by comparisons between\nsigned and unsigned integers.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                    |  2 +-\n t/meson.build               |  2 +-\n t/unit-tests/t-prio-queue.c | 91 -----------------------------------\n t/unit-tests/u-prio-queue.c | 94 +++++++++++++++++++++++++++++++++++++\n 4 files changed, 96 insertions(+), 93 deletions(-)\n delete mode 100644 t/unit-tests/t-prio-queue.c\n create mode 100644 t/unit-tests/u-prio-queue.c\n\ndiff --git a/Makefile b/Makefile\nindex 49ada4169d..049f857512 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1339,6 +1339,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%\n \n CLAR_TEST_SUITES += u-ctype\n CLAR_TEST_SUITES += u-mem-pool\n+CLAR_TEST_SUITES += u-prio-queue\n CLAR_TEST_SUITES += u-strvec\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n@@ -1351,7 +1352,6 @@ UNIT_TEST_PROGRAMS += t-hashmap\n UNIT_TEST_PROGRAMS += t-oid-array\n UNIT_TEST_PROGRAMS += t-oidmap\n UNIT_TEST_PROGRAMS += t-oidtree\n-UNIT_TEST_PROGRAMS += t-prio-queue\n UNIT_TEST_PROGRAMS += t-reftable-basics\n UNIT_TEST_PROGRAMS += t-reftable-block\n UNIT_TEST_PROGRAMS += t-reftable-merged\ndiff --git a/t/meson.build b/t/meson.build\nindex ffe951f9be..09232967cd 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -1,6 +1,7 @@\n clar_test_suites = [\n   'unit-tests/u-ctype.c',\n   'unit-tests/u-mem-pool.c',\n+  'unit-tests/u-prio-queue.c',\n   'unit-tests/u-strvec.c',\n ]\n \n@@ -47,7 +48,6 @@ unit_test_programs = [\n   'unit-tests/t-oid-array.c',\n   'unit-tests/t-oidmap.c',\n   'unit-tests/t-oidtree.c',\n-  'unit-tests/t-prio-queue.c',\n   'unit-tests/t-reftable-basics.c',\n   'unit-tests/t-reftable-block.c',\n   'unit-tests/t-reftable-merged.c',\ndiff --git a/t/unit-tests/t-prio-queue.c b/t/unit-tests/t-prio-queue.c\ndeleted file mode 100644\nindex a053635000..0000000000\n--- a/t/unit-tests/t-prio-queue.c\n+++ /dev/null\n@@ -1,91 +0,0 @@\n-#include \"test-lib.h\"\n-#include \"prio-queue.h\"\n-\n-static int intcmp(const void *va, const void *vb, void *data UNUSED)\n-{\n-\tconst int *a = va, *b = vb;\n-\treturn *a - *b;\n-}\n-\n-\n-#define MISSING  -1\n-#define DUMP\t -2\n-#define STACK\t -3\n-#define GET\t -4\n-#define REVERSE  -5\n-\n-static int show(int *v)\n-{\n-\treturn v ? *v : MISSING;\n-}\n-\n-static void test_prio_queue(int *input, size_t input_size,\n-\t\t\t    int *result, size_t result_size)\n-{\n-\tstruct prio_queue pq = { intcmp };\n-\tint j = 0;\n-\n-\tfor (size_t i = 0; i < input_size; i++) {\n-\t\tvoid *peek, *get;\n-\t\tswitch(input[i]) {\n-\t\tcase GET:\n-\t\t\tpeek = prio_queue_peek(&pq);\n-\t\t\tget = prio_queue_get(&pq);\n-\t\t\tif (!check(peek == get))\n-\t\t\t\treturn;\n-\t\t\tif (!check_uint(j, <, result_size))\n-\t\t\t\tbreak;\n-\t\t\tif (!check_int(result[j], ==, show(get)))\n-\t\t\t\ttest_msg(\"      j: %d\", j);\n-\t\t\tj++;\n-\t\t\tbreak;\n-\t\tcase DUMP:\n-\t\t\twhile ((peek = prio_queue_peek(&pq))) {\n-\t\t\t\tget = prio_queue_get(&pq);\n-\t\t\t\tif (!check(peek == get))\n-\t\t\t\t\treturn;\n-\t\t\t\tif (!check_uint(j, <, result_size))\n-\t\t\t\t\tbreak;\n-\t\t\t\tif (!check_int(result[j], ==, show(get)))\n-\t\t\t\t\ttest_msg(\"      j: %d\", j);\n-\t\t\t\tj++;\n-\t\t\t}\n-\t\t\tbreak;\n-\t\tcase STACK:\n-\t\t\tpq.compare = NULL;\n-\t\t\tbreak;\n-\t\tcase REVERSE:\n-\t\t\tprio_queue_reverse(&pq);\n-\t\t\tbreak;\n-\t\tdefault:\n-\t\t\tprio_queue_put(&pq, &input[i]);\n-\t\t\tbreak;\n-\t\t}\n-\t}\n-\tcheck_uint(j, ==, result_size);\n-\tclear_prio_queue(&pq);\n-}\n-\n-#define TEST_INPUT(input, result) \\\n-\ttest_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))\n-\n-int cmd_main(int argc UNUSED, const char **argv UNUSED)\n-{\n-\tTEST(TEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),\n-\t\t\t((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 })),\n-\t     \"prio-queue works for basic input\");\n-\tTEST(TEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }),\n-\t\t\t((int []){ 2, 3, 4, 1, 5, 6 })),\n-\t     \"prio-queue works for mixed put & get commands\");\n-\tTEST(TEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }),\n-\t\t\t((int []){ 1, 2, MISSING, 1, 2, MISSING })),\n-\t     \"prio-queue works when queue is empty\");\n-\tTEST(TEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),\n-\t\t\t((int []){ 3, 2, 6, 4, 5, 1, 8 })),\n-\t     \"prio-queue works when used as a LIFO stack\");\n-\tTEST(TEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),\n-\t\t\t((int []){ 1, 2, 3, 4, 5, 6 })),\n-\t     \"prio-queue works when LIFO stack is reversed\");\n-\n-\treturn test_done();\n-}\ndiff --git a/t/unit-tests/u-prio-queue.c b/t/unit-tests/u-prio-queue.c\nnew file mode 100644\nindex 0000000000..145e689c9c\n--- /dev/null\n+++ b/t/unit-tests/u-prio-queue.c\n@@ -0,0 +1,94 @@\n+#include \"unit-test.h\"\n+#include \"prio-queue.h\"\n+\n+static int intcmp(const void *va, const void *vb, void *data UNUSED)\n+{\n+\tconst int *a = va, *b = vb;\n+\treturn *a - *b;\n+}\n+\n+\n+#define MISSING  -1\n+#define DUMP\t -2\n+#define STACK\t -3\n+#define GET\t -4\n+#define REVERSE  -5\n+\n+static int show(int *v)\n+{\n+\treturn v ? *v : MISSING;\n+}\n+\n+static void test_prio_queue(int *input, size_t input_size,\n+\t\t\t    int *result, size_t result_size)\n+{\n+\tstruct prio_queue pq = { intcmp };\n+\tsize_t j = 0;\n+\n+\tfor (size_t i = 0; i < input_size; i++) {\n+\t\tvoid *peek, *get;\n+\t\tswitch(input[i]) {\n+\t\tcase GET:\n+\t\t\tpeek = prio_queue_peek(&pq);\n+\t\t\tget = prio_queue_get(&pq);\n+\t\t\tcl_assert(peek == get);\n+\t\t\tcl_assert(j < result_size);\n+\t\t\tcl_assert_equal_i(result[j], show(get));\n+\t\t\tj++;\n+\t\t\tbreak;\n+\t\tcase DUMP:\n+\t\t\twhile ((peek = prio_queue_peek(&pq))) {\n+\t\t\t\tget = prio_queue_get(&pq);\n+\t\t\t\tcl_assert(peek == get);\n+\t\t\t\tcl_assert(j < result_size);\n+\t\t\t\tcl_assert_equal_i(result[j], show(get));\n+\t\t\t\tj++;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tcase STACK:\n+\t\t\tpq.compare = NULL;\n+\t\t\tbreak;\n+\t\tcase REVERSE:\n+\t\t\tprio_queue_reverse(&pq);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tprio_queue_put(&pq, &input[i]);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tcl_assert_equal_i(j, result_size);\n+\tclear_prio_queue(&pq);\n+}\n+\n+#define TEST_INPUT(input, result) \\\n+\ttest_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))\n+\n+void test_prio_queue__basic(void)\n+{\n+\tTEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),\n+\t\t   ((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 }));\n+}\n+\n+void test_prio_queue__mixed(void)\n+{\n+\tTEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }),\n+\t\t   ((int []){ 2, 3, 4, 1, 5, 6 }));\n+}\n+\n+void test_prio_queue__empty(void)\n+{\n+\tTEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }),\n+\t\t   ((int []){ 1, 2, MISSING, 1, 2, MISSING }));\n+}\n+\n+void test_prio_queue__stack(void)\n+{\n+\tTEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),\n+\t\t   ((int []){ 3, 2, 6, 4, 5, 1, 8 }));\n+}\n+\n+void test_prio_queue__reverse_stack(void)\n+{\n+\tTEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),\n+\t\t   ((int []){ 1, 2, 3, 4, 5, 6 }));\n+}\n-- \n2.34.1\n\n"},{"id":"510714","messageId":"20250116161559.91038-5-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250116161559.91038-1-kuforiji98@gmail.com","subject":"[PATCH v2 4/4] t/unit-tests: convert reftable tree test to use clar test framework","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-16T16:15:59Z","receivedAt":"2025-01-16T16:16:32Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Adapts reftable tree test script to clar framework by using clar\nassertions where necessary.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                       |  2 +-\n t/meson.build                  |  2 +-\n t/unit-tests/t-reftable-tree.c | 86 ----------------------------------\n t/unit-tests/u-reftable-tree.c | 78 ++++++++++++++++++++++++++++++\n 4 files changed, 80 insertions(+), 88 deletions(-)\n delete mode 100644 t/unit-tests/t-reftable-tree.c\n create mode 100644 t/unit-tests/u-reftable-tree.c\n\ndiff --git a/Makefile b/Makefile\nindex 049f857512..75dbb8e25f 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1340,6 +1340,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%\n CLAR_TEST_SUITES += u-ctype\n CLAR_TEST_SUITES += u-mem-pool\n CLAR_TEST_SUITES += u-prio-queue\n+CLAR_TEST_SUITES += u-reftable-tree\n CLAR_TEST_SUITES += u-strvec\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n@@ -1360,7 +1361,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader\n UNIT_TEST_PROGRAMS += t-reftable-readwrite\n UNIT_TEST_PROGRAMS += t-reftable-record\n UNIT_TEST_PROGRAMS += t-reftable-stack\n-UNIT_TEST_PROGRAMS += t-reftable-tree\n UNIT_TEST_PROGRAMS += t-strbuf\n UNIT_TEST_PROGRAMS += t-strcmp-offset\n UNIT_TEST_PROGRAMS += t-trailer\ndiff --git a/t/meson.build b/t/meson.build\nindex 09232967cd..6dd41216ef 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -2,6 +2,7 @@ clar_test_suites = [\n   'unit-tests/u-ctype.c',\n   'unit-tests/u-mem-pool.c',\n   'unit-tests/u-prio-queue.c',\n+  'unit-tests/u-reftable-tree.c',\n   'unit-tests/u-strvec.c',\n ]\n \n@@ -56,7 +57,6 @@ unit_test_programs = [\n   'unit-tests/t-reftable-readwrite.c',\n   'unit-tests/t-reftable-record.c',\n   'unit-tests/t-reftable-stack.c',\n-  'unit-tests/t-reftable-tree.c',\n   'unit-tests/t-strbuf.c',\n   'unit-tests/t-strcmp-offset.c',\n   'unit-tests/t-trailer.c',\ndiff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c\ndeleted file mode 100644\nindex 79b175a45a..0000000000\n--- a/t/unit-tests/t-reftable-tree.c\n+++ /dev/null\n@@ -1,86 +0,0 @@\n-/*\n-Copyright 2020 Google LLC\n-\n-Use of this source code is governed by a BSD-style\n-license that can be found in the LICENSE file or at\n-https://developers.google.com/open-source/licenses/bsd\n-*/\n-\n-#include \"test-lib.h\"\n-#include \"reftable/tree.h\"\n-\n-static int t_compare(const void *a, const void *b)\n-{\n-\treturn (char *)a - (char *)b;\n-}\n-\n-struct curry {\n-\tvoid **arr;\n-\tsize_t len;\n-};\n-\n-static void store(void *arg, void *key)\n-{\n-\tstruct curry *c = arg;\n-\tc->arr[c->len++] = key;\n-}\n-\n-static void t_tree_search(void)\n-{\n-\tstruct tree_node *root = NULL;\n-\tvoid *values[11] = { 0 };\n-\tstruct tree_node *nodes[11] = { 0 };\n-\tsize_t i = 1;\n-\n-\t/*\n-\t * Pseudo-randomly insert the pointers for elements between\n-\t * values[1] and values[10] (inclusive) in the tree.\n-\t */\n-\tdo {\n-\t\tnodes[i] = tree_insert(&root, &values[i], &t_compare);\n-\t\tcheck(nodes[i] != NULL);\n-\t\ti = (i * 7) % 11;\n-\t} while (i != 1);\n-\n-\tfor (i = 1; i < ARRAY_SIZE(nodes); i++) {\n-\t\tcheck_pointer_eq(&values[i], nodes[i]->key);\n-\t\tcheck_pointer_eq(nodes[i], tree_search(root, &values[i], &t_compare));\n-\t}\n-\n-\tcheck(!tree_search(root, values, t_compare));\n-\ttree_free(root);\n-}\n-\n-static void t_infix_walk(void)\n-{\n-\tstruct tree_node *root = NULL;\n-\tvoid *values[11] = { 0 };\n-\tvoid *out[11] = { 0 };\n-\tstruct curry c = {\n-\t\t.arr = (void **) &out,\n-\t};\n-\tsize_t i = 1;\n-\tsize_t count = 0;\n-\n-\tdo {\n-\t\tstruct tree_node *node = tree_insert(&root, &values[i], t_compare);\n-\t\tcheck(node != NULL);\n-\t\ti = (i * 7) % 11;\n-\t\tcount++;\n-\t} while (i != 1);\n-\n-\tinfix_walk(root, &store, &c);\n-\tfor (i = 1; i < ARRAY_SIZE(values); i++)\n-\t\tcheck_pointer_eq(&values[i], out[i - 1]);\n-\tcheck(!out[i - 1]);\n-\tcheck_int(c.len, ==, count);\n-\ttree_free(root);\n-}\n-\n-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)\n-{\n-\tTEST(t_tree_search(), \"tree_search works\");\n-\tTEST(t_infix_walk(), \"infix_walk works\");\n-\n-\treturn test_done();\n-}\ndiff --git a/t/unit-tests/u-reftable-tree.c b/t/unit-tests/u-reftable-tree.c\nnew file mode 100644\nindex 0000000000..bcf9061071\n--- /dev/null\n+++ b/t/unit-tests/u-reftable-tree.c\n@@ -0,0 +1,78 @@\n+/*\n+Copyright 2020 Google LLC\n+\n+Use of this source code is governed by a BSD-style\n+license that can be found in the LICENSE file or at\n+https://developers.google.com/open-source/licenses/bsd\n+*/\n+\n+#include \"unit-test.h\"\n+#include \"reftable/tree.h\"\n+\n+static int t_compare(const void *a, const void *b)\n+{\n+\treturn (char *)a - (char *)b;\n+}\n+\n+struct curry {\n+\tvoid **arr;\n+\tsize_t len;\n+};\n+\n+static void store(void *arg, void *key)\n+{\n+\tstruct curry *c = arg;\n+\tc->arr[c->len++] = key;\n+}\n+\n+void test_reftable_tree__tree_search(void)\n+{\n+\tstruct tree_node *root = NULL;\n+\tvoid *values[11] = { 0 };\n+\tstruct tree_node *nodes[11] = { 0 };\n+\tsize_t i = 1;\n+\n+\t/*\n+\t * Pseudo-randomly insert the pointers for elements between\n+\t * values[1] and values[10] (inclusive) in the tree.\n+\t */\n+\tdo {\n+\t\tnodes[i] = tree_insert(&root, &values[i], &t_compare);\n+\t\tcl_assert(nodes[i] != NULL);\n+\t\ti = (i * 7) % 11;\n+\t} while (i != 1);\n+\n+\tfor (i = 1; i < ARRAY_SIZE(nodes); i++) {\n+\t\tcl_assert_equal_p(&values[i], nodes[i]->key);\n+\t\tcl_assert_equal_p(nodes[i], tree_search(root, &values[i], &t_compare));\n+\t}\n+\n+\tcl_assert(tree_search(root, values, t_compare) == NULL);\n+\ttree_free(root);\n+}\n+\n+void test_reftable_tree__infix_walk(void)\n+{\n+\tstruct tree_node *root = NULL;\n+\tvoid *values[11] = { 0 };\n+\tvoid *out[11] = { 0 };\n+\tstruct curry c = {\n+\t\t.arr = (void **) &out,\n+\t};\n+\tsize_t i = 1;\n+\tsize_t count = 0;\n+\n+\tdo {\n+\t\tstruct tree_node *node = tree_insert(&root, &values[i], t_compare);\n+\t\tcl_assert(node != NULL);\n+\t\ti = (i * 7) % 11;\n+\t\tcount++;\n+\t} while (i != 1);\n+\n+\tinfix_walk(root, &store, &c);\n+\tfor (i = 1; i < ARRAY_SIZE(values); i++)\n+\t\tcl_assert_equal_p(&values[i], out[i - 1]);\n+\tcl_assert(out[i - 1] == NULL);\n+\tcl_assert_equal_i(c.len, count);\n+\ttree_free(root);\n+}\n-- \n2.34.1\n\n"},{"id":"510722","messageId":"xmqqjzauslem.fsf@gitster.g","threadId":"62816","inReplyTo":"Z4kF1zR9TA8ff2bl@pks.im","subject":"Re: [PATCH 2/4] t/unit-tests: convert mem-pool test to use clar test framework","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-01-16T17:45:05Z","receivedAt":"2025-01-16T17:45:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> On Thu, Jan 16, 2025 at 11:49:09AM +0100, Seyi Kuforiji wrote:\n>> Adapt the mem-pool test script to use clar framework by using clar\n>> assertions where necessary. Following the consensus to convert the\n>> unit-tests scripts found in the t/unit-tests folder to clar driven by\n>> Patrick Steinhardt.\n>\n> I think it's a minor detail that isn't really worth mentioning that I\n> was the one introducing the clar, so I'd leave my name out of it. This\n> also applies to subsequent commit messages.\n\nBesides, that part of the description does not read quite\ngrammatical and the rest of the sentence is missing.\nI.e. \"Following the lead by somebody, WE DO SOMETHING\".\n"},{"id":"510758","messageId":"Z4n4MxQ8FT-w6QLW@pks.im","threadId":"62816","inReplyTo":"20250116161559.91038-1-kuforiji98@gmail.com","subject":"Re: [PATCH v2 0/4] t/unit-tests: convert unit-tests to use clar","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-17T06:27:11Z","receivedAt":"2025-01-17T06:27:16Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jan 16, 2025 at 05:15:55PM +0100, Seyi Kuforiji wrote:\n> Range-diff against v1:\n> 1:  00bb4d2880 = 1:  00bb4d2880 t/unit-tests: handle dashes in test suite filenames\n> 2:  59abf45f08 = 2:  59abf45f08 t/unit-tests: convert mem-pool test to use clar test framework\n> 3:  6e01da141d = 3:  6e01da141d t/unit-tests: adapt priority queue test to use clar test framework\n> 4:  b397a5f131 = 4:  b397a5f131 t/unit-tests: convert reftable tree test to use clar test framework\n\nI think you passed wrong commit ranges for the range-diff :)\n\nAnyway, I scanned through the changes and saw that all my feedback was\naddressed. I've got one more proposal for the first commit message, but\nother than that the series looks good to me.\n\nThanks!\n\nPatrick\n"},{"id":"510759","messageId":"Z4n4Qyt8qSBMVXUQ@pks.im","threadId":"62816","inReplyTo":"20250116161559.91038-2-kuforiji98@gmail.com","subject":"Re: [PATCH v2 1/4] t/unit-tests: handle dashes in test suite filenames","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-17T06:27:15Z","receivedAt":"2025-01-17T06:27:19Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jan 16, 2025 at 05:15:56PM +0100, Seyi Kuforiji wrote:\n> The script is designed to extract function signatures that match a\n> specific pattern derived from the unit test file's name.\n> `generate-clar-decls.sh` does not pick up dashes in filenames, which\n> prevents the scripts from being run.\n\nAs said in my first round, saying \"scripts\" here is misleading as the\nunit tests aren't scripts in the first place. How about:\n\n    The \"generate-clar-decls.sh\" script is designed to extract function\n    signatures that match a specific pattern derived from the unit test\n    file's name. The script does not know to massage file names with\n    dashes, which will make it search for functions that look like, for\n    example, `test_mem-pool_*`. Having dashes in function names is not\n    allowed though, so these patterns won't ever match a legal function\n    name.\n\nPatrick\n"},{"id":"510797","messageId":"20250117122926.101749-1-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250116161559.91038-1-kuforiji98@gmail.com","subject":"t/unit-tests: convert unit-tests to use clar","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-17T12:29:22Z","receivedAt":"2025-01-17T12:29:34Z","isPatch":false,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Hello,\n\nThis small patch series transitions the existing unit test files to the\nClar testing framework. This change is part of our ongoing effort to\nstandardize our testing approach and enhance maintainability.\n\nchanges in v3:\n- Some small fixes were made to the commit messages\n\nThanks\nSeyi\n\nMentored-by: Patrick Steinhardt ps@pks.im\nSigned-off-by: Seyi Kuforiji kuforiji98@gmail.com\n\nSeyi Kuforiji (4):\n  t/unit-tests: handle dashes in test suite filenames\n  t/unit-tests: convert mem-pool test to use clar test framework\n  t/unit-tests: adapt priority queue test to use clar test framework\n  t/unit-tests: convert reftable tree test to use clar test framework\n\n Makefile                            |  6 +-\n t/meson.build                       |  6 +-\n t/unit-tests/generate-clar-decls.sh |  1 +\n t/unit-tests/t-mem-pool.c           | 31 ----------\n t/unit-tests/t-prio-queue.c         | 91 ----------------------------\n t/unit-tests/t-reftable-tree.c      | 86 --------------------------\n t/unit-tests/u-mem-pool.c           | 25 ++++++++\n t/unit-tests/u-prio-queue.c         | 94 +++++++++++++++++++++++++++++\n t/unit-tests/u-reftable-tree.c      | 78 ++++++++++++++++++++++++\n 9 files changed, 204 insertions(+), 214 deletions(-)\n delete mode 100644 t/unit-tests/t-mem-pool.c\n delete mode 100644 t/unit-tests/t-prio-queue.c\n delete mode 100644 t/unit-tests/t-reftable-tree.c\n create mode 100644 t/unit-tests/u-mem-pool.c\n create mode 100644 t/unit-tests/u-prio-queue.c\n create mode 100644 t/unit-tests/u-reftable-tree.c\n\nRange-diff against v2:\n1:  00bb4d2880 ! 1:  f9e163a181 t/unit-tests: handle dashes in test suite filenames\n    @@ Metadata\n      ## Commit message ##\n         t/unit-tests: handle dashes in test suite filenames\n     \n    -    The script is designed to extract function signatures that match a\n    -    specific pattern derived from the unit test file's name.\n    -    `generate-clar-decls.sh` does not pick up dashes in filenames, which\n    -    prevents the scripts from being run.\n    +    \"generate-clar-decls.sh\" script is designed to extract function\n    +    signatures that match a specific pattern derived from the unit test\n    +    file's name. The script does not know to massage file names with dashes,\n    +    which will make it search for functions that look like, for example,\n    +    `test_mem-pool_*`. Having dashes in function names is not allowed\n    +    though, so these patterns won't ever match a legal function name.\n     \n         Adapt script to translate dashes (`-`) in test suite filenames to\n         underscores (`_`) to correctly extract the function signatures and run\n-:  ---------- > 2:  f46438f53e t/unit-tests: convert mem-pool test to use clar test framework\n-:  ---------- > 3:  f5cabebd3a t/unit-tests: adapt priority queue test to use clar test framework\n-:  ---------- > 4:  5323873612 t/unit-tests: convert reftable tree test to use clar test framework\n-- \n2.34.1\n\n"},{"id":"510798","messageId":"20250117122926.101749-2-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250117122926.101749-1-kuforiji98@gmail.com","subject":"[PATCH v3 1/4] t/unit-tests: handle dashes in test suite filenames","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-17T12:29:23Z","receivedAt":"2025-01-17T12:29:38Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"\"generate-clar-decls.sh\" script is designed to extract function\nsignatures that match a specific pattern derived from the unit test\nfile's name. The script does not know to massage file names with dashes,\nwhich will make it search for functions that look like, for example,\n`test_mem-pool_*`. Having dashes in function names is not allowed\nthough, so these patterns won't ever match a legal function name.\n\nAdapt script to translate dashes (`-`) in test suite filenames to\nunderscores (`_`) to correctly extract the function signatures and run\nthe corresponding tests. This will be used by subsequent commits which\nfollows the same construct.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n t/unit-tests/generate-clar-decls.sh | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/t/unit-tests/generate-clar-decls.sh b/t/unit-tests/generate-clar-decls.sh\nindex 3b315c64b3..abf6a2ea2a 100755\n--- a/t/unit-tests/generate-clar-decls.sh\n+++ b/t/unit-tests/generate-clar-decls.sh\n@@ -14,6 +14,7 @@ do\n \tsuite_name=$(basename \"$suite\")\n \tsuite_name=${suite_name%.c}\n \tsuite_name=${suite_name#u-}\n+\tsuite_name=$(echo \"$suite_name\" | tr '-' '_')\n \tsed -ne \"s/^\\(void test_${suite_name}__[a-zA-Z_0-9][a-zA-Z_0-9]*(void)\\)$/extern \\1;/p\" \"$suite\" ||\n \texit 1\n done >\"$OUTPUT\"\n-- \n2.34.1\n\n"},{"id":"510799","messageId":"20250117122926.101749-3-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250117122926.101749-1-kuforiji98@gmail.com","subject":"[PATCH v3 2/4] t/unit-tests: convert mem-pool test to use clar test framework","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-17T12:29:24Z","receivedAt":"2025-01-17T12:29:47Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Adapt the mem-pool test script to use clar framework by using clar\nassertions where necessary.Test functions are created as a standalone to\ntest different test cases.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                  |  2 +-\n t/meson.build             |  2 +-\n t/unit-tests/t-mem-pool.c | 31 -------------------------------\n t/unit-tests/u-mem-pool.c | 25 +++++++++++++++++++++++++\n 4 files changed, 27 insertions(+), 33 deletions(-)\n delete mode 100644 t/unit-tests/t-mem-pool.c\n create mode 100644 t/unit-tests/u-mem-pool.c\n\ndiff --git a/Makefile b/Makefile\nindex 97e8385b66..49ada4169d 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1338,6 +1338,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/%\n THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%\n \n CLAR_TEST_SUITES += u-ctype\n+CLAR_TEST_SUITES += u-mem-pool\n CLAR_TEST_SUITES += u-strvec\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n@@ -1347,7 +1348,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o\n UNIT_TEST_PROGRAMS += t-example-decorate\n UNIT_TEST_PROGRAMS += t-hash\n UNIT_TEST_PROGRAMS += t-hashmap\n-UNIT_TEST_PROGRAMS += t-mem-pool\n UNIT_TEST_PROGRAMS += t-oid-array\n UNIT_TEST_PROGRAMS += t-oidmap\n UNIT_TEST_PROGRAMS += t-oidtree\ndiff --git a/t/meson.build b/t/meson.build\nindex 602ebfe6a2..ffe951f9be 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -1,5 +1,6 @@\n clar_test_suites = [\n   'unit-tests/u-ctype.c',\n+  'unit-tests/u-mem-pool.c',\n   'unit-tests/u-strvec.c',\n ]\n \n@@ -43,7 +44,6 @@ unit_test_programs = [\n   'unit-tests/t-example-decorate.c',\n   'unit-tests/t-hash.c',\n   'unit-tests/t-hashmap.c',\n-  'unit-tests/t-mem-pool.c',\n   'unit-tests/t-oid-array.c',\n   'unit-tests/t-oidmap.c',\n   'unit-tests/t-oidtree.c',\ndiff --git a/t/unit-tests/t-mem-pool.c b/t/unit-tests/t-mem-pool.c\ndeleted file mode 100644\nindex fe500c704b..0000000000\n--- a/t/unit-tests/t-mem-pool.c\n+++ /dev/null\n@@ -1,31 +0,0 @@\n-#include \"test-lib.h\"\n-#include \"mem-pool.h\"\n-\n-static void setup_static(void (*f)(struct mem_pool *), size_t block_alloc)\n-{\n-\tstruct mem_pool pool = { .block_alloc = block_alloc };\n-\tf(&pool);\n-\tmem_pool_discard(&pool, 0);\n-}\n-\n-static void t_calloc_100(struct mem_pool *pool)\n-{\n-\tsize_t size = 100;\n-\tchar *buffer = mem_pool_calloc(pool, 1, size);\n-\tfor (size_t i = 0; i < size; i++)\n-\t\tcheck_int(buffer[i], ==, 0);\n-\tif (!check(pool->mp_block != NULL))\n-\t\treturn;\n-\tcheck(pool->mp_block->next_free != NULL);\n-\tcheck(pool->mp_block->end != NULL);\n-}\n-\n-int cmd_main(int argc UNUSED, const char **argv UNUSED)\n-{\n-\tTEST(setup_static(t_calloc_100, 1024 * 1024),\n-\t     \"mem_pool_calloc returns 100 zeroed bytes with big block\");\n-\tTEST(setup_static(t_calloc_100, 1),\n-\t     \"mem_pool_calloc returns 100 zeroed bytes with tiny block\");\n-\n-\treturn test_done();\n-}\ndiff --git a/t/unit-tests/u-mem-pool.c b/t/unit-tests/u-mem-pool.c\nnew file mode 100644\nindex 0000000000..2bc2493b7e\n--- /dev/null\n+++ b/t/unit-tests/u-mem-pool.c\n@@ -0,0 +1,25 @@\n+#include \"unit-test.h\"\n+#include \"mem-pool.h\"\n+\n+static void test_many_pool_allocations(size_t block_alloc)\n+{\n+\tstruct mem_pool pool = { .block_alloc = block_alloc };\n+\tsize_t size = 100;\n+\tchar *buffer = mem_pool_calloc(&pool, 1, size);\n+\tfor (size_t i = 0; i < size; i++)\n+\t\tcl_assert_equal_i(0, buffer[i]);\n+\tcl_assert(pool.mp_block != NULL);\n+\tcl_assert(pool.mp_block->next_free != NULL);\n+\tcl_assert(pool.mp_block->end != NULL);\n+\tmem_pool_discard(&pool, 0);\n+}\n+\n+void test_mem_pool__big_block(void)\n+{\n+\ttest_many_pool_allocations(1024 * 1024);\n+}\n+\n+void test_mem_pool__tiny_block(void)\n+{\n+\ttest_many_pool_allocations(1);\n+}\n-- \n2.34.1\n\n"},{"id":"510800","messageId":"20250117122926.101749-4-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250117122926.101749-1-kuforiji98@gmail.com","subject":"[PATCH v3 3/4] t/unit-tests: adapt priority queue test to use clar test framework","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-17T12:29:25Z","receivedAt":"2025-01-17T12:29:52Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Convert the prio-queue test script to clar framework by using clar\nassertions where necessary. Test functions are created as a standalone\nto test different cases.\n\nupdate the type of the variable `j` from int to `size_t`, this ensures\ncompatibility with the type used for result_size, which is also size_t,\npreventing a potential warning or error caused by comparisons between\nsigned and unsigned integers.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                    |  2 +-\n t/meson.build               |  2 +-\n t/unit-tests/t-prio-queue.c | 91 -----------------------------------\n t/unit-tests/u-prio-queue.c | 94 +++++++++++++++++++++++++++++++++++++\n 4 files changed, 96 insertions(+), 93 deletions(-)\n delete mode 100644 t/unit-tests/t-prio-queue.c\n create mode 100644 t/unit-tests/u-prio-queue.c\n\ndiff --git a/Makefile b/Makefile\nindex 49ada4169d..049f857512 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1339,6 +1339,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%\n \n CLAR_TEST_SUITES += u-ctype\n CLAR_TEST_SUITES += u-mem-pool\n+CLAR_TEST_SUITES += u-prio-queue\n CLAR_TEST_SUITES += u-strvec\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n@@ -1351,7 +1352,6 @@ UNIT_TEST_PROGRAMS += t-hashmap\n UNIT_TEST_PROGRAMS += t-oid-array\n UNIT_TEST_PROGRAMS += t-oidmap\n UNIT_TEST_PROGRAMS += t-oidtree\n-UNIT_TEST_PROGRAMS += t-prio-queue\n UNIT_TEST_PROGRAMS += t-reftable-basics\n UNIT_TEST_PROGRAMS += t-reftable-block\n UNIT_TEST_PROGRAMS += t-reftable-merged\ndiff --git a/t/meson.build b/t/meson.build\nindex ffe951f9be..09232967cd 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -1,6 +1,7 @@\n clar_test_suites = [\n   'unit-tests/u-ctype.c',\n   'unit-tests/u-mem-pool.c',\n+  'unit-tests/u-prio-queue.c',\n   'unit-tests/u-strvec.c',\n ]\n \n@@ -47,7 +48,6 @@ unit_test_programs = [\n   'unit-tests/t-oid-array.c',\n   'unit-tests/t-oidmap.c',\n   'unit-tests/t-oidtree.c',\n-  'unit-tests/t-prio-queue.c',\n   'unit-tests/t-reftable-basics.c',\n   'unit-tests/t-reftable-block.c',\n   'unit-tests/t-reftable-merged.c',\ndiff --git a/t/unit-tests/t-prio-queue.c b/t/unit-tests/t-prio-queue.c\ndeleted file mode 100644\nindex a053635000..0000000000\n--- a/t/unit-tests/t-prio-queue.c\n+++ /dev/null\n@@ -1,91 +0,0 @@\n-#include \"test-lib.h\"\n-#include \"prio-queue.h\"\n-\n-static int intcmp(const void *va, const void *vb, void *data UNUSED)\n-{\n-\tconst int *a = va, *b = vb;\n-\treturn *a - *b;\n-}\n-\n-\n-#define MISSING  -1\n-#define DUMP\t -2\n-#define STACK\t -3\n-#define GET\t -4\n-#define REVERSE  -5\n-\n-static int show(int *v)\n-{\n-\treturn v ? *v : MISSING;\n-}\n-\n-static void test_prio_queue(int *input, size_t input_size,\n-\t\t\t    int *result, size_t result_size)\n-{\n-\tstruct prio_queue pq = { intcmp };\n-\tint j = 0;\n-\n-\tfor (size_t i = 0; i < input_size; i++) {\n-\t\tvoid *peek, *get;\n-\t\tswitch(input[i]) {\n-\t\tcase GET:\n-\t\t\tpeek = prio_queue_peek(&pq);\n-\t\t\tget = prio_queue_get(&pq);\n-\t\t\tif (!check(peek == get))\n-\t\t\t\treturn;\n-\t\t\tif (!check_uint(j, <, result_size))\n-\t\t\t\tbreak;\n-\t\t\tif (!check_int(result[j], ==, show(get)))\n-\t\t\t\ttest_msg(\"      j: %d\", j);\n-\t\t\tj++;\n-\t\t\tbreak;\n-\t\tcase DUMP:\n-\t\t\twhile ((peek = prio_queue_peek(&pq))) {\n-\t\t\t\tget = prio_queue_get(&pq);\n-\t\t\t\tif (!check(peek == get))\n-\t\t\t\t\treturn;\n-\t\t\t\tif (!check_uint(j, <, result_size))\n-\t\t\t\t\tbreak;\n-\t\t\t\tif (!check_int(result[j], ==, show(get)))\n-\t\t\t\t\ttest_msg(\"      j: %d\", j);\n-\t\t\t\tj++;\n-\t\t\t}\n-\t\t\tbreak;\n-\t\tcase STACK:\n-\t\t\tpq.compare = NULL;\n-\t\t\tbreak;\n-\t\tcase REVERSE:\n-\t\t\tprio_queue_reverse(&pq);\n-\t\t\tbreak;\n-\t\tdefault:\n-\t\t\tprio_queue_put(&pq, &input[i]);\n-\t\t\tbreak;\n-\t\t}\n-\t}\n-\tcheck_uint(j, ==, result_size);\n-\tclear_prio_queue(&pq);\n-}\n-\n-#define TEST_INPUT(input, result) \\\n-\ttest_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))\n-\n-int cmd_main(int argc UNUSED, const char **argv UNUSED)\n-{\n-\tTEST(TEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),\n-\t\t\t((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 })),\n-\t     \"prio-queue works for basic input\");\n-\tTEST(TEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }),\n-\t\t\t((int []){ 2, 3, 4, 1, 5, 6 })),\n-\t     \"prio-queue works for mixed put & get commands\");\n-\tTEST(TEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }),\n-\t\t\t((int []){ 1, 2, MISSING, 1, 2, MISSING })),\n-\t     \"prio-queue works when queue is empty\");\n-\tTEST(TEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),\n-\t\t\t((int []){ 3, 2, 6, 4, 5, 1, 8 })),\n-\t     \"prio-queue works when used as a LIFO stack\");\n-\tTEST(TEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),\n-\t\t\t((int []){ 1, 2, 3, 4, 5, 6 })),\n-\t     \"prio-queue works when LIFO stack is reversed\");\n-\n-\treturn test_done();\n-}\ndiff --git a/t/unit-tests/u-prio-queue.c b/t/unit-tests/u-prio-queue.c\nnew file mode 100644\nindex 0000000000..145e689c9c\n--- /dev/null\n+++ b/t/unit-tests/u-prio-queue.c\n@@ -0,0 +1,94 @@\n+#include \"unit-test.h\"\n+#include \"prio-queue.h\"\n+\n+static int intcmp(const void *va, const void *vb, void *data UNUSED)\n+{\n+\tconst int *a = va, *b = vb;\n+\treturn *a - *b;\n+}\n+\n+\n+#define MISSING  -1\n+#define DUMP\t -2\n+#define STACK\t -3\n+#define GET\t -4\n+#define REVERSE  -5\n+\n+static int show(int *v)\n+{\n+\treturn v ? *v : MISSING;\n+}\n+\n+static void test_prio_queue(int *input, size_t input_size,\n+\t\t\t    int *result, size_t result_size)\n+{\n+\tstruct prio_queue pq = { intcmp };\n+\tsize_t j = 0;\n+\n+\tfor (size_t i = 0; i < input_size; i++) {\n+\t\tvoid *peek, *get;\n+\t\tswitch(input[i]) {\n+\t\tcase GET:\n+\t\t\tpeek = prio_queue_peek(&pq);\n+\t\t\tget = prio_queue_get(&pq);\n+\t\t\tcl_assert(peek == get);\n+\t\t\tcl_assert(j < result_size);\n+\t\t\tcl_assert_equal_i(result[j], show(get));\n+\t\t\tj++;\n+\t\t\tbreak;\n+\t\tcase DUMP:\n+\t\t\twhile ((peek = prio_queue_peek(&pq))) {\n+\t\t\t\tget = prio_queue_get(&pq);\n+\t\t\t\tcl_assert(peek == get);\n+\t\t\t\tcl_assert(j < result_size);\n+\t\t\t\tcl_assert_equal_i(result[j], show(get));\n+\t\t\t\tj++;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tcase STACK:\n+\t\t\tpq.compare = NULL;\n+\t\t\tbreak;\n+\t\tcase REVERSE:\n+\t\t\tprio_queue_reverse(&pq);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tprio_queue_put(&pq, &input[i]);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tcl_assert_equal_i(j, result_size);\n+\tclear_prio_queue(&pq);\n+}\n+\n+#define TEST_INPUT(input, result) \\\n+\ttest_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))\n+\n+void test_prio_queue__basic(void)\n+{\n+\tTEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),\n+\t\t   ((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 }));\n+}\n+\n+void test_prio_queue__mixed(void)\n+{\n+\tTEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }),\n+\t\t   ((int []){ 2, 3, 4, 1, 5, 6 }));\n+}\n+\n+void test_prio_queue__empty(void)\n+{\n+\tTEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }),\n+\t\t   ((int []){ 1, 2, MISSING, 1, 2, MISSING }));\n+}\n+\n+void test_prio_queue__stack(void)\n+{\n+\tTEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),\n+\t\t   ((int []){ 3, 2, 6, 4, 5, 1, 8 }));\n+}\n+\n+void test_prio_queue__reverse_stack(void)\n+{\n+\tTEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),\n+\t\t   ((int []){ 1, 2, 3, 4, 5, 6 }));\n+}\n-- \n2.34.1\n\n"},{"id":"510801","messageId":"20250117122926.101749-5-kuforiji98@gmail.com","threadId":"62816","inReplyTo":"20250117122926.101749-1-kuforiji98@gmail.com","subject":"[PATCH v3 4/4] t/unit-tests: convert reftable tree test to use clar test framework","fromName":"Seyi Kuforiji","fromEmail":"kuforiji98@gmail.com","sentAt":"2025-01-17T12:29:26Z","receivedAt":"2025-01-17T12:30:01Z","isPatch":true,"sender":{"key":"kuforiji98@gmail.com","avatar":"https://avatars.githubusercontent.com/u/94905626?v=4"},"body":"Adapts reftable tree test script to clar framework by using clar\nassertions where necessary.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Seyi Kuforiji <kuforiji98@gmail.com>\n---\n Makefile                       |  2 +-\n t/meson.build                  |  2 +-\n t/unit-tests/t-reftable-tree.c | 86 ----------------------------------\n t/unit-tests/u-reftable-tree.c | 78 ++++++++++++++++++++++++++++++\n 4 files changed, 80 insertions(+), 88 deletions(-)\n delete mode 100644 t/unit-tests/t-reftable-tree.c\n create mode 100644 t/unit-tests/u-reftable-tree.c\n\ndiff --git a/Makefile b/Makefile\nindex 049f857512..75dbb8e25f 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1340,6 +1340,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%\n CLAR_TEST_SUITES += u-ctype\n CLAR_TEST_SUITES += u-mem-pool\n CLAR_TEST_SUITES += u-prio-queue\n+CLAR_TEST_SUITES += u-reftable-tree\n CLAR_TEST_SUITES += u-strvec\n CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)\n CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))\n@@ -1360,7 +1361,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader\n UNIT_TEST_PROGRAMS += t-reftable-readwrite\n UNIT_TEST_PROGRAMS += t-reftable-record\n UNIT_TEST_PROGRAMS += t-reftable-stack\n-UNIT_TEST_PROGRAMS += t-reftable-tree\n UNIT_TEST_PROGRAMS += t-strbuf\n UNIT_TEST_PROGRAMS += t-strcmp-offset\n UNIT_TEST_PROGRAMS += t-trailer\ndiff --git a/t/meson.build b/t/meson.build\nindex 09232967cd..6dd41216ef 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -2,6 +2,7 @@ clar_test_suites = [\n   'unit-tests/u-ctype.c',\n   'unit-tests/u-mem-pool.c',\n   'unit-tests/u-prio-queue.c',\n+  'unit-tests/u-reftable-tree.c',\n   'unit-tests/u-strvec.c',\n ]\n \n@@ -56,7 +57,6 @@ unit_test_programs = [\n   'unit-tests/t-reftable-readwrite.c',\n   'unit-tests/t-reftable-record.c',\n   'unit-tests/t-reftable-stack.c',\n-  'unit-tests/t-reftable-tree.c',\n   'unit-tests/t-strbuf.c',\n   'unit-tests/t-strcmp-offset.c',\n   'unit-tests/t-trailer.c',\ndiff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c\ndeleted file mode 100644\nindex 79b175a45a..0000000000\n--- a/t/unit-tests/t-reftable-tree.c\n+++ /dev/null\n@@ -1,86 +0,0 @@\n-/*\n-Copyright 2020 Google LLC\n-\n-Use of this source code is governed by a BSD-style\n-license that can be found in the LICENSE file or at\n-https://developers.google.com/open-source/licenses/bsd\n-*/\n-\n-#include \"test-lib.h\"\n-#include \"reftable/tree.h\"\n-\n-static int t_compare(const void *a, const void *b)\n-{\n-\treturn (char *)a - (char *)b;\n-}\n-\n-struct curry {\n-\tvoid **arr;\n-\tsize_t len;\n-};\n-\n-static void store(void *arg, void *key)\n-{\n-\tstruct curry *c = arg;\n-\tc->arr[c->len++] = key;\n-}\n-\n-static void t_tree_search(void)\n-{\n-\tstruct tree_node *root = NULL;\n-\tvoid *values[11] = { 0 };\n-\tstruct tree_node *nodes[11] = { 0 };\n-\tsize_t i = 1;\n-\n-\t/*\n-\t * Pseudo-randomly insert the pointers for elements between\n-\t * values[1] and values[10] (inclusive) in the tree.\n-\t */\n-\tdo {\n-\t\tnodes[i] = tree_insert(&root, &values[i], &t_compare);\n-\t\tcheck(nodes[i] != NULL);\n-\t\ti = (i * 7) % 11;\n-\t} while (i != 1);\n-\n-\tfor (i = 1; i < ARRAY_SIZE(nodes); i++) {\n-\t\tcheck_pointer_eq(&values[i], nodes[i]->key);\n-\t\tcheck_pointer_eq(nodes[i], tree_search(root, &values[i], &t_compare));\n-\t}\n-\n-\tcheck(!tree_search(root, values, t_compare));\n-\ttree_free(root);\n-}\n-\n-static void t_infix_walk(void)\n-{\n-\tstruct tree_node *root = NULL;\n-\tvoid *values[11] = { 0 };\n-\tvoid *out[11] = { 0 };\n-\tstruct curry c = {\n-\t\t.arr = (void **) &out,\n-\t};\n-\tsize_t i = 1;\n-\tsize_t count = 0;\n-\n-\tdo {\n-\t\tstruct tree_node *node = tree_insert(&root, &values[i], t_compare);\n-\t\tcheck(node != NULL);\n-\t\ti = (i * 7) % 11;\n-\t\tcount++;\n-\t} while (i != 1);\n-\n-\tinfix_walk(root, &store, &c);\n-\tfor (i = 1; i < ARRAY_SIZE(values); i++)\n-\t\tcheck_pointer_eq(&values[i], out[i - 1]);\n-\tcheck(!out[i - 1]);\n-\tcheck_int(c.len, ==, count);\n-\ttree_free(root);\n-}\n-\n-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)\n-{\n-\tTEST(t_tree_search(), \"tree_search works\");\n-\tTEST(t_infix_walk(), \"infix_walk works\");\n-\n-\treturn test_done();\n-}\ndiff --git a/t/unit-tests/u-reftable-tree.c b/t/unit-tests/u-reftable-tree.c\nnew file mode 100644\nindex 0000000000..bcf9061071\n--- /dev/null\n+++ b/t/unit-tests/u-reftable-tree.c\n@@ -0,0 +1,78 @@\n+/*\n+Copyright 2020 Google LLC\n+\n+Use of this source code is governed by a BSD-style\n+license that can be found in the LICENSE file or at\n+https://developers.google.com/open-source/licenses/bsd\n+*/\n+\n+#include \"unit-test.h\"\n+#include \"reftable/tree.h\"\n+\n+static int t_compare(const void *a, const void *b)\n+{\n+\treturn (char *)a - (char *)b;\n+}\n+\n+struct curry {\n+\tvoid **arr;\n+\tsize_t len;\n+};\n+\n+static void store(void *arg, void *key)\n+{\n+\tstruct curry *c = arg;\n+\tc->arr[c->len++] = key;\n+}\n+\n+void test_reftable_tree__tree_search(void)\n+{\n+\tstruct tree_node *root = NULL;\n+\tvoid *values[11] = { 0 };\n+\tstruct tree_node *nodes[11] = { 0 };\n+\tsize_t i = 1;\n+\n+\t/*\n+\t * Pseudo-randomly insert the pointers for elements between\n+\t * values[1] and values[10] (inclusive) in the tree.\n+\t */\n+\tdo {\n+\t\tnodes[i] = tree_insert(&root, &values[i], &t_compare);\n+\t\tcl_assert(nodes[i] != NULL);\n+\t\ti = (i * 7) % 11;\n+\t} while (i != 1);\n+\n+\tfor (i = 1; i < ARRAY_SIZE(nodes); i++) {\n+\t\tcl_assert_equal_p(&values[i], nodes[i]->key);\n+\t\tcl_assert_equal_p(nodes[i], tree_search(root, &values[i], &t_compare));\n+\t}\n+\n+\tcl_assert(tree_search(root, values, t_compare) == NULL);\n+\ttree_free(root);\n+}\n+\n+void test_reftable_tree__infix_walk(void)\n+{\n+\tstruct tree_node *root = NULL;\n+\tvoid *values[11] = { 0 };\n+\tvoid *out[11] = { 0 };\n+\tstruct curry c = {\n+\t\t.arr = (void **) &out,\n+\t};\n+\tsize_t i = 1;\n+\tsize_t count = 0;\n+\n+\tdo {\n+\t\tstruct tree_node *node = tree_insert(&root, &values[i], t_compare);\n+\t\tcl_assert(node != NULL);\n+\t\ti = (i * 7) % 11;\n+\t\tcount++;\n+\t} while (i != 1);\n+\n+\tinfix_walk(root, &store, &c);\n+\tfor (i = 1; i < ARRAY_SIZE(values); i++)\n+\t\tcl_assert_equal_p(&values[i], out[i - 1]);\n+\tcl_assert(out[i - 1] == NULL);\n+\tcl_assert_equal_i(c.len, count);\n+\ttree_free(root);\n+}\n-- \n2.34.1\n\n"},{"id":"510807","messageId":"Z4pc5ItVQwTJNd--@pks.im","threadId":"62816","inReplyTo":"20250117122926.101749-1-kuforiji98@gmail.com","subject":"Re: t/unit-tests: convert unit-tests to use clar","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-17T13:36:36Z","receivedAt":"2025-01-17T13:36:42Z","isPatch":false,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Jan 17, 2025 at 01:29:22PM +0100, Seyi Kuforiji wrote:\n> Hello,\n> \n> This small patch series transitions the existing unit test files to the\n> Clar testing framework. This change is part of our ongoing effort to\n> standardize our testing approach and enhance maintainability.\n> \n> changes in v3:\n> - Some small fixes were made to the commit messages\n\nThanks, the series looks good to me now.\n\n> Range-diff against v2:\n> 1:  00bb4d2880 ! 1:  f9e163a181 t/unit-tests: handle dashes in test suite filenames\n>     @@ Metadata\n>       ## Commit message ##\n>          t/unit-tests: handle dashes in test suite filenames\n>      \n>     -    The script is designed to extract function signatures that match a\n>     -    specific pattern derived from the unit test file's name.\n>     -    `generate-clar-decls.sh` does not pick up dashes in filenames, which\n>     -    prevents the scripts from being run.\n>     +    \"generate-clar-decls.sh\" script is designed to extract function\n>     +    signatures that match a specific pattern derived from the unit test\n>     +    file's name. The script does not know to massage file names with dashes,\n>     +    which will make it search for functions that look like, for example,\n>     +    `test_mem-pool_*`. Having dashes in function names is not allowed\n>     +    though, so these patterns won't ever match a legal function name.\n>      \n>          Adapt script to translate dashes (`-`) in test suite filenames to\n>          underscores (`_`) to correctly extract the function signatures and run\n> -:  ---------- > 2:  f46438f53e t/unit-tests: convert mem-pool test to use clar test framework\n> -:  ---------- > 3:  f5cabebd3a t/unit-tests: adapt priority queue test to use clar test framework\n> -:  ---------- > 4:  5323873612 t/unit-tests: convert reftable tree test to use clar test framework\n\nThe range-diff is still not correct :P Now it seems like you only passed\nthe first commit of your v2 to it, instead of the tip of the v2 branch.\n\nPatrick\n"},{"id":"510938","messageId":"CAOLa=ZQvW1fRv_BVAFYvj1u==TC4U+xgBMbVNH0ZNfnhqimfYw@mail.gmail.com","threadId":"62816","inReplyTo":"20250117122926.101749-3-kuforiji98@gmail.com","subject":"Re: [PATCH v3 2/4] t/unit-tests: convert mem-pool test to use clar test framework","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2025-01-20T10:18:42Z","receivedAt":"2025-01-20T10:18:43Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Seyi Kuforiji <kuforiji98@gmail.com> writes:\n\n> Adapt the mem-pool test script to use clar framework by using clar\n> assertions where necessary.Test functions are created as a standalone to\n\nNit: missing space post period. Rest of tha patch looks good!\n\n> test different test cases.\n\n[snip]\n"},{"id":"510939","messageId":"CAOLa=ZT=8V6uP7r-qf55772KEXmEj5H0xJWtsfGWt+Ptjb9YWA@mail.gmail.com","threadId":"62816","inReplyTo":"20250117122926.101749-4-kuforiji98@gmail.com","subject":"Re: [PATCH v3 3/4] t/unit-tests: adapt priority queue test to use clar test framework","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2025-01-20T10:22:07Z","receivedAt":"2025-01-20T10:22:09Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Seyi Kuforiji <kuforiji98@gmail.com> writes:\n\n> Convert the prio-queue test script to clar framework by using clar\n> assertions where necessary. Test functions are created as a standalone\n> to test different cases.\n>\n> update the type of the variable `j` from int to `size_t`, this ensures\n\nNit: s/update/Update\n\n> compatibility with the type used for result_size, which is also size_t,\n> preventing a potential warning or error caused by comparisons between\n> signed and unsigned integers.\n>\n\n[snip]\n"}]}