Git fork

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 <kuforiji98@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Seyi Kuforiji and committed by
Junio C Hamano
9bbc981c 1cfd187f

+38 -179
+2 -4
Makefile
··· 1380 1380 CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X) 1381 1381 CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES)) 1382 1382 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o 1383 - CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o 1384 1383 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 1386 1386 1387 - UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS)) 1388 1387 UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o 1389 - UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o 1390 1388 1391 1389 # xdiff and reftable libs may in turn depend on what is in libgit.a 1392 1390 GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)
-1
t/Makefile
··· 125 125 @mkdir -p mesontmp && \ 126 126 printf "%s\n" \ 127 127 "integration_tests t[0-9][0-9][0-9][0-9]-*.sh" \ 128 - "unit_test_programs unit-tests/t-*.c" \ 129 128 "clar_test_suites unit-tests/u-*.c" | \ 130 129 while read -r variable pattern; do \ 131 130 awk "/^$$variable = \[\$$/ {flag=1 ; next } /^]$$/ { flag=0 } flag { gsub(/^ \047/, \"\"); gsub(/\047,\$$/, \"\"); print }" meson.build >mesontmp/meson.txt && \
+1 -20
t/meson.build
··· 28 28 'unit-tests/clar/clar.c', 29 29 'unit-tests/unit-test.c', 30 30 'unit-tests/lib-oid.c', 31 - 'unit-tests/lib-reftable-clar.c' 31 + 'unit-tests/lib-reftable.c' 32 32 ] 33 33 34 34 clar_decls_h = custom_target( ··· 61 61 dependencies: [libgit_commonmain], 62 62 ) 63 63 test('unit-tests', clar_unit_tests) 64 - 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 64 84 65 subdir('helper') 85 66
-101
t/unit-tests/lib-reftable-clar.c
··· 1 - #include "unit-test.h" 2 - #include "lib-reftable-clar.h" 3 - #include "hex.h" 4 - #include "parse-options.h" 5 - #include "reftable/constants.h" 6 - #include "reftable/writer.h" 7 - #include "strbuf.h" 8 - #include "string-list.h" 9 - #include "strvec.h" 10 - 11 - void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id) 12 - { 13 - memset(p, (uint8_t)i, hash_size(id)); 14 - } 15 - 16 - static ssize_t strbuf_writer_write(void *b, const void *data, size_t sz) 17 - { 18 - strbuf_add(b, data, sz); 19 - return sz; 20 - } 21 - 22 - static int strbuf_writer_flush(void *arg UNUSED) 23 - { 24 - return 0; 25 - } 26 - 27 - struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf, 28 - struct reftable_write_options *opts) 29 - { 30 - struct reftable_writer *writer; 31 - int ret = reftable_writer_new(&writer, &strbuf_writer_write, &strbuf_writer_flush, 32 - buf, opts); 33 - cl_assert(!ret); 34 - return writer; 35 - } 36 - 37 - void cl_reftable_write_to_buf(struct reftable_buf *buf, 38 - struct reftable_ref_record *refs, 39 - size_t nrefs, 40 - struct reftable_log_record *logs, 41 - size_t nlogs, 42 - struct reftable_write_options *_opts) 43 - { 44 - struct reftable_write_options opts = { 0 }; 45 - const struct reftable_stats *stats; 46 - struct reftable_writer *writer; 47 - uint64_t min = 0xffffffff; 48 - uint64_t max = 0; 49 - int ret; 50 - 51 - if (_opts) 52 - opts = *_opts; 53 - 54 - for (size_t i = 0; i < nrefs; i++) { 55 - uint64_t ui = refs[i].update_index; 56 - if (ui > max) 57 - max = ui; 58 - if (ui < min) 59 - min = ui; 60 - } 61 - for (size_t i = 0; i < nlogs; i++) { 62 - uint64_t ui = logs[i].update_index; 63 - if (ui > max) 64 - max = ui; 65 - if (ui < min) 66 - min = ui; 67 - } 68 - 69 - writer = cl_reftable_strbuf_writer(buf, &opts); 70 - ret = reftable_writer_set_limits(writer, min, max); 71 - cl_assert_equal_i(ret, 0); 72 - 73 - if (nrefs) { 74 - ret = reftable_writer_add_refs(writer, refs, nrefs); 75 - cl_assert_equal_i(ret, 0); 76 - } 77 - 78 - if (nlogs) { 79 - ret = reftable_writer_add_logs(writer, logs, nlogs); 80 - cl_assert_equal_i(ret, 0); 81 - } 82 - 83 - ret = reftable_writer_close(writer); 84 - cl_assert_equal_i(ret, 0); 85 - 86 - stats = reftable_writer_stats(writer); 87 - for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++) { 88 - size_t off = i * (opts.block_size ? opts.block_size 89 - : DEFAULT_BLOCK_SIZE); 90 - if (!off) 91 - off = header_size(opts.hash_id == REFTABLE_HASH_SHA256 ? 2 : 1); 92 - cl_assert(buf->buf[off] == 'r'); 93 - } 94 - 95 - if (nrefs) 96 - cl_assert(stats->ref_stats.blocks > 0); 97 - if (nlogs) 98 - cl_assert(stats->log_stats.blocks > 0); 99 - 100 - reftable_writer_free(writer); 101 - }
-20
t/unit-tests/lib-reftable-clar.h
··· 1 - #include "git-compat-util.h" 2 - #include "clar/clar.h" 3 - #include "clar-decls.h" 4 - #include "git-compat-util.h" 5 - #include "reftable/reftable-writer.h" 6 - #include "strbuf.h" 7 - 8 - struct reftable_buf; 9 - 10 - void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id); 11 - 12 - struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf, 13 - struct reftable_write_options *opts); 14 - 15 - void cl_reftable_write_to_buf(struct reftable_buf *buf, 16 - struct reftable_ref_record *refs, 17 - size_t nrecords, 18 - struct reftable_log_record *logs, 19 - size_t nlogs, 20 - struct reftable_write_options *opts);
+19 -16
t/unit-tests/lib-reftable.c
··· 1 - #define DISABLE_SIGN_COMPARE_WARNINGS 2 - 1 + #include "unit-test.h" 3 2 #include "lib-reftable.h" 4 - #include "test-lib.h" 3 + #include "hex.h" 4 + #include "parse-options.h" 5 5 #include "reftable/constants.h" 6 6 #include "reftable/writer.h" 7 7 #include "strbuf.h" 8 + #include "string-list.h" 9 + #include "strvec.h" 8 10 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) 10 12 { 11 13 memset(p, (uint8_t)i, hash_size(id)); 12 14 } ··· 22 24 return 0; 23 25 } 24 26 25 - struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf, 27 + struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf, 26 28 struct reftable_write_options *opts) 27 29 { 28 30 struct reftable_writer *writer; 29 31 int ret = reftable_writer_new(&writer, &strbuf_writer_write, &strbuf_writer_flush, 30 32 buf, opts); 31 - check(!ret); 33 + cl_assert(!ret); 32 34 return writer; 33 35 } 34 36 35 - void t_reftable_write_to_buf(struct reftable_buf *buf, 37 + void cl_reftable_write_to_buf(struct reftable_buf *buf, 36 38 struct reftable_ref_record *refs, 37 39 size_t nrefs, 38 40 struct reftable_log_record *logs, ··· 64 66 min = ui; 65 67 } 66 68 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); 69 72 70 73 if (nrefs) { 71 74 ret = reftable_writer_add_refs(writer, refs, nrefs); 72 - check_int(ret, ==, 0); 75 + cl_assert_equal_i(ret, 0); 73 76 } 74 77 75 78 if (nlogs) { 76 79 ret = reftable_writer_add_logs(writer, logs, nlogs); 77 - check_int(ret, ==, 0); 80 + cl_assert_equal_i(ret, 0); 78 81 } 79 82 80 83 ret = reftable_writer_close(writer); 81 - check_int(ret, ==, 0); 84 + cl_assert_equal_i(ret, 0); 82 85 83 86 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++) { 85 88 size_t off = i * (opts.block_size ? opts.block_size 86 89 : DEFAULT_BLOCK_SIZE); 87 90 if (!off) 88 91 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'); 90 93 } 91 94 92 95 if (nrefs) 93 - check_int(stats->ref_stats.blocks, >, 0); 96 + cl_assert(stats->ref_stats.blocks > 0); 94 97 if (nlogs) 95 - check_int(stats->log_stats.blocks, >, 0); 98 + cl_assert(stats->log_stats.blocks > 0); 96 99 97 100 reftable_writer_free(writer); 98 101 }
+7 -8
t/unit-tests/lib-reftable.h
··· 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" 4 4 #include "git-compat-util.h" 5 5 #include "reftable/reftable-writer.h" 6 + #include "strbuf.h" 6 7 7 8 struct reftable_buf; 8 9 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); 10 11 11 - struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf, 12 + struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf, 12 13 struct reftable_write_options *opts); 13 14 14 - void t_reftable_write_to_buf(struct reftable_buf *buf, 15 + void cl_reftable_write_to_buf(struct reftable_buf *buf, 15 16 struct reftable_ref_record *refs, 16 17 size_t nrecords, 17 18 struct reftable_log_record *logs, 18 19 size_t nlogs, 19 20 struct reftable_write_options *opts); 20 - 21 - #endif
+1 -1
t/unit-tests/u-reftable-basics.c
··· 7 7 */ 8 8 9 9 #include "unit-test.h" 10 - #include "lib-reftable-clar.h" 10 + #include "lib-reftable.h" 11 11 #include "reftable/basics.h" 12 12 13 13 struct integer_needle_lesseq_args {
+1 -1
t/unit-tests/u-reftable-block.c
··· 7 7 */ 8 8 9 9 #include "unit-test.h" 10 - #include "lib-reftable-clar.h" 10 + #include "lib-reftable.h" 11 11 #include "reftable/block.h" 12 12 #include "reftable/blocksource.h" 13 13 #include "reftable/constants.h"
+1 -1
t/unit-tests/u-reftable-merged.c
··· 7 7 */ 8 8 9 9 #include "unit-test.h" 10 - #include "lib-reftable-clar.h" 10 + #include "lib-reftable.h" 11 11 #include "reftable/blocksource.h" 12 12 #include "reftable/constants.h" 13 13 #include "reftable/merged.h"
+1 -1
t/unit-tests/u-reftable-pq.c
··· 7 7 */ 8 8 9 9 #include "unit-test.h" 10 - #include "lib-reftable-clar.h" 10 + #include "lib-reftable.h" 11 11 #include "reftable/constants.h" 12 12 #include "reftable/pq.h" 13 13 #include "strbuf.h"
+1 -1
t/unit-tests/u-reftable-readwrite.c
··· 9 9 #define DISABLE_SIGN_COMPARE_WARNINGS 10 10 11 11 #include "unit-test.h" 12 - #include "lib-reftable-clar.h" 12 + #include "lib-reftable.h" 13 13 #include "reftable/basics.h" 14 14 #include "reftable/blocksource.h" 15 15 #include "reftable/reftable-error.h"
+1 -1
t/unit-tests/u-reftable-record.c
··· 7 7 */ 8 8 9 9 #include "unit-test.h" 10 - #include "lib-reftable-clar.h" 10 + #include "lib-reftable.h" 11 11 #include "reftable/basics.h" 12 12 #include "reftable/constants.h" 13 13 #include "reftable/record.h"
+2 -2
t/unit-tests/u-reftable-stack.c
··· 10 10 11 11 #include "unit-test.h" 12 12 #include "dir.h" 13 - #include "lib-reftable-clar.h" 13 + #include "lib-reftable.h" 14 14 #include "reftable/merged.h" 15 15 #include "reftable/reftable-error.h" 16 16 #include "reftable/stack.h" ··· 497 497 struct reftable_buf path = REFTABLE_BUF_INIT; 498 498 struct stat stat_result; 499 499 size_t i, N = ARRAY_SIZE(refs); 500 - int err; 500 + int err = 0; 501 501 502 502 err = reftable_new_stack(&st, dir, &opts); 503 503 cl_assert(!err);
+1 -1
t/unit-tests/u-reftable-table.c
··· 1 1 #include "unit-test.h" 2 - #include "lib-reftable-clar.h" 2 + #include "lib-reftable.h" 3 3 #include "reftable/blocksource.h" 4 4 #include "reftable/constants.h" 5 5 #include "reftable/iter.h"