Git fork

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>

authored by

Seyi Kuforiji and committed by
Junio C Hamano
ffbd3f98 8b702f93

+13 -21
+1 -1
Makefile
··· 1340 1340 CLAR_TEST_SUITES += u-ctype 1341 1341 CLAR_TEST_SUITES += u-mem-pool 1342 1342 CLAR_TEST_SUITES += u-prio-queue 1343 + CLAR_TEST_SUITES += u-reftable-tree 1343 1344 CLAR_TEST_SUITES += u-strvec 1344 1345 CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X) 1345 1346 CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES)) ··· 1360 1361 UNIT_TEST_PROGRAMS += t-reftable-readwrite 1361 1362 UNIT_TEST_PROGRAMS += t-reftable-record 1362 1363 UNIT_TEST_PROGRAMS += t-reftable-stack 1363 - UNIT_TEST_PROGRAMS += t-reftable-tree 1364 1364 UNIT_TEST_PROGRAMS += t-strbuf 1365 1365 UNIT_TEST_PROGRAMS += t-strcmp-offset 1366 1366 UNIT_TEST_PROGRAMS += t-trailer
+1 -1
t/meson.build
··· 2 2 'unit-tests/u-ctype.c', 3 3 'unit-tests/u-mem-pool.c', 4 4 'unit-tests/u-prio-queue.c', 5 + 'unit-tests/u-reftable-tree.c', 5 6 'unit-tests/u-strvec.c', 6 7 ] 7 8 ··· 56 57 'unit-tests/t-reftable-readwrite.c', 57 58 'unit-tests/t-reftable-record.c', 58 59 'unit-tests/t-reftable-stack.c', 59 - 'unit-tests/t-reftable-tree.c', 60 60 'unit-tests/t-strbuf.c', 61 61 'unit-tests/t-strcmp-offset.c', 62 62 'unit-tests/t-trailer.c',
+11 -19
t/unit-tests/t-reftable-tree.c t/unit-tests/u-reftable-tree.c
··· 6 6 https://developers.google.com/open-source/licenses/bsd 7 7 */ 8 8 9 - #include "test-lib.h" 9 + #include "unit-test.h" 10 10 #include "reftable/tree.h" 11 11 12 12 static int t_compare(const void *a, const void *b) ··· 25 25 c->arr[c->len++] = key; 26 26 } 27 27 28 - static void t_tree_search(void) 28 + void test_reftable_tree__tree_search(void) 29 29 { 30 30 struct tree_node *root = NULL; 31 31 void *values[11] = { 0 }; ··· 38 38 */ 39 39 do { 40 40 nodes[i] = tree_insert(&root, &values[i], &t_compare); 41 - check(nodes[i] != NULL); 41 + cl_assert(nodes[i] != NULL); 42 42 i = (i * 7) % 11; 43 43 } while (i != 1); 44 44 45 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 48 } 49 49 50 - check(!tree_search(root, values, t_compare)); 50 + cl_assert(tree_search(root, values, t_compare) == NULL); 51 51 tree_free(root); 52 52 } 53 53 54 - static void t_infix_walk(void) 54 + void test_reftable_tree__infix_walk(void) 55 55 { 56 56 struct tree_node *root = NULL; 57 57 void *values[11] = { 0 }; ··· 64 64 65 65 do { 66 66 struct tree_node *node = tree_insert(&root, &values[i], t_compare); 67 - check(node != NULL); 67 + cl_assert(node != NULL); 68 68 i = (i * 7) % 11; 69 69 count++; 70 70 } while (i != 1); 71 71 72 72 infix_walk(root, &store, &c); 73 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 77 tree_free(root); 78 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 - }