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>
This commit is contained in:
committed by
Junio C Hamano
parent
8b702f93dd
commit
ffbd3f98f9
2
Makefile
2
Makefile
@@ -1340,6 +1340,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%
|
|||||||
CLAR_TEST_SUITES += u-ctype
|
CLAR_TEST_SUITES += u-ctype
|
||||||
CLAR_TEST_SUITES += u-mem-pool
|
CLAR_TEST_SUITES += u-mem-pool
|
||||||
CLAR_TEST_SUITES += u-prio-queue
|
CLAR_TEST_SUITES += u-prio-queue
|
||||||
|
CLAR_TEST_SUITES += u-reftable-tree
|
||||||
CLAR_TEST_SUITES += u-strvec
|
CLAR_TEST_SUITES += u-strvec
|
||||||
CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
|
CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
|
||||||
CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
|
CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
|
||||||
@@ -1360,7 +1361,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader
|
|||||||
UNIT_TEST_PROGRAMS += t-reftable-readwrite
|
UNIT_TEST_PROGRAMS += t-reftable-readwrite
|
||||||
UNIT_TEST_PROGRAMS += t-reftable-record
|
UNIT_TEST_PROGRAMS += t-reftable-record
|
||||||
UNIT_TEST_PROGRAMS += t-reftable-stack
|
UNIT_TEST_PROGRAMS += t-reftable-stack
|
||||||
UNIT_TEST_PROGRAMS += t-reftable-tree
|
|
||||||
UNIT_TEST_PROGRAMS += t-strbuf
|
UNIT_TEST_PROGRAMS += t-strbuf
|
||||||
UNIT_TEST_PROGRAMS += t-strcmp-offset
|
UNIT_TEST_PROGRAMS += t-strcmp-offset
|
||||||
UNIT_TEST_PROGRAMS += t-trailer
|
UNIT_TEST_PROGRAMS += t-trailer
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ clar_test_suites = [
|
|||||||
'unit-tests/u-ctype.c',
|
'unit-tests/u-ctype.c',
|
||||||
'unit-tests/u-mem-pool.c',
|
'unit-tests/u-mem-pool.c',
|
||||||
'unit-tests/u-prio-queue.c',
|
'unit-tests/u-prio-queue.c',
|
||||||
|
'unit-tests/u-reftable-tree.c',
|
||||||
'unit-tests/u-strvec.c',
|
'unit-tests/u-strvec.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -56,7 +57,6 @@ unit_test_programs = [
|
|||||||
'unit-tests/t-reftable-readwrite.c',
|
'unit-tests/t-reftable-readwrite.c',
|
||||||
'unit-tests/t-reftable-record.c',
|
'unit-tests/t-reftable-record.c',
|
||||||
'unit-tests/t-reftable-stack.c',
|
'unit-tests/t-reftable-stack.c',
|
||||||
'unit-tests/t-reftable-tree.c',
|
|
||||||
'unit-tests/t-strbuf.c',
|
'unit-tests/t-strbuf.c',
|
||||||
'unit-tests/t-strcmp-offset.c',
|
'unit-tests/t-strcmp-offset.c',
|
||||||
'unit-tests/t-trailer.c',
|
'unit-tests/t-trailer.c',
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ license that can be found in the LICENSE file or at
|
|||||||
https://developers.google.com/open-source/licenses/bsd
|
https://developers.google.com/open-source/licenses/bsd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "test-lib.h"
|
#include "unit-test.h"
|
||||||
#include "reftable/tree.h"
|
#include "reftable/tree.h"
|
||||||
|
|
||||||
static int t_compare(const void *a, const void *b)
|
static int t_compare(const void *a, const void *b)
|
||||||
@@ -25,7 +25,7 @@ static void store(void *arg, void *key)
|
|||||||
c->arr[c->len++] = key;
|
c->arr[c->len++] = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void t_tree_search(void)
|
void test_reftable_tree__tree_search(void)
|
||||||
{
|
{
|
||||||
struct tree_node *root = NULL;
|
struct tree_node *root = NULL;
|
||||||
void *values[11] = { 0 };
|
void *values[11] = { 0 };
|
||||||
@@ -38,20 +38,20 @@ static void t_tree_search(void)
|
|||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
nodes[i] = tree_insert(&root, &values[i], &t_compare);
|
nodes[i] = tree_insert(&root, &values[i], &t_compare);
|
||||||
check(nodes[i] != NULL);
|
cl_assert(nodes[i] != NULL);
|
||||||
i = (i * 7) % 11;
|
i = (i * 7) % 11;
|
||||||
} while (i != 1);
|
} while (i != 1);
|
||||||
|
|
||||||
for (i = 1; i < ARRAY_SIZE(nodes); i++) {
|
for (i = 1; i < ARRAY_SIZE(nodes); i++) {
|
||||||
check_pointer_eq(&values[i], nodes[i]->key);
|
cl_assert_equal_p(&values[i], nodes[i]->key);
|
||||||
check_pointer_eq(nodes[i], tree_search(root, &values[i], &t_compare));
|
cl_assert_equal_p(nodes[i], tree_search(root, &values[i], &t_compare));
|
||||||
}
|
}
|
||||||
|
|
||||||
check(!tree_search(root, values, t_compare));
|
cl_assert(tree_search(root, values, t_compare) == NULL);
|
||||||
tree_free(root);
|
tree_free(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void t_infix_walk(void)
|
void test_reftable_tree__infix_walk(void)
|
||||||
{
|
{
|
||||||
struct tree_node *root = NULL;
|
struct tree_node *root = NULL;
|
||||||
void *values[11] = { 0 };
|
void *values[11] = { 0 };
|
||||||
@@ -64,23 +64,15 @@ static void t_infix_walk(void)
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
struct tree_node *node = tree_insert(&root, &values[i], t_compare);
|
struct tree_node *node = tree_insert(&root, &values[i], t_compare);
|
||||||
check(node != NULL);
|
cl_assert(node != NULL);
|
||||||
i = (i * 7) % 11;
|
i = (i * 7) % 11;
|
||||||
count++;
|
count++;
|
||||||
} while (i != 1);
|
} while (i != 1);
|
||||||
|
|
||||||
infix_walk(root, &store, &c);
|
infix_walk(root, &store, &c);
|
||||||
for (i = 1; i < ARRAY_SIZE(values); i++)
|
for (i = 1; i < ARRAY_SIZE(values); i++)
|
||||||
check_pointer_eq(&values[i], out[i - 1]);
|
cl_assert_equal_p(&values[i], out[i - 1]);
|
||||||
check(!out[i - 1]);
|
cl_assert(out[i - 1] == NULL);
|
||||||
check_int(c.len, ==, count);
|
cl_assert_equal_i(c.len, count);
|
||||||
tree_free(root);
|
tree_free(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
|
||||||
{
|
|
||||||
TEST(t_tree_search(), "tree_search works");
|
|
||||||
TEST(t_infix_walk(), "infix_walk works");
|
|
||||||
|
|
||||||
return test_done();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user