Skip to content

Commit ffbd3f9

Browse files
Seyi007gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Seyi Kuforiji <[email protected]> Acked-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8b702f9 commit ffbd3f9

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%
13401340
CLAR_TEST_SUITES += u-ctype
13411341
CLAR_TEST_SUITES += u-mem-pool
13421342
CLAR_TEST_SUITES += u-prio-queue
1343+
CLAR_TEST_SUITES += u-reftable-tree
13431344
CLAR_TEST_SUITES += u-strvec
13441345
CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
13451346
CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
@@ -1360,7 +1361,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader
13601361
UNIT_TEST_PROGRAMS += t-reftable-readwrite
13611362
UNIT_TEST_PROGRAMS += t-reftable-record
13621363
UNIT_TEST_PROGRAMS += t-reftable-stack
1363-
UNIT_TEST_PROGRAMS += t-reftable-tree
13641364
UNIT_TEST_PROGRAMS += t-strbuf
13651365
UNIT_TEST_PROGRAMS += t-strcmp-offset
13661366
UNIT_TEST_PROGRAMS += t-trailer

t/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ clar_test_suites = [
22
'unit-tests/u-ctype.c',
33
'unit-tests/u-mem-pool.c',
44
'unit-tests/u-prio-queue.c',
5+
'unit-tests/u-reftable-tree.c',
56
'unit-tests/u-strvec.c',
67
]
78

@@ -56,7 +57,6 @@ unit_test_programs = [
5657
'unit-tests/t-reftable-readwrite.c',
5758
'unit-tests/t-reftable-record.c',
5859
'unit-tests/t-reftable-stack.c',
59-
'unit-tests/t-reftable-tree.c',
6060
'unit-tests/t-strbuf.c',
6161
'unit-tests/t-strcmp-offset.c',
6262
'unit-tests/t-trailer.c',

t/unit-tests/t-reftable-tree.c renamed to t/unit-tests/u-reftable-tree.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ license that can be found in the LICENSE file or at
66
https://developers.google.com/open-source/licenses/bsd
77
*/
88

9-
#include "test-lib.h"
9+
#include "unit-test.h"
1010
#include "reftable/tree.h"
1111

1212
static int t_compare(const void *a, const void *b)
@@ -25,7 +25,7 @@ static void store(void *arg, void *key)
2525
c->arr[c->len++] = key;
2626
}
2727

28-
static void t_tree_search(void)
28+
void test_reftable_tree__tree_search(void)
2929
{
3030
struct tree_node *root = NULL;
3131
void *values[11] = { 0 };
@@ -38,20 +38,20 @@ static void t_tree_search(void)
3838
*/
3939
do {
4040
nodes[i] = tree_insert(&root, &values[i], &t_compare);
41-
check(nodes[i] != NULL);
41+
cl_assert(nodes[i] != NULL);
4242
i = (i * 7) % 11;
4343
} while (i != 1);
4444

4545
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));
4848
}
4949

50-
check(!tree_search(root, values, t_compare));
50+
cl_assert(tree_search(root, values, t_compare) == NULL);
5151
tree_free(root);
5252
}
5353

54-
static void t_infix_walk(void)
54+
void test_reftable_tree__infix_walk(void)
5555
{
5656
struct tree_node *root = NULL;
5757
void *values[11] = { 0 };
@@ -64,23 +64,15 @@ static void t_infix_walk(void)
6464

6565
do {
6666
struct tree_node *node = tree_insert(&root, &values[i], t_compare);
67-
check(node != NULL);
67+
cl_assert(node != NULL);
6868
i = (i * 7) % 11;
6969
count++;
7070
} while (i != 1);
7171

7272
infix_walk(root, &store, &c);
7373
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);
7777
tree_free(root);
7878
}
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-
}

0 commit comments

Comments
 (0)