t/unit-tests: convert reftable tree test to use clar test framework

Adapts reftable tree test script to clar framework by using clar assertions where necessary. Mentored-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com> Acked-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Seyi Kuforiji committed Jan 17, 2025 at 13:29 UTC ffbd3f98f999102cab47fda4c992d7fa07e1d912
3 files changed +13 -21
Makefile
+1 -1
@@ -1340,6 +1340,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%
1340 CLAR_TEST_SUITES += u-ctype
1341 CLAR_TEST_SUITES += u-mem-pool
1342 CLAR_TEST_SUITES += u-prio-queue
1343 +CLAR_TEST_SUITES += u-reftable-tree
1344 CLAR_TEST_SUITES += u-strvec
1345 CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
1346 CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
@@ -1360,7 +1361,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader
1361 UNIT_TEST_PROGRAMS += t-reftable-readwrite
1362 UNIT_TEST_PROGRAMS += t-reftable-record
1363 UNIT_TEST_PROGRAMS += t-reftable-stack
1363 -UNIT_TEST_PROGRAMS += t-reftable-tree
1364 UNIT_TEST_PROGRAMS += t-strbuf
1365 UNIT_TEST_PROGRAMS += t-strcmp-offset
1366 UNIT_TEST_PROGRAMS += t-trailer
t/meson.build
+1 -1
@@ -2,6 +2,7 @@ clar_test_suites = [
2 'unit-tests/u-ctype.c',
3 'unit-tests/u-mem-pool.c',
4 'unit-tests/u-prio-queue.c',
5 + 'unit-tests/u-reftable-tree.c',
6 'unit-tests/u-strvec.c',
7 ]
8
@@ -56,7 +57,6 @@ unit_test_programs = [
57 'unit-tests/t-reftable-readwrite.c',
58 'unit-tests/t-reftable-record.c',
59 'unit-tests/t-reftable-stack.c',
59 - 'unit-tests/t-reftable-tree.c',
60 'unit-tests/t-strbuf.c',
61 'unit-tests/t-strcmp-offset.c',
62 'unit-tests/t-trailer.c',
t/unit-tests/u-reftable-tree.c renamed
+11 -19
@@ -6,7 +6,7 @@ license that can be found in the LICENSE file or at
6 https://developers.google.com/open-source/licenses/bsd
7 */
8
9 -#include "test-lib.h"
9 +#include "unit-test.h"
10 #include "reftable/tree.h"
11
12 static int t_compare(const void *a, const void *b)
@@ -25,7 +25,7 @@ static void store(void *arg, void *key)
25 c->arr[c->len++] = key;
26 }
27
28 -static void t_tree_search(void)
28 +void test_reftable_tree__tree_search(void)
29 {
30 struct tree_node *root = NULL;
31 void *values[11] = { 0 };
@@ -38,20 +38,20 @@ static void t_tree_search(void)
38 */
39 do {
40 nodes[i] = tree_insert(&root, &values[i], &t_compare);
41 - check(nodes[i] != NULL);
41 + cl_assert(nodes[i] != NULL);
42 i = (i * 7) % 11;
43 } while (i != 1);
44
45 for (i = 1; i < ARRAY_SIZE(nodes); i++) {
46 - check_pointer_eq(&values[i], nodes[i]->key);
47 - check_pointer_eq(nodes[i], tree_search(root, &values[i], &t_compare));
46 + cl_assert_equal_p(&values[i], nodes[i]->key);
47 + cl_assert_equal_p(nodes[i], tree_search(root, &values[i], &t_compare));
48 }
49
50 - check(!tree_search(root, values, t_compare));
50 + cl_assert(tree_search(root, values, t_compare) == NULL);
51 tree_free(root);
52 }
53
54 -static void t_infix_walk(void)
54 +void test_reftable_tree__infix_walk(void)
55 {
56 struct tree_node *root = NULL;
57 void *values[11] = { 0 };
@@ -64,23 +64,15 @@ static void t_infix_walk(void)
64
65 do {
66 struct tree_node *node = tree_insert(&root, &values[i], t_compare);
67 - check(node != NULL);
67 + cl_assert(node != NULL);
68 i = (i * 7) % 11;
69 count++;
70 } while (i != 1);
71
72 infix_walk(root, &store, &c);
73 for (i = 1; i < ARRAY_SIZE(values); i++)
74 - check_pointer_eq(&values[i], out[i - 1]);
75 - check(!out[i - 1]);
76 - check_int(c.len, ==, count);
74 + cl_assert_equal_p(&values[i], out[i - 1]);
75 + cl_assert(out[i - 1] == NULL);
76 + cl_assert_equal_i(c.len, count);
77 tree_free(root);
78 }
79 -
80 -int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
81 -{
82 - TEST(t_tree_search(), "tree_search works");
83 - TEST(t_infix_walk(), "infix_walk works");
84 -
85 - return test_done();
86 -}