Subject: [PATCH v5 1/5] t/unit-tests: convert reftable table test to use clar

From: Seyi Kufoiji <[email-masked]>
Date: Thu, 24 Jul 2025 14:28:09 +0100

From: Seyi Kuforiji <[email-masked]>

Adapt reftable table test file to use clar by using clar assertions
where necessary.

Signed-off-by: Seyi Kuforiji <[email-masked]>
Signed-off-by: Junio C Hamano <[email-masked]>
---
 Makefile                                      |  4 +-
 t/meson.build                                 |  5 +-
 ...{t-reftable-table.c => u-reftable-table.c} | 75 +++++++++----------
 3 files changed, 39 insertions(+), 45 deletions(-)
 rename t/unit-tests/{t-reftable-table.c => u-reftable-table.c} (75%)

diff --git a/Makefile b/Makefile
index 3cccc73073..0227fdb3e1 100644
--- a/Makefile
+++ b/Makefile
@@ -1368,6 +1368,7 @@ CLAR_TEST_SUITES += u-reftable-basics
 CLAR_TEST_SUITES += u-reftable-block
 CLAR_TEST_SUITES += u-reftable-merged
 CLAR_TEST_SUITES += u-reftable-pq
+CLAR_TEST_SUITES += u-reftable-table
 CLAR_TEST_SUITES += u-reftable-tree
 CLAR_TEST_SUITES += u-strbuf
 CLAR_TEST_SUITES += u-strcmp-offset
@@ -1384,7 +1385,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable-clar.o
 UNIT_TEST_PROGRAMS += t-reftable-readwrite
 UNIT_TEST_PROGRAMS += t-reftable-record
 UNIT_TEST_PROGRAMS += t-reftable-stack
-UNIT_TEST_PROGRAMS += t-reftable-table
 UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
 UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
 UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
@@ -3972,4 +3972,4 @@ $(LIBGIT_HIDDEN_EXPORT): $(LIBGIT_PARTIAL_EXPORT)
 	$(OBJCOPY) --localize-hidden $^ $@
 
 contrib/libgit-sys/libgitpub.a: $(LIBGIT_HIDDEN_EXPORT)
