Skip to content

Commit 9bbc981

Browse files
Seyi007gitster
authored andcommitted
t/unit-tests: finalize migration of reftable-related tests
The old `lib-reftable.{c,h}` implemented helper functions for our homegrown unit-testing framework. As part of migrating reftable-related tests to the Clar framework, Clar-specific versions of these functions in `lib-reftable-clar.{c,h}` were introduced. Now that all test files using these helpers have been converted to Clar, we can safely remove the original `lib-reftable.{c,h}` and rename the Clar- specific versions back to `lib-reftable.{c,h}`. This restores a clean and consistent naming scheme for shared test utilities. Finally, update our build system to reflect the changes made and remove redundant code related to the reftable tests and our old homegrown unit-testing setup. `test-lib.{c,h}` remains unchanged in our build system as some files particularly `t/helper/test-example-tap.c` depends on it in order to run, and removing that would be beyond the scope of this patch. Signed-off-by: Seyi Kuforiji <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1cfd187 commit 9bbc981

15 files changed

+38
-179
lines changed

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,13 +1380,11 @@ CLAR_TEST_SUITES += u-urlmatch-normalization
13801380
CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
13811381
CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
13821382
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
1383-
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
13841383
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
1385-
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable-clar.o
1384+
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
1385+
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
13861386

1387-
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
13881387
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
1389-
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
13901388

13911389
# xdiff and reftable libs may in turn depend on what is in libgit.a
13921390
GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)

t/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ check-meson:
125125
@mkdir -p mesontmp && \
126126
printf "%s\n" \
127127
"integration_tests t[0-9][0-9][0-9][0-9]-*.sh" \
128-
"unit_test_programs unit-tests/t-*.c" \
129128
"clar_test_suites unit-tests/u-*.c" | \
130129
while read -r variable pattern; do \
131130
awk "/^$$variable = \[\$$/ {flag=1 ; next } /^]$$/ { flag=0 } flag { gsub(/^ \047/, \"\"); gsub(/\047,\$$/, \"\"); print }" meson.build >mesontmp/meson.txt && \

t/meson.build

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ clar_sources = [
2828
'unit-tests/clar/clar.c',
2929
'unit-tests/unit-test.c',
3030
'unit-tests/lib-oid.c',
31-
'unit-tests/lib-reftable-clar.c'
31+
'unit-tests/lib-reftable.c'
3232
]
3333

3434
clar_decls_h = custom_target(
@@ -62,25 +62,6 @@ clar_unit_tests = executable('unit-tests',
6262
)
6363
test('unit-tests', clar_unit_tests)
6464

65-
unit_test_programs = [
66-
]
67-
68-
foreach unit_test_program : unit_test_programs
69-
unit_test_name = fs.stem(unit_test_program)
70-
unit_test = executable(unit_test_name,
71-
sources: [
72-
'unit-tests/test-lib.c',
73-
'unit-tests/lib-reftable.c',
74-
unit_test_program,
75-
],
76-
dependencies: [libgit_commonmain],
77-
)
78-
test(unit_test_name, unit_test,
79-
workdir: meson.current_source_dir(),
80-
timeout: 0,
81-
)
82-
endforeach
83-
8465
subdir('helper')
8566

8667
integration_tests = [

t/unit-tests/lib-reftable-clar.c

Lines changed: 0 additions & 101 deletions
This file was deleted.

t/unit-tests/lib-reftable-clar.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

t/unit-tests/lib-reftable.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
#define DISABLE_SIGN_COMPARE_WARNINGS
2-
1+
#include "unit-test.h"
32
#include "lib-reftable.h"
4-
#include "test-lib.h"
3+
#include "hex.h"
4+
#include "parse-options.h"
55
#include "reftable/constants.h"
66
#include "reftable/writer.h"
77
#include "strbuf.h"
8+
#include "string-list.h"
9+
#include "strvec.h"
810

9-
void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
11+
void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
1012
{
1113
memset(p, (uint8_t)i, hash_size(id));
1214
}
@@ -22,17 +24,17 @@ static int strbuf_writer_flush(void *arg UNUSED)
2224
return 0;
2325
}
2426

25-
struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
27+
struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
2628
struct reftable_write_options *opts)
2729
{
2830
struct reftable_writer *writer;
2931
int ret = reftable_writer_new(&writer, &strbuf_writer_write, &strbuf_writer_flush,
3032
buf, opts);
31-
check(!ret);
33+
cl_assert(!ret);
3234
return writer;
3335
}
3436

