mbox series

[GSoC,v3,0/5] t: port reftable/tree_test.c to the unit testing framework

Message ID 20240612130217.8877-1-chandrapratap3519@gmail.com (mailing list archive)
Headers show
Series t: port reftable/tree_test.c to the unit testing framework | expand

Message

Chandra Pratap June 12, 2024, 12:52 p.m. UTC
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@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>

---
Changes in v3:
- Fix a typo in the commit message of the fifth patch
- Add a check for number of input & output elements in the fifth patch
- 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, 86 insertions(+), 72 deletions(-)

Range-diff against v2:
1:  3010c8f01a ! 1:  44800ad205 t-reftable-tree: improve the test for infix_walk()
    @@ Commit message
         In the current testing setup for infix_walk(), the following
         properties of an infix traversal of a tree remain untested:
         - every node of the tree must be visited
    -    - every node must be visited exactly only
    -    and only the property 'traversal in increasing order' is tested.
    +    - every node must be visited exactly once
    +    In fact, only the property 'traversal in increasing order' is tested.
         Modify test_infix_walk() to check for all the properties above.

         This can be achieved by storing the nodes' keys linearly, in a nullified
    @@ t/unit-tests/t-reftable-tree.c: static int test_compare(const void *a, const voi
      struct curry {
     -	void *last;
     +	void **arr;
    -+	size_t i;
    ++	size_t len;
      };

     -static void check_increasing(void *arg, void *key)
    @@ t/unit-tests/t-reftable-tree.c: static int test_compare(const void *a, const voi
     -	if (c->last)
     -		check_int(test_compare(c->last, key), <, 0);
     -	c->last = key;
    -+	c->arr[c->i++] = key;
    ++	c->arr[c->len++] = key;
      }

      static void test_tree_search(void)
    @@ t/unit-tests/t-reftable-tree.c: static void test_infix_walk(void)
      {
      	struct tree_node *root = NULL;
      	void *values[11] = { 0 };
    -+	void *out[20] = { 0 };
    - 	struct curry c = { 0 };
    +-	struct curry c = { 0 };
    ++	void *out[11] = { 0 };
    ++	struct curry c = {
    ++		.arr = (void **) &out,
    ++	};
      	size_t i = 1;
    ++	size_t count = 0;

    -@@ t/unit-tests/t-reftable-tree.c: static void test_infix_walk(void)
    + 	do {
    + 		tree_search(values + i, &root, &test_compare, 1);
      		i = (i * 7) % 11;
    ++		count++;
      	} while (i != 1);

     -	infix_walk(root, &check_increasing, &c);
    -+	c.arr = (void **) &out;
     +	infix_walk(root, &store, &c);
     +	for (i = 1; i < ARRAY_SIZE(values); i++)
     +		check_pointer_eq(values + i, out[i - 1]);
    -+	check(!out[i]);
    ++	check(!out[i - 1]);
    ++	check_int(c.len, ==, count);
      	tree_free(root);
      }