-	$(AR) $(ARFLAGS) $@ $^
+	$(AR) $(ARFLAGS) $@ $^
\ No newline at end of file
diff --git a/t/meson.build b/t/meson.build
index ac4394b7a2..46d3a8580b 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -12,6 +12,7 @@ clar_test_suites = [
   'unit-tests/u-reftable-block.c',
   'unit-tests/u-reftable-merged.c',
   'unit-tests/u-reftable-pq.c',
+  'unit-tests/u-reftable-table.c',
   'unit-tests/u-reftable-tree.c',
   'unit-tests/u-strbuf.c',
   'unit-tests/u-strcmp-offset.c',
@@ -59,11 +60,9 @@ clar_unit_tests = executable('unit-tests',
 test('unit-tests', clar_unit_tests)
 
 unit_test_programs = [
-  'unit-tests/t-reftable-reader.c',
   'unit-tests/t-reftable-readwrite.c',
   'unit-tests/t-reftable-record.c',
   'unit-tests/t-reftable-stack.c',
-  'unit-tests/t-reftable-table.c',
 ]
 
 foreach unit_test_program : unit_test_programs
@@ -1233,4 +1232,4 @@ if perl.found() and time.found()
       timeout: 0,
     )
   endforeach
-endif
+endif
\ No newline at end of file
diff --git a/t/unit-tests/t-reftable-table.c b/t/unit-tests/u-reftable-table.c
similarity index 75%
rename from t/unit-tests/t-reftable-table.c
rename to t/unit-tests/u-reftable-table.c
index 7e1eb533d0..839107d8a4 100644
--- a/t/unit-tests/t-reftable-table.c
+++ b/t/unit-tests/u-reftable-table.c
@@ -1,12 +1,12 @@
-#include "test-lib.h"
-#include "lib-reftable.h"
+#include "unit-test.h"
+#include "lib-reftable-clar.h"
 #include "reftable/blocksource.h"
 #include "reftable/constants.h"
 #include "reftable/iter.h"
 #include "reftable/table.h"
 #include "strbuf.h"
 
-static int t_table_seek_once(void)
+void test_reftable_table__seek_once(void)
 {
 	struct reftable_ref_record records[] = {
 		{
@@ -22,32 +22,32 @@ static int t_table_seek_once(void)
 	struct reftable_buf buf = REFTABLE_BUF_INIT;
 	int ret;
 
-	t_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
+	cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
 	block_source_from_buf(&source, &buf);
 
 	ret = reftable_table_new(&table, &source, "name");
-	check(!ret);
+	cl_assert(!ret);
 
 	reftable_table_init_ref_iterator(table, &it);
 	ret = reftable_iterator_seek_ref(&it, "");
-	check(!ret);
+	cl_assert(!ret);
 	ret = reftable_iterator_next_ref(&it, &ref);
-	check(!ret);
+	cl_assert(!ret);
 
-	ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
-	check_int(ret, ==, 1);
+	ret = reftable_ref_record_equal(&ref, &records[0],
+					REFTABLE_HASH_SIZE_SHA1);
+	cl_assert_equal_i(ret, 1);
 
 	ret = reftable_iterator_next_ref(&it, &ref);
-	check_int(ret, ==, 1);
+	cl_assert_equal_i(ret, 1);
 
 	reftable_ref_record_release(&ref);
 	reftable_iterator_destroy(&it);
 	reftable_table_decref(table);
 	reftable_buf_release(&buf);
-	return 0;
 }
 
-static int t_table_reseek(void)
+void test_reftable_table__reseek(void)
 {
 	struct reftable_ref_record records[] = {
 		{
@@ -63,35 +63,35 @@ static int t_table_reseek(void)
 	struct reftable_buf buf = REFTABLE_BUF_INIT;
 	int ret;
 
-	t_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
+	cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records),
+				 NULL, 0, NULL);
 	block_source_from_buf(&source, &buf);
 
 	ret = reftable_table_new(&table, &source, "name");
-	check(!ret);
+	cl_assert(!ret);
 
 	reftable_table_init_ref_iterator(table, &it);
 
 	for (size_t i = 0; i < 5; i++) {
 		ret = reftable_iterator_seek_ref(&it, "");
-		check(!ret);
+		cl_assert(!ret);
 		ret = reftable_iterator_next_ref(&it, &ref);
-		check(!ret);
+		cl_assert(!ret);
 
 		ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
-		check_int(ret, ==, 1);
+		cl_assert_equal_i(ret, 1);
 
 		ret = reftable_iterator_next_ref(&it, &ref);
-		check_int(ret, ==, 1);
+		cl_assert_equal_i(ret, 1);
 	}
 
 	reftable_ref_record_release(&ref);
 	reftable_iterator_destroy(&it);
 	reftable_table_decref(table);
 	reftable_buf_release(&buf);
-	return 0;
 }
 
-static int t_table_block_iterator(void)
+void test_reftable_table__block_iterator(void)
 {
 	struct reftable_block_source source = { 0 };
 	struct reftable_table_iterator it = { 0 };
@@ -147,14 +147,14 @@ static int t_table_block_iterator(void)
 					     (uintmax_t) i);
 	}
 
-	t_reftable_write_to_buf(&buf, records, nrecords, NULL, 0, NULL);
+	cl_reftable_write_to_buf(&buf, records, nrecords, NULL, 0, NULL);
 	block_source_from_buf(&source, &buf);
 
 	ret = reftable_table_new(&table, &source, "name");
-	check(!ret);
+	cl_assert(!ret);
 
 	ret = reftable_table_iterator_init(&it, table);
-	check(!ret);
+	cl_assert(!ret);
 
 	for (size_t i = 0; i < ARRAY_SIZE(expected_blocks); i++) {
 		struct reftable_iterator record_it = { 0 };
@@ -163,22 +163,26 @@ static int t_table_block_iterator(void)
 		};
 
 		ret = reftable_table_iterator_next(&it, &block);
-		check(!ret);
+		cl_assert(!ret);
 
-		check_int(block->block_type, ==, expected_blocks[i].block_type);
-		check_int(block->header_off, ==, expected_blocks[i].header_off);
-		check_int(block->restart_count, ==, expected_blocks[i].restart_count);
+		cl_assert_equal_i(block->block_type,
+				  expected_blocks[i].block_type);
+		cl_assert_equal_i(block->header_off,
+				  expected_blocks[i].header_off);
+		cl_assert_equal_i(block->restart_count,
+				  expected_blocks[i].restart_count);
 
 		ret = reftable_block_init_iterator(block, &record_it);
-		check(!ret);
+		cl_assert(!ret);
 
 		for (size_t j = 0; ; j++) {
 			ret = iterator_next(&record_it, &record);
 			if (ret > 0) {
-				check_int(j, ==, expected_blocks[i].record_count);
+				cl_assert_equal_i(j,
+						  expected_blocks[i].record_count);
 				break;
 			}
-			check(!ret);
+			cl_assert(!ret);
 		}
 
 		reftable_iterator_destroy(&record_it);
@@ -186,7 +190,7 @@ static int t_table_block_iterator(void)
 	}
 
 	ret = reftable_table_iterator_next(&it, &block);
-	check_int(ret, ==, 1);
+	cl_assert_equal_i(ret, 1);
 
 	for (size_t i = 0; i < nrecords; i++)
 		reftable_free(records[i].refname);
@@ -194,13 +198,4 @@ static int t_table_block_iterator(void)
 	reftable_table_decref(table);
 	reftable_buf_release(&buf);
 	reftable_free(records);
-	return 0;
-}
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
-	TEST(t_table_seek_once(), "table can seek once");
-	TEST(t_table_reseek(), "table can reseek multiple times");
-	TEST(t_table_block_iterator(), "table can iterate through blocks");
-	return test_done();
 }
-- 
2.43.0