In the recent codebase update (commit 8bf6fbd, 2023-12-09), a new unit testing framework written entirely in C was introduced to the Git project aimed at simplifying testing and reducing test run times. Currently, tests for the reftable refs-backend are performed by a custom testing framework defined by reftable/test_framework.{c, h}. Port reftable/tree_test.c to the unit testing framework and improve upon the ported test. The first patch in the series is preparatory cleanup, the second patch moves the test to the unit testing framework, and the rest of the patches improve upon the ported test. Mentored-by: Patrick Steinhardt <ps@xxxxxx> Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx> Signed-off-by: Chandra Pratap <chandrapratap3519@xxxxxxxxx> --- Changes in v2: - Add more context in the commit message of the third patch - Add an improvement patch for test_infix_walk() - Small refactor changes CI/PR: https://github.com/gitgitgadget/git/pull/1740 Chandra Pratap(5): reftable: remove unnecessary curly braces in t: move reftable/tree_test.c to the unit testing t-reftable-tree: split test_tree() into two sub-test t-reftable-tree: add test for non-existent key t-reftable-tree: improve the test for infix_walk() Makefile | 2 +- reftable/tree.c | 15 +++-------- reftable/tree_test.c | 60 ------------------------------- t/helper/test-reftable.c | 1 - t/unit-tests/t-reftable-tree.c | 76 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 72 deletions(-) Range-diff against v1: 1: 161d8892d6 ! 1: 542e497334 t-reftable-tree: split test_tree() into two sub-test functions @@ Commit message This improves the overall readability of the test file as well as simplifies debugging. + Note that the last parameter in the tree_search() functiom is + 'int insert' which when set, inserts the key if it is not found + in the tree. Otherwise, the function returns NULL for such cases. + Mentored-by: Patrick Steinhardt <ps@xxxxxx> Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx> Signed-off-by: Chandra Pratap <chandrapratap3519@xxxxxxxxx> @@ t/unit-tests/t-reftable-tree.c: static void check_increasing(void *arg, void *ke { struct tree_node *root = NULL; void *values[11] = { 0 }; + struct tree_node *nodes[11] = { 0 }; + size_t i = 1; +- struct curry c = { 0 }; + + do { + nodes[i] = tree_search(values + i, &root, &test_compare, 1); @@ t/unit-tests/t-reftable-tree.c: static void test_tree(void) check_pointer_eq(nodes[i], tree_search(values + i, &root, &test_compare, 0)); } @@ t/unit-tests/t-reftable-tree.c: static void test_tree(void) +static void test_infix_walk(void) +{ + struct tree_node *root = NULL; -+ void *values[13] = { 0 }; ++ void *values[11] = { 0 }; + struct curry c = { 0 }; + size_t i = 1; + + do { + tree_search(values + i, &root, &test_compare, 1); -+ i = (i * 5) % 13; ++ i = (i * 7) % 11; + } while (i != 1); + + infix_walk(root, &check_increasing, &c); 2: d649c4a193 = 2: c976a37cbc t-reftable-tree: add test for non-existent key -: ---------- > 3: 3010c8f01a t-reftable-tree: improve the test for infix_walk()