35-
void t_reftable_write_to_buf(struct reftable_buf *buf,
37+
void cl_reftable_write_to_buf(struct reftable_buf *buf,
3638
struct reftable_ref_record *refs,
3739
size_t nrefs,
3840
struct reftable_log_record *logs,
@@ -64,35 +66,36 @@ void t_reftable_write_to_buf(struct reftable_buf *buf,
6466
min = ui;
6567
}
6668

67-
writer = t_reftable_strbuf_writer(buf, &opts);
68-
reftable_writer_set_limits(writer, min, max);
69+
writer = cl_reftable_strbuf_writer(buf, &opts);
70+
ret = reftable_writer_set_limits(writer, min, max);
71+
cl_assert(!ret);
6972

7073
if (nrefs) {
7174
ret = reftable_writer_add_refs(writer, refs, nrefs);
72-
check_int(ret, ==, 0);
75+
cl_assert_equal_i(ret, 0);
7376
}
7477

7578
if (nlogs) {
7679
ret = reftable_writer_add_logs(writer, logs, nlogs);
77-
check_int(ret, ==, 0);
80+
cl_assert_equal_i(ret, 0);
7881
}
7982

8083
ret = reftable_writer_close(writer);
81-
check_int(ret, ==, 0);
84+
cl_assert_equal_i(ret, 0);
8285

8386
stats = reftable_writer_stats(writer);
84-
for (size_t i = 0; i < stats->ref_stats.blocks; i++) {
87+
for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++) {
8588
size_t off = i * (opts.block_size ? opts.block_size
8689
: DEFAULT_BLOCK_SIZE);
8790
if (!off)
8891
off = header_size(opts.hash_id == REFTABLE_HASH_SHA256 ? 2 : 1);
89-
check_char(buf->buf[off], ==, 'r');
92+
cl_assert(buf->buf[off] == 'r');
9093
}
9194

9295
if (nrefs)
93-
check_int(stats->ref_stats.blocks, >, 0);
96+
cl_assert(stats->ref_stats.blocks > 0);
9497
if (nlogs)
95-
check_int(stats->log_stats.blocks, >, 0);
98+
cl_assert(stats->log_stats.blocks > 0);
9699

97100
reftable_writer_free(writer);
98101
}

t/unit-tests/lib-reftable.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
#ifndef LIB_REFTABLE_H
2-
#define LIB_REFTABLE_H
3-
1+
#include "git-compat-util.h"
2+
#include "clar/clar.h"
3+
#include "clar-decls.h"
44
#include "git-compat-util.h"
55
#include "reftable/reftable-writer.h"
6+
#include "strbuf.h"
67

78
struct reftable_buf;
89

9-
void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
10+
void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
1011

11-
struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
12+
struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
1213
struct reftable_write_options *opts);
1314

14-
void t_reftable_write_to_buf(struct reftable_buf *buf,
15+
void cl_reftable_write_to_buf(struct reftable_buf *buf,
1516
struct reftable_ref_record *refs,
1617
size_t nrecords,
1718
struct reftable_log_record *logs,
1819
size_t nlogs,
1920
struct reftable_write_options *opts);
20-
21-
#endif

t/unit-tests/u-reftable-basics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license that can be found in the LICENSE file or at
77
*/
88

99
#include "unit-test.h"
10-
#include "lib-reftable-clar.h"
10+
#include "lib-reftable.h"
1111
#include "reftable/basics.h"
1212

1313
struct integer_needle_lesseq_args {

t/unit-tests/u-reftable-block.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license that can be found in the LICENSE file or at
77
*/
88

99
#include "unit-test.h"
10-
#include "lib-reftable-clar.h"
10+
#include "lib-reftable.h"
1111
#include "reftable/block.h"
1212
#include "reftable/blocksource.h"
1313
#include "reftable/constants.h"

t/unit-tests/u-reftable-merged.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license that can be found in the LICENSE file or at
77
*/
88

99
#include "unit-test.h"
10-
#include "lib-reftable-clar.h"
10+
#include "lib-reftable.h"
1111
#include "reftable/blocksource.h"
1212
#include "reftable/constants.h"
1313
#include "reftable/merged.h"

0 commit comments

Comments
 (0)