Skip to contentSkip to conversation

t/unit-tests: convert unit-tests to use clar

PATCH Superseded Seyi Kuforiji 3 participants 31 messages Apr 29, 2025 – May 26, 2025

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover t/unit-tests: convert unit-tests to use clar

Hello,

This small patch series marks the final batch of our existing unit test files transitioned to the Clar testing framework. It covers all the reftable-related test files, and is part of our ongoing effort to standardize our testing framework to enhance its maintainability.

Changes in v2:
- some code refactoring based on review, which includes temporary relocation of reftable helper functions to t/unit-tests/unit-test.{c,h} files in the initial commit

Thanks
Seyi

Seyi Kuforiji (10):
t/unit-tests: implement reftable test helper functions in

    unit-test.{c,h}

t/unit-tests: convert reftable basics test to use clar test framework t/unit-tests: convert reftable block test to use clar t/unit-tests: convert reftable merged test to use clar t/unit-tests: convert reftable pq test to use clar t/unit-tests: convert reftable reader test to use clar t/unit-tests: convert reftable readwrite test to use clar t/unit-tests: convert reftable record test to use clar t/unit-tests: convert reftable stack test to use clar t/unit-tests: adapt lib-reftable{c,h} helper functions to clar

 Makefile                            |   20 +-
 t/meson.build                       |   21 +-
 t/unit-tests/lib-reftable.c         |   26 +-
 t/unit-tests/lib-reftable.h         |    6 +-
 t/unit-tests/t-reftable-basics.c    |  219 ----
 t/unit-tests/t-reftable-block.c     |  383 -------
 t/unit-tests/t-reftable-merged.c    |  546 ----------
 t/unit-tests/t-reftable-pq.c        |  161 ---
 t/unit-tests/t-reftable-reader.c    |   96 --
 t/unit-tests/t-reftable-readwrite.c |  985 ------------------
 t/unit-tests/t-reftable-record.c    |  585 -----------
 t/unit-tests/t-reftable-stack.c     | 1451 ---------------------------
 t/unit-tests/u-reftable-basics.c    |  195 ++++
 t/unit-tests/u-reftable-block.c     |  373 +++++++
 t/unit-tests/u-reftable-merged.c    |  515 ++++++++++
 t/unit-tests/u-reftable-pq.c        |  152 +++
 t/unit-tests/u-reftable-reader.c    |   78 ++
 t/unit-tests/u-reftable-readwrite.c |  870 ++++++++++++++++
 t/unit-tests/u-reftable-record.c    |  565 +++++++++++
 t/unit-tests/u-reftable-stack.c     | 1247 +++++++++++++++++++++++
 20 files changed, 4031 insertions(+), 4463 deletions(-)
 delete mode 100644 t/unit-tests/t-reftable-basics.c
 delete mode 100644 t/unit-tests/t-reftable-block.c
 delete mode 100644 t/unit-tests/t-reftable-merged.c
 delete mode 100644 t/unit-tests/t-reftable-pq.c
 delete mode 100644 t/unit-tests/t-reftable-reader.c
 delete mode 100644 t/unit-tests/t-reftable-readwrite.c
 delete mode 100644 t/unit-tests/t-reftable-record.c
 delete mode 100644 t/unit-tests/t-reftable-stack.c
 create mode 100644 t/unit-tests/u-reftable-basics.c
 create mode 100644 t/unit-tests/u-reftable-block.c
 create mode 100644 t/unit-tests/u-reftable-merged.c
 create mode 100644 t/unit-tests/u-reftable-pq.c
 create mode 100644 t/unit-tests/u-reftable-reader.c
 create mode 100644 t/unit-tests/u-reftable-readwrite.c
 create mode 100644 t/unit-tests/u-reftable-record.c
 create mode 100644 t/unit-tests/u-reftable-stack.c

Range-diff against v1:

 -:  ---------- >  1:  d85c5694ca t/unit-tests: implement reftable test helper functions in unit-test.{c,h}
 2:  4c5fc06603 !  2:  d24faa0176 t/unit-tests: convert reftable basics test to use clar test framework
    @@ Makefile: CLAR_TEST_SUITES += u-oid-array
      CLAR_TEST_SUITES += u-reftable-tree
      CLAR_TEST_SUITES += u-strbuf
      CLAR_TEST_SUITES += u-strcmp-offset
    -@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
    - CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
    +@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
      CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
    + CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
      
     -UNIT_TEST_PROGRAMS += t-reftable-basics
      UNIT_TEST_PROGRAMS += t-reftable-block
 3:  c9bdff8290 !  3:  d9eb47645b t/unit-tests: convert reftable block test to use clar
    @@ Makefile: CLAR_TEST_SUITES += u-oidmap
      CLAR_TEST_SUITES += u-reftable-tree
      CLAR_TEST_SUITES += u-strbuf
      CLAR_TEST_SUITES += u-strcmp-offset
    -@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
    - CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
    +@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
      CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
    + CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
      
     -UNIT_TEST_PROGRAMS += t-reftable-block
      UNIT_TEST_PROGRAMS += t-reftable-merged
 4:  60e2ff8bca !  4:  6ffc7cdfc6 t/unit-tests: convert reftable merged test to use clar
    @@ Makefile: CLAR_TEST_SUITES += u-oidtree
      CLAR_TEST_SUITES += u-reftable-tree
      CLAR_TEST_SUITES += u-strbuf
      CLAR_TEST_SUITES += u-strcmp-offset
    -@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
    - CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
    +@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
      CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
    + CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
      
     -UNIT_TEST_PROGRAMS += t-reftable-merged
      UNIT_TEST_PROGRAMS += t-reftable-pq
 5:  b06520b033 !  5:  19b08968a0 t/unit-tests: convert reftable pq test to use clar
    @@ Makefile: CLAR_TEST_SUITES += u-prio-queue
      CLAR_TEST_SUITES += u-reftable-tree
      CLAR_TEST_SUITES += u-strbuf
      CLAR_TEST_SUITES += u-strcmp-offset
    -@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
    - CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
    +@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
      CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
    + CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
      
     -UNIT_TEST_PROGRAMS += t-reftable-pq
      UNIT_TEST_PROGRAMS += t-reftable-reader
 6:  8b8ad57ff5 !  6:  b34d6714ed t/unit-tests: convert reftable reader test to use clar
    @@ Makefile: CLAR_TEST_SUITES += u-reftable-basics
      CLAR_TEST_SUITES += u-reftable-tree
      CLAR_TEST_SUITES += u-strbuf
      CLAR_TEST_SUITES += u-strcmp-offset
    -@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
    - CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
    +@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
      CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
    + CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
      
     -UNIT_TEST_PROGRAMS += t-reftable-reader
      UNIT_TEST_PROGRAMS += t-reftable-readwrite
 7:  da73e8c85b !  7:  05c909ea94 t/unit-tests: convert reftable readwrite test to use clar
    @@ Makefile: CLAR_TEST_SUITES += u-reftable-block
      CLAR_TEST_SUITES += u-reftable-tree
      CLAR_TEST_SUITES += u-strbuf
      CLAR_TEST_SUITES += u-strcmp-offset
    -@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
    - CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
    +@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
      CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
    + CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
      
     -UNIT_TEST_PROGRAMS += t-reftable-readwrite
      UNIT_TEST_PROGRAMS += t-reftable-record
 8:  ac6fd74321 !  8:  1515cf15b7 t/unit-tests: convert reftable record test to use clar
    @@ Makefile: CLAR_TEST_SUITES += u-reftable-merged
      CLAR_TEST_SUITES += u-reftable-tree
      CLAR_TEST_SUITES += u-strbuf
      CLAR_TEST_SUITES += u-strcmp-offset
    -@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
    - CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
    +@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
      CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
    + CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
      
     -UNIT_TEST_PROGRAMS += t-reftable-record
      UNIT_TEST_PROGRAMS += t-reftable-stack
 9:  5bc6a599c6 !  9:  dcbb2b6e56 t/unit-tests: convert reftable stack test to use clar
    @@ Makefile: CLAR_TEST_SUITES += u-reftable-pq
      CLAR_TEST_SUITES += u-reftable-tree
      CLAR_TEST_SUITES += u-strbuf
      CLAR_TEST_SUITES += u-strcmp-offset
    -@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
    - CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
    +@@ Makefile: CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
      CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
    + CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
      
     -UNIT_TEST_PROGRAMS += t-reftable-stack
      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
     
      ## t/meson.build ##
     @@ t/meson.build: clar_test_suites = [
 1:  304d17fef8 ! 10:  79aa0145aa t/unit-tests: adapt lib-reftable{c,h} helper functions to clar
    @@ Commit message
         Adapt functions in lib-reftable.{c,h} to use clar. These functions
         conform with the clar testing framework and become available for all
         reftable-related test files implemented using the clar testing
    -    framework, which requires them. This will be used by subsequent commits.
    +    framework, which requires them. This change migrates the helper
    +    functions back into `lib-reftable.{c,h}`.
     
         Signed-off-by: Seyi Kuforiji <[email protected]>
     
    @@ Makefile: CLAR_TEST_SUITES += u-urlmatch-normalization
     +CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
     +CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
      
    - UNIT_TEST_PROGRAMS += t-reftable-basics
    - UNIT_TEST_PROGRAMS += t-reftable-block
    -@@ Makefile: UNIT_TEST_PROGRAMS += t-reftable-record
    - UNIT_TEST_PROGRAMS += t-reftable-stack
      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
    @@ t/unit-tests/lib-reftable.h
      			     struct reftable_ref_record *refs,
      			     size_t nrecords,
      			     struct reftable_log_record *logs,
    +
    + ## t/unit-tests/unit-test.c ##
    +@@
    + #include "unit-test.h"
    + #include "hex.h"
    + #include "parse-options.h"
    +-#include "reftable/constants.h"
    +-#include "reftable/writer.h"
    + #include "strbuf.h"
    + #include "string-list.h"
    + #include "strvec.h"
    + 
    +-void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
    +-{
    +-	memset(p, (uint8_t)i, hash_size(id));
    +-}
    +-
    +-static ssize_t strbuf_writer_write(void *b, const void *data, size_t sz)
    +-{
    +-	strbuf_add(b, data, sz);
    +-	return sz;
    +-}
    +-
    +-static int strbuf_writer_flush(void *arg UNUSED)
    +-{
    +-	return 0;
    +-}
    +-
    +-struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
    +-						 struct reftable_write_options *opts)
    +-{
    +-	struct reftable_writer *writer;
    +-	int ret = reftable_writer_new(&writer, &strbuf_writer_write, &strbuf_writer_flush,
    +-				      buf, opts);
    +-	cl_assert(ret == 0);
    +-	return writer;
    +-}
    +-
    +-void cl_reftable_write_to_buf(struct reftable_buf *buf,
    +-			     struct reftable_ref_record *refs,
    +-			     size_t nrefs,
    +-			     struct reftable_log_record *logs,
    +-			     size_t nlogs,
    +-			     struct reftable_write_options *_opts)
    +-{
    +-	struct reftable_write_options opts = { 0 };
    +-	const struct reftable_stats *stats;
    +-	struct reftable_writer *writer;
    +-	uint64_t min = 0xffffffff;
    +-	uint64_t max = 0;
    +-	int ret;
    +-
    +-	if (_opts)
    +-		opts = *_opts;
    +-
    +-	for (size_t i = 0; i < nrefs; i++) {
    +-		uint64_t ui = refs[i].update_index;
    +-		if (ui > max)
    +-			max = ui;
    +-		if (ui < min)
    +-			min = ui;
    +-	}
    +-	for (size_t i = 0; i < nlogs; i++) {
    +-		uint64_t ui = logs[i].update_index;
    +-		if (ui > max)
    +-			max = ui;
    +-		if (ui < min)
    +-			min = ui;
    +-	}
    +-
    +-	writer = cl_reftable_strbuf_writer(buf, &opts);
    +-	reftable_writer_set_limits(writer, min, max);
    +-
    +-	if (nrefs) {
    +-		ret = reftable_writer_add_refs(writer, refs, nrefs);
    +-		cl_assert_equal_i(ret, 0);
    +-	}
    +-
    +-	if (nlogs) {
    +-		ret = reftable_writer_add_logs(writer, logs, nlogs);
    +-		cl_assert_equal_i(ret, 0);
    +-	}
    +-
    +-	ret = reftable_writer_close(writer);
    +-	cl_assert_equal_i(ret, 0);
    +-
    +-	stats = reftable_writer_stats(writer);
    +-	for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++) {
    +-		size_t off = i * (opts.block_size ? opts.block_size
    +-						  : DEFAULT_BLOCK_SIZE);
    +-		if (!off)
    +-			off = header_size(opts.hash_id == REFTABLE_HASH_SHA256 ? 2 : 1);
    +-		cl_assert(buf->buf[off] == 'r');
    +-	}
    +-
    +-	if (nrefs)
    +-		cl_assert(stats->ref_stats.blocks > 0);
    +-	if (nlogs)
    +-		cl_assert(stats->log_stats.blocks > 0);
    +-
    +-	reftable_writer_free(writer);
    +-}
    +-
    + static const char * const unit_test_usage[] = {
    + 	N_("unit-test [<options>]"),
    + 	NULL,
    +
    + ## t/unit-tests/unit-test.h ##
    +@@
    + #include "git-compat-util.h"
    + #include "clar/clar.h"
    + #include "clar-decls.h"
    +-#include "git-compat-util.h"
    +-#include "reftable/reftable-writer.h"
    + #include "strbuf.h"
    + 
    +-struct reftable_buf;
    +-
    +-void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
    +-
    +-struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
    +-						 struct reftable_write_options *opts);
    +-
    +-void cl_reftable_write_to_buf(struct reftable_buf *buf,
    +-			     struct reftable_ref_record *refs,
    +-			     size_t nrecords,
    +-			     struct reftable_log_record *logs,
    +-			     size_t nlogs,
    +-			     struct reftable_write_options *opts);
    +-
    + #define cl_failf(fmt, ...) do { \
    + 	char desc[4096]; \
    + 	snprintf(desc, sizeof(desc), fmt, __VA_ARGS__); \
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/10 t/unit-tests: implement reftable test helper functions in unit-test.{c,h}

Helper functions defined in t/unit-tests/lib-reftable.{c,h} are required for the reftable-related test files to run efficeintly. In the current implementation these functions are designed to conform with our homegrown unit-testing structure. So in other to convert the reftable test files, there is need for a clar specific implementation of these helper functions.

type cast for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++), implement equivalent helper functions in unit-test.{c,h} to use clar. These functions conform with the clar testing framework and become available for all reftable-related test files implemented using the clar testing framework, which requires them. This will be used by subsequent commits.

---
 t/unit-tests/unit-test.c | 93 ++++++++++++++++++++++++++++++++++++++++
 t/unit-tests/unit-test.h | 16 +++++++
 2 files changed, 109 insertions(+)
t/unit-tests/unit-test.c +93 -0
index 5af645048a..6c2a4e6aa8 100644
@@ -1,10 +1,103 @@
 #include "unit-test.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "reftable/constants.h"
+#include "reftable/writer.h"
 #include "strbuf.h"
 #include "string-list.h"
 #include "strvec.h"
 
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
+{
+	memset(p, (uint8_t)i, hash_size(id));
+}
+
+static ssize_t strbuf_writer_write(void *b, const void *data, size_t sz)
+{
+	strbuf_add(b, data, sz);
+	return sz;
+}
+
+static int strbuf_writer_flush(void *arg UNUSED)
+{
+	return 0;
+}
+
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
+						 struct reftable_write_options *opts)
+{
+	struct reftable_writer *writer;
+	int ret = reftable_writer_new(&writer, &strbuf_writer_write, &strbuf_writer_flush,
+				      buf, opts);
+	cl_assert(ret == 0);
+	return writer;
+}
+
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
+			     struct reftable_ref_record *refs,
+			     size_t nrefs,
+			     struct reftable_log_record *logs,
+			     size_t nlogs,
+			     struct reftable_write_options *_opts)
+{
+	struct reftable_write_options opts = { 0 };
+	const struct reftable_stats *stats;
+	struct reftable_writer *writer;
+	uint64_t min = 0xffffffff;
+	uint64_t max = 0;
+	int ret;
+
+	if (_opts)
+		opts = *_opts;
+
+	for (size_t i = 0; i < nrefs; i++) {
+		uint64_t ui = refs[i].update_index;
+		if (ui > max)
+			max = ui;
+		if (ui < min)
+			min = ui;
+	}
+	for (size_t i = 0; i < nlogs; i++) {
+		uint64_t ui = logs[i].update_index;
+		if (ui > max)
+			max = ui;
+		if (ui < min)
+			min = ui;
+	}
+
+	writer = cl_reftable_strbuf_writer(buf, &opts);
+	reftable_writer_set_limits(writer, min, max);
+
+	if (nrefs) {
+		ret = reftable_writer_add_refs(writer, refs, nrefs);
+		cl_assert_equal_i(ret, 0);
+	}
+
+	if (nlogs) {
+		ret = reftable_writer_add_logs(writer, logs, nlogs);
+		cl_assert_equal_i(ret, 0);
+	}
+
+	ret = reftable_writer_close(writer);
+	cl_assert_equal_i(ret, 0);
+
+	stats = reftable_writer_stats(writer);
+	for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++) {
+		size_t off = i * (opts.block_size ? opts.block_size
+						  : DEFAULT_BLOCK_SIZE);
+		if (!off)
+			off = header_size(opts.hash_id == REFTABLE_HASH_SHA256 ? 2 : 1);
+		cl_assert(buf->buf[off] == 'r');
+	}
+
+	if (nrefs)
+		cl_assert(stats->ref_stats.blocks > 0);
+	if (nlogs)
+		cl_assert(stats->log_stats.blocks > 0);
+
+	reftable_writer_free(writer);
+}
+
 static const char * const unit_test_usage[] = {
 	N_("unit-test [<options>]"),
 	NULL,
t/unit-tests/unit-test.h +16 -0
index 85e5d6a948..fe0aebd876 100644
@@ -1,8 +1,24 @@
 #include "git-compat-util.h"
 #include "clar/clar.h"
 #include "clar-decls.h"
+#include "git-compat-util.h"
+#include "reftable/reftable-writer.h"
 #include "strbuf.h"
 
+struct reftable_buf;
+
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
+
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
+						 struct reftable_write_options *opts);
+
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
+			     struct reftable_ref_record *refs,
+			     size_t nrecords,
+			     struct reftable_log_record *logs,
+			     size_t nlogs,
+			     struct reftable_write_options *opts);
+
 #define cl_failf(fmt, ...) do { \
 	char desc[4096]; \
 	snprintf(desc, sizeof(desc), fmt, __VA_ARGS__); \
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 01/10] t/unit-tests: implement reftable test helper functions in unit-test.{c,h}

Quoted 2 lines · Seyi Kuforiji

Helper functions defined in t/unit-tests/lib-reftable.{c,h} are required for the reftable-related test files to run efficeintly. In the

efficeintly? effectively? efficiently? correctly? Wouldn't it be sufficient to say "... to run." without anything else?

Quoted 4 lines

current implementation these functions are designed to conform with our homegrown unit-testing structure. So in other to convert the reftable test files, there is need for a clar specific implementation of these helper functions.

OK.

Quoted 3 lines

type cast for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++), implement equivalent helper functions in unit-test.{c,h} to use clar.

I cannot quite parse this.

Quoted 4 lines

These functions conform with the clar testing framework and become available for all reftable-related test files implemented using the clar testing framework, which requires them. This will be used by subsequent commits.

OK.

Quoted 5 lines
---
 t/unit-tests/unit-test.c | 93 ++++++++++++++++++++++++++++++++++++++++
 t/unit-tests/unit-test.h | 16 +++++++
 2 files changed, 109 insertions(+)

Hmph, this probably is a question better asked to Patrick, but it somehow feels a bit unsatisfactory that we are duplicating instead of replacing, as we cannot see "ah, this removed thing is now added in a different shape to fit in the other framework" in the patch--- instead what we see in the patch is a bunch of "a completely new thing that honors the convention we are familiar in existing clar based tests is added here".

#3 lore raw

Re: [PATCH v2 01/10] t/unit-tests: implement reftable test helper functions in unit-test.{c,h}

Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Seyi Kuforiji
---
 t/unit-tests/unit-test.c | 93 ++++++++++++++++++++++++++++++++++++++++
 t/unit-tests/unit-test.h | 16 +++++++
 2 files changed, 109 insertions(+)
Quoted 7 lines

Hmph, this probably is a question better asked to Patrick, but it somehow feels a bit unsatisfactory that we are duplicating instead of replacing, as we cannot see "ah, this removed thing is now added in a different shape to fit in the other framework" in the patch--- instead what we see in the patch is a bunch of "a completely new thing that honors the convention we are familiar in existing clar based tests is added here".

Well, my expectation is that at the end of this patch series we will remove the old functionality. The steps should roughly be:

1. Implement equivalents for the reftable-specific test library for clar.

2. Convert all reftable unit tests to use the new functions.

3. Remove the old functions.

Given that (2) is a bunch of tests it makes perfect sense to first have a separate patch that adds without removing yet.

What I found a bit confusing though is that the new functions aren't added to "t/unit-tests/lib-reftable.{c,h}". This would be very much preferable from my point of view as the test functions aren't globally relevant, but really only relevant to the reftable library.

Patrick

#4 lore raw

Re: [PATCH v2 01/10] t/unit-tests: implement reftable test helper functions in unit-test.{c,h}

In reply to Seyi Kuforiji
Quoted 14 lines · Seyi Kuforiji

Helper functions defined in t/unit-tests/lib-reftable.{c,h} are required for the reftable-related test files to run efficeintly. In the current implementation these functions are designed to conform with our homegrown unit-testing structure. So in other to convert the reftable test files, there is need for a clar specific implementation of these helper functions.

type cast for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++), implement equivalent helper functions in unit-test.{c,h} to use clar. These functions conform with the clar testing framework and become available for all reftable-related test files implemented using the clar testing framework, which requires them. This will be used by subsequent commits.

Quoted 5 lines
---
 t/unit-tests/unit-test.c | 93 ++++++++++++++++++++++++++++++++++++++++
 t/unit-tests/unit-test.h | 16 +++++++
 2 files changed, 109 insertions(+)

I think this functionality should be added to "t/unit-tests/lib-reftable.{c,h}" instead of to the generic unit testing library as it is highly specific to reftables.

Quoted 27 lines
t/unit-tests/unit-test.c +15 -0
index 5af645048a..6c2a4e6aa8 100644
@@ -1,10 +1,103 @@
 #include "unit-test.h"
 #include "hex.h"
 #include "parse-options.h"
+#include "reftable/constants.h"
+#include "reftable/writer.h"
 #include "strbuf.h"
 #include "string-list.h"
 #include "strvec.h"
 
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
+{
+	memset(p, (uint8_t)i, hash_size(id));
+}
+
+static ssize_t strbuf_writer_write(void *b, const void *data, size_t sz)
+{
+	strbuf_add(b, data, sz);
+	return sz;
+}
+
+static int strbuf_writer_flush(void *arg UNUSED)
+{

t/unit-tests/unit-test.c line 32

Quoted 10 lines
t/unit-tests/unit-test.c +10 -0
+	return 0;
+}
+
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
+						 struct reftable_write_options *opts)
+{
+	struct reftable_writer *writer;
+	int ret = reftable_writer_new(&writer, &strbuf_writer_write, &strbuf_writer_flush,
+				      buf, opts);
+	cl_assert(ret == 0);

We typically don't explicitly compare with zero, so this should rather be cl_assert(!ret).

Quoted 27 lines
t/unit-tests/unit-test.c +27 -0
+	return writer;
+}
+
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
+			     struct reftable_ref_record *refs,
+			     size_t nrefs,
+			     struct reftable_log_record *logs,
+			     size_t nlogs,
+			     struct reftable_write_options *_opts)
+{
+	struct reftable_write_options opts = { 0 };
+	const struct reftable_stats *stats;
+	struct reftable_writer *writer;
+	uint64_t min = 0xffffffff;
+	uint64_t max = 0;
+	int ret;
+
+	if (_opts)
+		opts = *_opts;
+
+	for (size_t i = 0; i < nrefs; i++) {
+		uint64_t ui = refs[i].update_index;
+		if (ui > max)
+			max = ui;
+		if (ui < min)
+			min = ui;
+	}

t/unit-tests/unit-test.c line 69

Quoted 10 lines
t/unit-tests/unit-test.c +10 -0
+	for (size_t i = 0; i < nlogs; i++) {
+		uint64_t ui = logs[i].update_index;
+		if (ui > max)
+			max = ui;
+		if (ui < min)
+			min = ui;
+	}
+
+	writer = cl_reftable_strbuf_writer(buf, &opts);
+	reftable_writer_set_limits(writer, min, max);

This function may return an error, as well, so let's verify it while at it.

Patrick

#5 lore raw

PATCH v2 2/10 t/unit-tests: convert reftable basics test to use clar test framework

In reply to Seyi Kuforiji

Adapt reftable basics test file to clar by using clar assertions where necessary.Break up test edge case to improve modularity and clarity.

---
 Makefile                         |   2 +-
 t/meson.build                    |   2 +-
 t/unit-tests/t-reftable-basics.c | 219 -------------------------------
 t/unit-tests/u-reftable-basics.c | 195 +++++++++++++++++++++++++++
 4 files changed, 197 insertions(+), 221 deletions(-)
 delete mode 100644 t/unit-tests/t-reftable-basics.c
 create mode 100644 t/unit-tests/u-reftable-basics.c
Makefile +1 -1
index 13f9062a05..7b12bb078c 100644
@@ -1362,6 +1362,7 @@ CLAR_TEST_SUITES += u-oid-array
 CLAR_TEST_SUITES += u-oidmap
 CLAR_TEST_SUITES += u-oidtree
 CLAR_TEST_SUITES += u-prio-queue
+CLAR_TEST_SUITES += u-reftable-basics
 CLAR_TEST_SUITES += u-reftable-tree
 CLAR_TEST_SUITES += u-strbuf
 CLAR_TEST_SUITES += u-strcmp-offset
@@ -1374,7 +1375,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
 
-UNIT_TEST_PROGRAMS += t-reftable-basics
 UNIT_TEST_PROGRAMS += t-reftable-block
 UNIT_TEST_PROGRAMS += t-reftable-merged
 UNIT_TEST_PROGRAMS += t-reftable-pq
t/meson.build +1 -1
index bfb744e886..8a42b595d9 100644
@@ -8,6 +8,7 @@ clar_test_suites = [
   'unit-tests/u-oidmap.c',
   'unit-tests/u-oidtree.c',
   'unit-tests/u-prio-queue.c',
+  'unit-tests/u-reftable-basics.c',
   'unit-tests/u-reftable-tree.c',
   'unit-tests/u-strbuf.c',
   'unit-tests/u-strcmp-offset.c',
@@ -54,7 +55,6 @@ clar_unit_tests = executable('unit-tests',
 test('unit-tests', clar_unit_tests)
 
 unit_test_programs = [
-  'unit-tests/t-reftable-basics.c',
   'unit-tests/t-reftable-block.c',
   'unit-tests/t-reftable-merged.c',
   'unit-tests/t-reftable-pq.c',
t/unit-tests/t-reftable-basics.c deleted +0 -219

219 lines not on this page · raw message

t/unit-tests/u-reftable-basics.c new file +195 -0

195 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH v2 02/10] t/unit-tests: convert reftable basics test to use clar test framework

Quoted 334 lines · Seyi Kuforiji

Adapt reftable basics test file to clar by using clar assertions where necessary.Break up test edge case to improve modularity and clarity.

---
 Makefile                         |   2 +-
 t/meson.build                    |   2 +-
 t/unit-tests/t-reftable-basics.c | 219 -------------------------------
 t/unit-tests/u-reftable-basics.c | 195 +++++++++++++++++++++++++++
 4 files changed, 197 insertions(+), 221 deletions(-)
 delete mode 100644 t/unit-tests/t-reftable-basics.c
 create mode 100644 t/unit-tests/u-reftable-basics.c
Makefile +1 -1
index 13f9062a05..7b12bb078c 100644
@@ -1362,6 +1362,7 @@ CLAR_TEST_SUITES += u-oid-array
 CLAR_TEST_SUITES += u-oidmap
 CLAR_TEST_SUITES += u-oidtree
 CLAR_TEST_SUITES += u-prio-queue
+CLAR_TEST_SUITES += u-reftable-basics
 CLAR_TEST_SUITES += u-reftable-tree
 CLAR_TEST_SUITES += u-strbuf
 CLAR_TEST_SUITES += u-strcmp-offset
@@ -1374,7 +1375,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
 
-UNIT_TEST_PROGRAMS += t-reftable-basics
 UNIT_TEST_PROGRAMS += t-reftable-block
 UNIT_TEST_PROGRAMS += t-reftable-merged
 UNIT_TEST_PROGRAMS += t-reftable-pq
t/meson.build +1 -1
index bfb744e886..8a42b595d9 100644
@@ -8,6 +8,7 @@ clar_test_suites = [
   'unit-tests/u-oidmap.c',
   'unit-tests/u-oidtree.c',
   'unit-tests/u-prio-queue.c',
+  'unit-tests/u-reftable-basics.c',
   'unit-tests/u-reftable-tree.c',
   'unit-tests/u-strbuf.c',
   'unit-tests/u-strcmp-offset.c',
@@ -54,7 +55,6 @@ clar_unit_tests = executable('unit-tests',
 test('unit-tests', clar_unit_tests)
 
 unit_test_programs = [
-  'unit-tests/t-reftable-basics.c',
   'unit-tests/t-reftable-block.c',
   'unit-tests/t-reftable-merged.c',
   'unit-tests/t-reftable-pq.c',
t/unit-tests/t-reftable-basics.c deleted +0 -219
deleted file mode 100644
index c9e751e49e..0000000000
@@ -1,219 +0,0 @@
-/*
-Copyright 2020 Google LLC
-
-Use of this source code is governed by a BSD-style
-license that can be found in the LICENSE file or at
-https://developers.google.com/open-source/licenses/bsd
-*/
-
-#include "test-lib.h"
-#include "reftable/basics.h"
-
-struct integer_needle_lesseq_args {
-	int needle;
-	int *haystack;
-};
-
-static int integer_needle_lesseq(size_t i, void *_args)
-{
-	struct integer_needle_lesseq_args *args = _args;
-	return args->needle <= args->haystack[i];
-}
-
-static void *realloc_stub(void *p UNUSED, size_t size UNUSED)
-{
-	return NULL;
-}
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
-	if_test ("binary search with binsearch works") {
-		int haystack[] = { 2, 4, 6, 8, 10 };
-		struct {
-			int needle;
-			size_t expected_idx;
-		} testcases[] = {
-			{-9000, 0},
-			{-1, 0},
-			{0, 0},
-			{2, 0},
-			{3, 1},
-			{4, 1},
-			{7, 3},
-			{9, 4},
-			{10, 4},
-			{11, 5},
-			{9000, 5},
-		};
-
-		for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
-			struct integer_needle_lesseq_args args = {
-				.haystack = haystack,
-				.needle = testcases[i].needle,
-			};
-			size_t idx;
-
-			idx = binsearch(ARRAY_SIZE(haystack),
-					&integer_needle_lesseq, &args);
-			check_int(idx, ==, testcases[i].expected_idx);
-		}
-	}
-
-	if_test ("names_length returns size of a NULL-terminated string array") {
-		const char *a[] = { "a", "b", NULL };
-		check_int(names_length(a), ==, 2);
-	}
-
-	if_test ("names_equal compares NULL-terminated string arrays") {
-		const char *a[] = { "a", "b", "c", NULL };
-		const char *b[] = { "a", "b", "d", NULL };
-		const char *c[] = { "a", "b", NULL };
-
-		check(names_equal(a, a));
-		check(!names_equal(a, b));
-		check(!names_equal(a, c));
-	}
-
-	if_test ("parse_names works for basic input") {
-		char in1[] = "line\n";
-		char in2[] = "a\nb\nc";
-		char **out = parse_names(in1, strlen(in1));
-		check(out != NULL);
-		check_str(out[0], "line");
-		check(!out[1]);
-		free_names(out);
-
-		out = parse_names(in2, strlen(in2));
-		check(out != NULL);
-		check_str(out[0], "a");
-		check_str(out[1], "b");
-		check_str(out[2], "c");
-		check(!out[3]);
-		free_names(out);
-	}
-
-	if_test ("parse_names drops empty string") {
-		char in[] = "a\n\nb\n";
-		char **out = parse_names(in, strlen(in));
-		check(out != NULL);
-		check_str(out[0], "a");
-		/* simply '\n' should be dropped as empty string */
-		check_str(out[1], "b");
-		check(!out[2]);
-		free_names(out);
-	}
-
-	if_test ("common_prefix_size works") {
-		struct reftable_buf a = REFTABLE_BUF_INIT;
-		struct reftable_buf b = REFTABLE_BUF_INIT;
-		struct {
-			const char *a, *b;
-			int want;
-		} cases[] = {
-			{"abcdef", "abc", 3},
-			{ "abc", "ab", 2 },
-			{ "", "abc", 0 },
-			{ "abc", "abd", 2 },
-			{ "abc", "pqr", 0 },
-		};
-
-		for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
-			check(!reftable_buf_addstr(&a, cases[i].a));
-			check(!reftable_buf_addstr(&b, cases[i].b));
-			check_uint(common_prefix_size(&a, &b), ==, cases[i].want);
-			reftable_buf_reset(&a);
-			reftable_buf_reset(&b);
-		}
-		reftable_buf_release(&a);
-		reftable_buf_release(&b);
-	}
-
-	if_test ("reftable_put_be64 and reftable_get_be64 work") {
-		uint64_t in = 0x1122334455667788;
-		uint8_t dest[8];
-		uint64_t out;
-		reftable_put_be64(dest, in);
-		out = reftable_get_be64(dest);
-		check_int(in, ==, out);
-	}
-
-	if_test ("reftable_put_be32 and reftable_get_be32 work") {
-		uint32_t in = 0x11223344;
-		uint8_t dest[4];
-		uint32_t out;
-		reftable_put_be32(dest, in);
-		out = reftable_get_be32(dest);
-		check_int(in, ==, out);
-	}
-
-	if_test ("reftable_put_be24 and reftable_get_be24 work") {
-		uint32_t in = 0x112233;
-		uint8_t dest[3];
-		uint32_t out;
-		reftable_put_be24(dest, in);
-		out = reftable_get_be24(dest);
-		check_int(in, ==, out);
-	}
-
-	if_test ("put_be16 and get_be16 work") {
-		uint32_t in = 0xfef1;
-		uint8_t dest[3];
-		uint32_t out;
-		reftable_put_be16(dest, in);
-		out = reftable_get_be16(dest);
-		check_int(in, ==, out);
-	}
-
-	if_test ("REFTABLE_ALLOC_GROW works") {
-		int *arr = NULL, *old_arr;
-		size_t alloc = 0, old_alloc;
-
-		check(!REFTABLE_ALLOC_GROW(arr, 1, alloc));
-		check(arr != NULL);
-		check_uint(alloc, >=, 1);
-		arr[0] = 42;
-
-		old_alloc = alloc;
-		old_arr = arr;
-		reftable_set_alloc(NULL, realloc_stub, NULL);
-		check(REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc));
-		check(arr == old_arr);
-		check_uint(alloc, ==, old_alloc);
-
-		old_alloc = alloc;
-		reftable_set_alloc(NULL, NULL, NULL);
-		check(!REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc));
-		check(arr != NULL);
-		check_uint(alloc, >, old_alloc);
-		arr[alloc - 1] = 42;
-
-		reftable_free(arr);
-	}
-
-	if_test ("REFTABLE_ALLOC_GROW_OR_NULL works") {
-		int *arr = NULL;
-		size_t alloc = 0, old_alloc;
-
-		REFTABLE_ALLOC_GROW_OR_NULL(arr, 1, alloc);
-		check(arr != NULL);
-		check_uint(alloc, >=, 1);
-		arr[0] = 42;
-
-		old_alloc = alloc;
-		REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
-		check(arr != NULL);
-		check_uint(alloc, >, old_alloc);
-		arr[alloc - 1] = 42;
-
-		old_alloc = alloc;
-		reftable_set_alloc(NULL, realloc_stub, NULL);
-		REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
-		check(arr == NULL);
-		check_uint(alloc, ==, 0);
-		reftable_set_alloc(NULL, NULL, NULL);
-
-		reftable_free(arr);
-	}
-
-	return test_done();
-}
t/unit-tests/u-reftable-basics.c new file +49 -0
new file mode 100644
index 0000000000..63dd568faf
@@ -0,0 +1,195 @@
+/*
+Copyright 2020 Google LLC
+
+Use of this source code is governed by a BSD-style
+license that can be found in the LICENSE file or at
+https://developers.google.com/open-source/licenses/bsd
+*/
+
+#include "unit-test.h"
+#include "reftable/basics.h"
+
+struct integer_needle_lesseq_args {
+	int needle;
+	int *haystack;
+};
+
+static int integer_needle_lesseq(size_t i, void *_args)
+{
+	struct integer_needle_lesseq_args *args = _args;
+	return args->needle <= args->haystack[i];
+}
+
+static void *realloc_stub(void *p UNUSED, size_t size UNUSED)
+{
+	return NULL;
+}
+
+void test_reftable_basics__binsearch(void)
+{
+	int haystack[] = { 2, 4, 6, 8, 10 };
+	struct {
+		int needle;
+		size_t expected_idx;
+	} testcases[] = {
+		{-9000, 0},
+		{-1, 0},
+		{0, 0},
+		{2, 0},
+		{3, 1},
+		{4, 1},
+		{7, 3},
+		{9, 4},
+		{10, 4},
+		{11, 5},
+		{9000, 5},
+	};
+
+	for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
+		struct integer_needle_lesseq_args args = {

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

Quoted 10 lines
t/unit-tests/u-reftable-basics.c new file +10 -0
+			.haystack = haystack,
+			.needle = testcases[i].needle,
+		};
+		size_t idx;
+
+		idx = binsearch(ARRAY_SIZE(haystack),
+				&integer_needle_lesseq, &args);
+		cl_assert_equal_i(idx, testcases[i].expected_idx);
+	}
+

Nit: empty newline can be removed.

Quoted 28 lines
t/unit-tests/u-reftable-basics.c new file +28 -0
+}
+
+void test_reftable_basics__names_length(void)
+{
+	const char *a[] = { "a", "b", NULL };
+	cl_assert_equal_i(names_length(a), 2);
+}
+
+void test_reftable_basics__names_equal(void)
+{
+	const char *a[] = { "a", "b", "c", NULL };
+	const char *b[] = { "a", "b", "d", NULL };
+	const char *c[] = { "a", "b", NULL };
+
+	cl_assert(names_equal(a, a));
+	cl_assert(!names_equal(a, b));
+	cl_assert(!names_equal(a, c));
+}
+
+void test_reftable_basics__parse_names(void)
+{
+	char in1[] = "line\n";
+	char in2[] = "a\nb\nc";
+	char **out = parse_names(in1, strlen(in1));
+	cl_assert(out != NULL);
+	cl_assert_equal_s(out[0], "line");
+	cl_assert(!out[1]);
+	free_names(out);

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

Quoted 10 lines
t/unit-tests/u-reftable-basics.c new file +10 -0
+
+	out = parse_names(in2, strlen(in2));
+	cl_assert(out != NULL);
+	cl_assert_equal_s(out[0], "a");
+	cl_assert_equal_s(out[1], "b");
+	cl_assert_equal_s(out[2], "c");
+	cl_assert(!out[3]);
+	free_names(out);
+}
+

I think you missed converting "parse_names drops empty string".

Quoted 11 lines
t/unit-tests/u-reftable-basics.c new file +11 -0
+void test_reftable_basics__common_prefix_size(void)
+{
+	struct reftable_buf a = REFTABLE_BUF_INIT;
+	struct reftable_buf b = REFTABLE_BUF_INIT;
+	struct {
+		const char *a, *b;
+		int want;
+	} cases[] = {
+		{"abcdef", "abc", 3},
+		{ "abc", "ab", 2 },
+		{ "", "abc", 0 },

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

Quoted 10 lines
t/unit-tests/u-reftable-basics.c new file +10 -0
+		{ "abc", "abd", 2 },
+		{ "abc", "pqr", 0 },
+	};
+
+	for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
+		reftable_buf_reset(&a);
+		reftable_buf_reset(&b);
+		cl_assert_equal_i(reftable_buf_addstr(&a, cases[i].a), 0);
+		cl_assert_equal_i(reftable_buf_addstr(&b, cases[i].b), 0);
+		cl_assert_equal_i(common_prefix_size(&a, &b), cases[i].want);

Why did you change the order of reftable_buf_reset() calls? The reordered logic achieves the same result, but I'd recommend to keep things as-is so that reviewers aren't puzzled by this arbitrary change.

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

Quoted 4 lines
t/unit-tests/u-reftable-basics.c new file +4 -0
+	}
+	reftable_buf_release(&a);
+	reftable_buf_release(&b);
+}

I miss tests for put_be64 and put_be32.

Quoted 11 lines
t/unit-tests/u-reftable-basics.c new file +11 -0
+void test_reftable_basics__put_get_be24(void)
+{
+	uint32_t in = 0x112233;
+	uint8_t dest[3];
+	uint32_t out;
+	reftable_put_be24(dest, in);
+	out = reftable_get_be24(dest);
+	cl_assert_equal_i(in, out);
+}
+
+void test_reftable_basics__put_get_be16(void)

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

Quoted 10 lines
t/unit-tests/u-reftable-basics.c new file +10 -0
+{
+	uint32_t in = 0xfef1;
+	uint8_t dest[3];
+	uint32_t out;
+	reftable_put_be16(dest, in);
+	out = reftable_get_be16(dest);
+	cl_assert_equal_i(in, out);
+}
+
+void test_reftable_basics__grow_alloc(void)

Let's rename this to __alloc_grow() to match the name of the function.

Quoted 17 lines
t/unit-tests/u-reftable-basics.c new file +17 -0
+{
+	int *arr = NULL, *old_arr;
+	size_t alloc = 0, old_alloc;
+
+	cl_assert_equal_i(REFTABLE_ALLOC_GROW(arr, 1, alloc), 0);
+	cl_assert(arr != NULL);
+	cl_assert(alloc >= 1);
+	arr[0] = 42;
+
+	old_alloc = alloc;
+	old_arr = arr;
+	reftable_set_alloc(NULL, realloc_stub, NULL);
+	cl_assert(REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc));
+	cl_assert(arr == old_arr);
+	cl_assert_equal_i(alloc, old_alloc);
+
+	old_alloc = alloc;

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

Quoted 10 lines
t/unit-tests/u-reftable-basics.c new file +10 -0
+	reftable_set_alloc(NULL, NULL, NULL);
+	cl_assert_equal_i(REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc), 0);
+	cl_assert(arr != NULL);
+	cl_assert(alloc > old_alloc);
+	arr[alloc - 1] = 42;
+
+	reftable_free(arr);
+}
+
+void test_reftable_basics__grow_alloc_or_null(void)

Same here, let's rename to alloc_grow_or_null.

Quoted 14 lines
t/unit-tests/u-reftable-basics.c new file +14 -0
+{
+	int *arr = NULL;
+	size_t alloc = 0, old_alloc;
+
+	REFTABLE_ALLOC_GROW_OR_NULL(arr, 1, alloc);
+	cl_assert(arr != NULL);
+	cl_assert(alloc >= 1);
+	arr[0] = 42;
+
+	old_alloc = alloc;
+	REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
+	cl_assert(arr != NULL);
+	cl_assert(alloc > old_alloc);
+	arr[alloc - 1] = 42;

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

Quoted 10 lines
t/unit-tests/u-reftable-basics.c new file +10 -0
+
+	old_alloc = alloc;
+	reftable_set_alloc(NULL, realloc_stub, NULL);
+	REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
+	cl_assert(arr == NULL);
+	cl_assert_equal_i(alloc, 0);
+	reftable_set_alloc(NULL, NULL, NULL);
+
+	reftable_free(arr);
+}

Other than that this looks well-done to me, thanks!

Patrick

#7 lore raw

PATCH v2 3/10 t/unit-tests: convert reftable block test to use clar

In reply to Seyi Kuforiji

Adapt reftable block test file to use clar testing framework by using clar assertions where necessary.

---
 Makefile                        |   2 +-
 t/meson.build                   |   2 +-
 t/unit-tests/t-reftable-block.c | 383 --------------------------------
 t/unit-tests/u-reftable-block.c | 373 +++++++++++++++++++++++++++++++
 4 files changed, 375 insertions(+), 385 deletions(-)
 delete mode 100644 t/unit-tests/t-reftable-block.c
 create mode 100644 t/unit-tests/u-reftable-block.c
Makefile +1 -1
index 7b12bb078c..239c575dad 100644
@@ -1363,6 +1363,7 @@ CLAR_TEST_SUITES += u-oidmap
 CLAR_TEST_SUITES += u-oidtree
 CLAR_TEST_SUITES += u-prio-queue
 CLAR_TEST_SUITES += u-reftable-basics
+CLAR_TEST_SUITES += u-reftable-block
 CLAR_TEST_SUITES += u-reftable-tree
 CLAR_TEST_SUITES += u-strbuf
 CLAR_TEST_SUITES += u-strcmp-offset
@@ -1375,7 +1376,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
 
-UNIT_TEST_PROGRAMS += t-reftable-block
 UNIT_TEST_PROGRAMS += t-reftable-merged
 UNIT_TEST_PROGRAMS += t-reftable-pq
 UNIT_TEST_PROGRAMS += t-reftable-reader
t/meson.build +1 -1
index 8a42b595d9..e0d723e74b 100644
@@ -9,6 +9,7 @@ clar_test_suites = [
   'unit-tests/u-oidtree.c',
   'unit-tests/u-prio-queue.c',
   'unit-tests/u-reftable-basics.c',
+  'unit-tests/u-reftable-block.c',
   'unit-tests/u-reftable-tree.c',
   'unit-tests/u-strbuf.c',
   'unit-tests/u-strcmp-offset.c',
@@ -55,7 +56,6 @@ clar_unit_tests = executable('unit-tests',
 test('unit-tests', clar_unit_tests)
 
 unit_test_programs = [
-  'unit-tests/t-reftable-block.c',
   'unit-tests/t-reftable-merged.c',
   'unit-tests/t-reftable-pq.c',
   'unit-tests/t-reftable-reader.c',
t/unit-tests/t-reftable-block.c deleted +0 -383

383 lines not on this page · raw message

t/unit-tests/u-reftable-block.c new file +373 -0

373 lines not on this page · raw message

Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH v2 03/10] t/unit-tests: convert reftable block test to use clar

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

Quoted 5 lines · Seyi Kuforiji
t/unit-tests/t-reftable-block.c deleted +0 -0
deleted file mode 100644
index 22040aeefa..0000000000

Hm, why is this recorded as a delete and creation? Weird, inspecting the diff locally properly shows it as a rename, which makes it a ton easier to review. It would be great if you could try to play around with the --find-renames option in the next iteration of this series and double check that these are shown as a rename.

Quoted 12 lines
t/unit-tests/u-reftable-block.c new file +6 -0
new file mode 100644
index 0000000000..af24901230
@@ -0,0 +1,373 @@
+/*
+Copyright 2020 Google LLC
+
+Use of this source code is governed by a BSD-style
+license that can be found in the LICENSE file or at
+https://developers.google.com/open-source/licenses/bsd

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

Quoted 10 lines
t/unit-tests/u-reftable-block.c new file +10 -0
+*/
+
+#include "unit-test.h"
+#include "reftable/block.h"
+#include "reftable/blocksource.h"
+#include "reftable/constants.h"
+#include "reftable/reftable-error.h"
+#include "strbuf.h"
+
+void test_reftable_block__index_read_write(void)

This doesn't got to do anything with indices but with refs, so I'd rename this to __ref_read_write().

Quoted 15 lines
t/unit-tests/u-reftable-block.c new file +15 -0
+{
+	const int header_off = 21; /* random */
+	struct reftable_record recs[30];
+	const size_t N = ARRAY_SIZE(recs);
+	const size_t block_size = 1024;
+	struct reftable_block block = { 0 };
+	struct block_writer bw = {
+		.last_key = REFTABLE_BUF_INIT,
+	};
+	struct reftable_record rec = {
+		.type = BLOCK_TYPE_REF,
+	};
+	size_t i = 0;
+	int ret;
+	struct block_reader br = { 0 };

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

Quoted 10 lines
t/unit-tests/u-reftable-block.c new file +10 -0
+	struct block_iter it = BLOCK_ITER_INIT;
+	struct reftable_buf want = REFTABLE_BUF_INIT, buf = REFTABLE_BUF_INIT;
+
+	REFTABLE_CALLOC_ARRAY(block.data, block_size);
+	cl_assert(block.data != NULL);
+	block.len = block_size;
+	block_source_from_buf(&block.source ,&buf);
+	ret = block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
+				header_off, hash_size(REFTABLE_HASH_SHA1));
+	cl_assert(ret == 0);

Same comment here, asserts like this can be retained as cl_assert(!ret).

Quoted 9 lines
t/unit-tests/u-reftable-block.c new file +9 -0
+	rec.u.ref.refname = (char *) "";
+	rec.u.ref.value_type = REFTABLE_REF_DELETION;
+	ret = block_writer_add(&bw, &rec);
+	cl_assert_equal_i(ret, REFTABLE_API_ERROR);
+
+	for (i = 0; i < N; i++) {
+		rec.u.ref.refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
+		rec.u.ref.value_type = REFTABLE_REF_VAL1;
+		memset(rec.u.ref.value.val1, i, REFTABLE_HASH_SIZE_SHA1);

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

Quoted 10 lines
t/unit-tests/u-reftable-block.c new file +10 -0
+
+		recs[i] = rec;
+		ret = block_writer_add(&bw, &rec);
+		rec.u.ref.refname = NULL;
+		rec.u.ref.value_type = REFTABLE_REF_DELETION;
+		cl_assert_equal_i(ret, 0);
+	}
+
+	ret = block_writer_finish(&bw);
+	cl_assert(ret > 0);

It's a bit unfortunate that we have to use cl_assert() here, but that isn't the fault of this series. I do have a pull request pending upstream that introduces integer comparisons. Once we've updated to that version I'll go through our unit tests and adapt callsites accordingly.

[snip]

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

Quoted 1 line
t/unit-tests/u-reftable-block.c new file +1 -0
+void test_reftable_block__ref_read_write(void)

This one here should be called __index_read_write(). I guess you confused the first and and this test name with one another.

Patrick

#9 lore raw

Re: [PATCH v2 03/10] t/unit-tests: convert reftable block test to use clar

Quoted 14 lines · Patrick Steinhardt

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

Quoted 5 lines · Seyi Kuforiji
t/unit-tests/t-reftable-block.c deleted +0 -0
deleted file mode 100644
index 22040aeefa..0000000000

Hm, why is this recorded as a delete and creation? Weird, inspecting the diff locally properly shows it as a rename, which makes it a ton easier to review. It would be great if you could try to play around with the --find-renames option in the next iteration of this series and double check that these are shown as a rename.

I used --find-renames=90 for this patch series. Is there any recommended number to set it to? :/

Quoted 46 lines
Quoted 12 lines
t/unit-tests/u-reftable-block.c new file +6 -0
new file mode 100644
index 0000000000..af24901230
@@ -0,0 +1,373 @@
+/*
+Copyright 2020 Google LLC
+
+Use of this source code is governed by a BSD-style
+license that can be found in the LICENSE file or at
+https://developers.google.com/open-source/licenses/bsd

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

Quoted 10 lines
t/unit-tests/u-reftable-block.c new file +10 -0
+*/
+
+#include "unit-test.h"
+#include "reftable/block.h"
+#include "reftable/blocksource.h"
+#include "reftable/constants.h"
+#include "reftable/reftable-error.h"
+#include "strbuf.h"
+
+void test_reftable_block__index_read_write(void)

This doesn't got to do anything with indices but with refs, so I'd rename this to __ref_read_write().

Quoted 20 lines
t/unit-tests/u-reftable-block.c new file +20 -0
+{
+     const int header_off = 21; /* random */
+     struct reftable_record recs[30];
+     const size_t N = ARRAY_SIZE(recs);
+     const size_t block_size = 1024;
+     struct reftable_block block = { 0 };
+     struct block_writer bw = {
+             .last_key = REFTABLE_BUF_INIT,
+     };
+     struct reftable_record rec = {
+             .type = BLOCK_TYPE_REF,
+     };
+     size_t i = 0;
+     int ret;
+     struct block_reader br = { 0 };
+     struct block_iter it = BLOCK_ITER_INIT;
+     struct reftable_buf want = REFTABLE_BUF_INIT, buf = REFTABLE_BUF_INIT;
+
+     REFTABLE_CALLOC_ARRAY(block.data, block_size);
+     cl_assert(block.data != NULL);
Quoted 9 lines

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

Quoted 5 lines
t/unit-tests/u-reftable-block.c new file +5 -0
+     block.len = block_size;
+     block_source_from_buf(&block.source ,&buf);
+     ret = block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
+                             header_off, hash_size(REFTABLE_HASH_SHA1));
+     cl_assert(ret == 0);

Same comment here, asserts like this can be retained as cl_assert(!ret).

ohh, I didn't know this was possible.

Quoted 25 lines
Quoted 9 lines
t/unit-tests/u-reftable-block.c new file +9 -0
+     rec.u.ref.refname = (char *) "";
+     rec.u.ref.value_type = REFTABLE_REF_DELETION;
+     ret = block_writer_add(&bw, &rec);
+     cl_assert_equal_i(ret, REFTABLE_API_ERROR);
+
+     for (i = 0; i < N; i++) {
+             rec.u.ref.refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
+             rec.u.ref.value_type = REFTABLE_REF_VAL1;
+             memset(rec.u.ref.value.val1, i, REFTABLE_HASH_SIZE_SHA1);

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

Quoted 10 lines
t/unit-tests/u-reftable-block.c new file +10 -0
+
+             recs[i] = rec;
+             ret = block_writer_add(&bw, &rec);
+             rec.u.ref.refname = NULL;
+             rec.u.ref.value_type = REFTABLE_REF_DELETION;
+             cl_assert_equal_i(ret, 0);
+     }
+
+     ret = block_writer_finish(&bw);
+     cl_assert(ret > 0);

It's a bit unfortunate that we have to use cl_assert() here, but that isn't the fault of this series. I do have a pull request pending upstream that introduces integer comparisons. Once we've updated to that version I'll go through our unit tests and adapt callsites accordingly.

Quoted 7 lines

[snip]

Quoted 1 line

+void test_reftable_block__ref_read_write(void)

This one here should be called __index_read_write(). I guess you confused the first and and this test name with one another.

Patrick

Ah, okay, Thanks!

Best
Seyi

#10 lore raw

Re: [PATCH v2 03/10] t/unit-tests: convert reftable block test to use clar

Quoted 16 lines · Seyi Chamber
Quoted 14 lines · Patrick Steinhardt

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

Quoted 5 lines · Seyi Kuforiji
t/unit-tests/t-reftable-block.c deleted +0 -0
deleted file mode 100644
index 22040aeefa..0000000000

Hm, why is this recorded as a delete and creation? Weird, inspecting the diff locally properly shows it as a rename, which makes it a ton easier to review. It would be great if you could try to play around with the --find-renames option in the next iteration of this series and double check that these are shown as a rename.

Quoted 2 lines

I used --find-renames=90 for this patch series. Is there any recommended number to set it to? :/

Note that "90" also isn't interpreted the way you think it is, at least going by git-format-patch(1):

-M[<n>], --find-renames[=<n>]
Detect renames. If <n> is specified, it is a threshold on the similarity index (i.e. amount of addition/deletions compared to the file’s size). For example, -M90% means Git should consider a delete/add pair to be a rename if more than 90% of the file hasn’t changed. Without a % sign, the number is to be read as a fraction, with a decimal point before it. I.e., -M5 becomes 0.5, and is thus the same as -M50%. Similarly, -M05 is the same as -M5%. To limit detection to exact renames, use -M100%. The default similarity index is 50%.

What you probably wanted to say is --find-renames=90%, but without the percentage sign it is read as a fraction, where 1 means "exact copy" and 0 means "all different".

I'd recommend to just play around with this option and inspect the outcome until things look reviewable. :)

Patrick

#11 lore raw

Re: [PATCH v2 03/10] t/unit-tests: convert reftable block test to use clar

Quoted 11 lines · Patrick Steinhardt

-M[<n>], --find-renames[=<n>]
Detect renames. If <n> is specified, it is a threshold on the similarity index (i.e. amount of addition/deletions compared to the file’s size). For example, -M90% means Git should consider a delete/add pair to be a rename if more than 90% of the file hasn’t changed. Without a % sign, the number is to be read as a fraction, with a decimal point before it. I.e., -M5 becomes 0.5, and is thus the same as -M50%. Similarly, -M05 is the same as -M5%. To limit detection to exact renames, use -M100%. The default similarity index is 50%.

What you probably wanted to say is --find-renames=90%, but without the percentage sign it is read as a fraction, where 1 means "exact copy" and 0 means "all different".

I am confused. -M<number> without trailing %-sign is taken as fraction against 1 followed by the same number of '0' has the <number> has digits. -M5 is 5 over 10, -M50 is 50 over 100. -M90 is 90 over 100, so -M90 and -M90% should mean the same thing.

But you are right. When you want to claim your pre- and post- image files still correspond with each other in a meaningful way, even after making extensive change, you would want to _lower_, not raise, your similarity threshold. If the default is -M50, then -M90 would be a useful option to reject what Git (mistakenly) thinks are renames and tell it to instead consider they are removals and creations.

THanks.

#12 lore raw

Re: [PATCH v2 03/10] t/unit-tests: convert reftable block test to use clar

Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Patrick Steinhardt

-M[<n>], --find-renames[=<n>]
Detect renames. If <n> is specified, it is a threshold on the similarity index (i.e. amount of addition/deletions compared to the file’s size). For example, -M90% means Git should consider a delete/add pair to be a rename if more than 90% of the file hasn’t changed. Without a % sign, the number is to be read as a fraction, with a decimal point before it. I.e., -M5 becomes 0.5, and is thus the same as -M50%. Similarly, -M05 is the same as -M5%. To limit detection to exact renames, use -M100%. The default similarity index is 50%.

Quoted 8 lines
Quoted 3 lines

What you probably wanted to say is --find-renames=90%, but without the percentage sign it is read as a fraction, where 1 means "exact copy" and 0 means "all different".

I am confused. -M<number> without trailing %-sign is taken as fraction against 1 followed by the same number of '0' has the <number> has digits. -M5 is 5 over 10, -M50 is 50 over 100. -M90 is 90 over 100, so -M90 and -M90% should mean the same thing.

Hm, I guess _I_ was confused then. It doesn't feel natural to me that -M90 would mean 90% whereas -M5 means 50%, and the documentation isn't quite clear about this, either.

Quoted 6 lines

But you are right. When you want to claim your pre- and post- image files still correspond with each other in a meaningful way, even after making extensive change, you would want to _lower_, not raise, your similarity threshold. If the default is -M50, then -M90 would be a useful option to reject what Git (mistakenly) thinks are renames and tell it to instead consider they are removals and creations.

Yeah, at least that point stands :)

Patrick

#13 lore raw

PATCH v2 4/10 t/unit-tests: convert reftable merged test to use clar

In reply to Seyi Kuforiji

Adapt reftable merged test file to use clar testing framework by using clar assertions where necessary.

---
 Makefile                         |   2 +-
 t/meson.build                    |   2 +-
 t/unit-tests/t-reftable-merged.c | 546 -------------------------------
 t/unit-tests/u-reftable-merged.c | 515 +++++++++++++++++++++++++++++
 4 files changed, 517 insertions(+), 548 deletions(-)
 delete mode 100644 t/unit-tests/t-reftable-merged.c
 create mode 100644 t/unit-tests/u-reftable-merged.c
Makefile +1 -1
index 239c575dad..2b1642465a 100644
@@ -1364,6 +1364,7 @@ CLAR_TEST_SUITES += u-oidtree
 CLAR_TEST_SUITES += u-prio-queue
 CLAR_TEST_SUITES += u-reftable-basics
 CLAR_TEST_SUITES += u-reftable-block
+CLAR_TEST_SUITES += u-reftable-merged
 CLAR_TEST_SUITES += u-reftable-tree
 CLAR_TEST_SUITES += u-strbuf
 CLAR_TEST_SUITES += u-strcmp-offset
@@ -1376,7 +1377,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
 
-UNIT_TEST_PROGRAMS += t-reftable-merged
 UNIT_TEST_PROGRAMS += t-reftable-pq
 UNIT_TEST_PROGRAMS += t-reftable-reader
 UNIT_TEST_PROGRAMS += t-reftable-readwrite
t/meson.build +1 -1
index e0d723e74b..70a783ba80 100644
@@ -10,6 +10,7 @@ clar_test_suites = [
   'unit-tests/u-prio-queue.c',
   'unit-tests/u-reftable-basics.c',
   'unit-tests/u-reftable-block.c',
+  'unit-tests/u-reftable-merged.c',
   'unit-tests/u-reftable-tree.c',
   'unit-tests/u-strbuf.c',
   'unit-tests/u-strcmp-offset.c',
@@ -56,7 +57,6 @@ clar_unit_tests = executable('unit-tests',
 test('unit-tests', clar_unit_tests)
 
 unit_test_programs = [
-  'unit-tests/t-reftable-merged.c',
   'unit-tests/t-reftable-pq.c',
   'unit-tests/t-reftable-reader.c',
   'unit-tests/t-reftable-readwrite.c',
t/unit-tests/t-reftable-merged.c deleted +0 -546

546 lines not on this page · raw message

t/unit-tests/u-reftable-merged.c new file +515 -0

515 lines not on this page · raw message

Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH v2 04/10] t/unit-tests: convert reftable merged test to use clar

Quoted 53 lines · Seyi Kuforiji
t/unit-tests/u-reftable-merged.c new file +47 -0
new file mode 100644
index 0000000000..48c8f9f6b5
@@ -0,0 +1,515 @@
+/*
+Copyright 2020 Google LLC
+
+Use of this source code is governed by a BSD-style
+license that can be found in the LICENSE file or at
+https://developers.google.com/open-source/licenses/bsd
+*/
+
+#include "unit-test.h"
+#include "lib-reftable.h"
+#include "reftable/blocksource.h"
+#include "reftable/constants.h"
+#include "reftable/merged.h"
+#include "reftable/reader.h"
+#include "reftable/reftable-error.h"
+#include "reftable/reftable-merged.h"
+#include "reftable/reftable-writer.h"
+
+static struct reftable_merged_table *
+merged_table_from_records(struct reftable_ref_record **refs,
+			  struct reftable_block_source **source,
+			  struct reftable_reader ***readers, const size_t *sizes,
+			  struct reftable_buf *buf, const size_t n)
+{
+	struct reftable_merged_table *mt = NULL;
+	struct reftable_write_options opts = {
+		.block_size = 256,
+	};
+	int err;
+
+	REFTABLE_CALLOC_ARRAY(*readers, n);
+	cl_assert(*readers != NULL);
+	REFTABLE_CALLOC_ARRAY(*source, n);
+	cl_assert(*source != NULL);
+
+	for (size_t i = 0; i < n; i++) {
+		cl_reftable_write_to_buf(&buf[i], refs[i], sizes[i], NULL, 0, &opts);
+		block_source_from_buf(&(*source)[i], &buf[i]);
+
+		err = reftable_reader_new(&(*readers)[i], &(*source)[i],
+					  "name");
+		cl_assert(err == 0);
+	}
+
+	err = reftable_merged_table_new(&mt, *readers, n, REFTABLE_HASH_SHA1);
+	cl_assert(err == 0);
+	return mt;

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

Quoted 10 lines
t/unit-tests/u-reftable-merged.c new file +10 -0
+}
+
+static void readers_destroy(struct reftable_reader **readers, const size_t n)
+{
+	for (size_t i = 0; i < n; i++)
+		reftable_reader_decref(readers[i]);
+	reftable_free(readers);
+}
+
+void test_reftable_merged__merged_single_record(void)

This should be __single_record(void). Same for the others, the __merged prefix is somewhat duplicate as you already have it in the test suite name.

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

Quoted 1 line
t/unit-tests/u-reftable-merged.c new file +1 -0
+void test_reftable_merged__merged_seek_multiple_times(void)

So, same here, let's rename to __seek_multiple_times().

Quoted 44 lines
t/unit-tests/u-reftable-merged.c new file +44 -0
+{
+	struct reftable_ref_record r1[] = {
+		{
+			.refname = (char *) "a",
+			.update_index = 1,
+			.value_type = REFTABLE_REF_VAL1,
+			.value.val1 = { 1 },
+		},
+		{
+			.refname = (char *) "c",
+			.update_index = 1,
+			.value_type = REFTABLE_REF_VAL1,
+			.value.val1 = { 2 },
+		}
+	};
+	struct reftable_ref_record r2[] = {
+		{
+			.refname = (char *) "b",
+			.update_index = 2,
+			.value_type = REFTABLE_REF_VAL1,
+			.value.val1 = { 3 },
+		},
+		{
+			.refname = (char *) "d",
+			.update_index = 2,
+			.value_type = REFTABLE_REF_VAL1,
+			.value.val1 = { 4 },
+		},
+	};
+	struct reftable_ref_record *refs[] = {
+		r1, r2,
+	};
+	size_t sizes[] = {
+		ARRAY_SIZE(r1), ARRAY_SIZE(r2),
+	};
+	struct reftable_buf bufs[] = {
+		REFTABLE_BUF_INIT, REFTABLE_BUF_INIT,
+	};
+	struct reftable_block_source *sources = NULL;
+	struct reftable_reader **readers = NULL;
+	struct reftable_ref_record rec = { 0 };
+	struct reftable_iterator it = { 0 };
+	struct reftable_merged_table *mt;
+

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

Quoted 10 lines
t/unit-tests/u-reftable-merged.c new file +10 -0
+	mt = merged_table_from_records(refs, &sources, &readers, sizes, bufs, 2);
+	merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
+
+	for (size_t i = 0; i < 5; i++) {
+		int err = reftable_iterator_seek_ref(&it, "c");
+		cl_assert(err == 0);
+
+		cl_assert(reftable_iterator_next_ref(&it, &rec) == 0);
+		cl_assert_equal_i(reftable_ref_record_equal(&rec, &r1[1],
+													REFTABLE_HASH_SIZE_SHA1), 1);

Indentation is wrong. Our tabs are 8 spaces, so this is indented too deep now.

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

Quoted 3 lines
t/unit-tests/u-reftable-merged.c new file +3 -0
+		cl_assert(reftable_iterator_next_ref(&it, &rec) == 0);
+		cl_assert_equal_i(reftable_ref_record_equal(&rec, &r2[1],
+													REFTABLE_HASH_SIZE_SHA1), 1);

Same here. There are also other instances in this file.

Patrick

#15 lore raw

PATCH v2 5/10 t/unit-tests: convert reftable pq test to use clar

In reply to Seyi Kuforiji

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

---
 Makefile                     |   2 +-
 t/meson.build                |   2 +-
 t/unit-tests/t-reftable-pq.c | 161 -----------------------------------
 t/unit-tests/u-reftable-pq.c | 152 +++++++++++++++++++++++++++++++++
 4 files changed, 154 insertions(+), 163 deletions(-)
 delete mode 100644 t/unit-tests/t-reftable-pq.c
 create mode 100644 t/unit-tests/u-reftable-pq.c
Makefile +1 -1
index 2b1642465a..4142927d0a 100644
@@ -1365,6 +1365,7 @@ CLAR_TEST_SUITES += u-prio-queue
 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-tree
 CLAR_TEST_SUITES += u-strbuf
 CLAR_TEST_SUITES += u-strcmp-offset
@@ -1377,7 +1378,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
 
-UNIT_TEST_PROGRAMS += t-reftable-pq
 UNIT_TEST_PROGRAMS += t-reftable-reader
 UNIT_TEST_PROGRAMS += t-reftable-readwrite
 UNIT_TEST_PROGRAMS += t-reftable-record
t/meson.build +1 -1
index 70a783ba80..9bded2d15c 100644
@@ -11,6 +11,7 @@ clar_test_suites = [
   'unit-tests/u-reftable-basics.c',
   'unit-tests/u-reftable-block.c',
   'unit-tests/u-reftable-merged.c',
+  'unit-tests/u-reftable-pq.c',
   'unit-tests/u-reftable-tree.c',
   'unit-tests/u-strbuf.c',
   'unit-tests/u-strcmp-offset.c',
@@ -57,7 +58,6 @@ clar_unit_tests = executable('unit-tests',
 test('unit-tests', clar_unit_tests)
 
 unit_test_programs = [
-  'unit-tests/t-reftable-pq.c',
   'unit-tests/t-reftable-reader.c',
   'unit-tests/t-reftable-readwrite.c',
   'unit-tests/t-reftable-record.c',
t/unit-tests/t-reftable-pq.c deleted +0 -161

161 lines not on this page · raw message

t/unit-tests/u-reftable-pq.c new file +152 -0

152 lines not on this page · raw message

Signature · 1 line
2.43.0
#16 lore raw

PATCH v2 6/10 t/unit-tests: convert reftable reader test to use clar

In reply to Seyi Kuforiji

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

---
 Makefile                         |  2 +-
 t/meson.build                    |  2 +-
 t/unit-tests/t-reftable-reader.c | 96 --------------------------------
 t/unit-tests/u-reftable-reader.c | 78 ++++++++++++++++++++++++++
 4 files changed, 80 insertions(+), 98 deletions(-)
 delete mode 100644 t/unit-tests/t-reftable-reader.c
 create mode 100644 t/unit-tests/u-reftable-reader.c
Makefile +1 -1
index 4142927d0a..d3e8677653 100644
@@ -1366,6 +1366,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-reader
 CLAR_TEST_SUITES += u-reftable-tree
 CLAR_TEST_SUITES += u-strbuf
 CLAR_TEST_SUITES += u-strcmp-offset
@@ -1378,7 +1379,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
 
-UNIT_TEST_PROGRAMS += t-reftable-reader
 UNIT_TEST_PROGRAMS += t-reftable-readwrite
 UNIT_TEST_PROGRAMS += t-reftable-record
 UNIT_TEST_PROGRAMS += t-reftable-stack
t/meson.build +1 -1
index 9bded2d15c..6a22bd2790 100644
@@ -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-reader.c',
   'unit-tests/u-reftable-tree.c',
   'unit-tests/u-strbuf.c',
   'unit-tests/u-strcmp-offset.c',
@@ -58,7 +59,6 @@ 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',
t/unit-tests/t-reftable-reader.c deleted +0 -96

96 lines not on this page · raw message

t/unit-tests/u-reftable-reader.c new file +78 -0

78 lines not on this page · raw message

Signature · 1 line
2.43.0
#17 lore raw

Re: [PATCH v2 06/10] t/unit-tests: convert reftable reader test to use clar

Quoted 22 lines · Seyi Kuforiji
t/unit-tests/u-reftable-reader.c new file +16 -0
new file mode 100644
index 0000000000..6c35063105
@@ -0,0 +1,78 @@
+#include "unit-test.h"
+#include "lib-reftable.h"
+#include "reftable/blocksource.h"
+#include "reftable/reader.h"
+
+void test_reftable_reader__seek_once(void)
+{
+	struct reftable_ref_record records[] = {
+		{
+			.refname = (char *) "refs/heads/main",
+			.value_type = REFTABLE_REF_VAL1,
+			.value.val1 = { 42 },
+		},
+	};
+	struct reftable_block_source source = { 0 };
+	struct reftable_ref_record ref = { 0 };

t/unit-tests/u-reftable-reader.c line 26

Quoted 10 lines
t/unit-tests/u-reftable-reader.c new file +10 -0
+	struct reftable_iterator it = { 0 };
+	struct reftable_reader *reader;
+	struct reftable_buf buf = REFTABLE_BUF_INIT;
+
+	cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
+	block_source_from_buf(&source, &buf);
+
+	cl_assert(reftable_reader_new(&reader, &source, "name") == 0);
+
+

Nit: empty newline.

t/unit-tests/u-reftable-reader.c line 33

Quoted 7 lines
t/unit-tests/u-reftable-reader.c new file +7 -0
+	reftable_reader_init_ref_iterator(reader, &it);
+	cl_assert(reftable_iterator_seek_ref(&it, "") == 0);
+	cl_assert(reftable_iterator_next_ref(&it, &ref) == 0);
+
+	cl_assert_equal_i(reftable_ref_record_equal(&ref, &records[0],
+												REFTABLE_HASH_SIZE_SHA1), 1);
+

Indentation is wrong again.

Quoted 26 lines
t/unit-tests/u-reftable-reader.c new file +26 -0
+	cl_assert_equal_i(reftable_iterator_next_ref(&it, &ref), 1);
+
+	reftable_ref_record_release(&ref);
+	reftable_iterator_destroy(&it);
+	reftable_reader_decref(reader);
+	reftable_buf_release(&buf);
+}
+
+void test_reftable_reader__reseek(void)
+{
+	struct reftable_ref_record records[] = {
+		{
+			.refname = (char *) "refs/heads/main",
+			.value_type = REFTABLE_REF_VAL1,
+			.value.val1 = { 42 },
+		},
+	};
+	struct reftable_block_source source = { 0 };
+	struct reftable_ref_record ref = { 0 };
+	struct reftable_iterator it = { 0 };
+	struct reftable_reader *reader;
+	struct reftable_buf buf = REFTABLE_BUF_INIT;
+
+	cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
+	block_source_from_buf(&source, &buf);
+

t/unit-tests/u-reftable-reader.c line 69

Quoted 10 lines
t/unit-tests/u-reftable-reader.c new file +10 -0
+	cl_assert(reftable_reader_new(&reader, &source, "name") == 0);
+
+	reftable_reader_init_ref_iterator(reader, &it);
+
+	for (size_t i = 0; i < 5; i++) {
+		cl_assert(reftable_iterator_seek_ref(&it, "") == 0);
+		cl_assert(reftable_iterator_next_ref(&it, &ref) == 0);
+
+		cl_assert_equal_i(reftable_ref_record_equal(&ref, &records[0],
+													REFTABLE_HASH_SIZE_SHA1), 1);

Here, as well.

Patrick

#18 lore raw

PATCH v2 7/10 t/unit-tests: convert reftable readwrite test to use clar

In reply to Seyi Kuforiji

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

---
 Makefile                            |   2 +-
 t/meson.build                       |   2 +-
 t/unit-tests/t-reftable-readwrite.c | 985 ----------------------------
 t/unit-tests/u-reftable-readwrite.c | 870 ++++++++++++++++++++++++
 4 files changed, 872 insertions(+), 987 deletions(-)
 delete mode 100644 t/unit-tests/t-reftable-readwrite.c
 create mode 100644 t/unit-tests/u-reftable-readwrite.c
Makefile +1 -1
index d3e8677653..88b6851b37 100644
@@ -1367,6 +1367,7 @@ CLAR_TEST_SUITES += u-reftable-block
 CLAR_TEST_SUITES += u-reftable-merged
 CLAR_TEST_SUITES += u-reftable-pq
 CLAR_TEST_SUITES += u-reftable-reader
+CLAR_TEST_SUITES += u-reftable-readwrite
 CLAR_TEST_SUITES += u-reftable-tree
 CLAR_TEST_SUITES += u-strbuf
 CLAR_TEST_SUITES += u-strcmp-offset
@@ -1379,7 +1380,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
 
-UNIT_TEST_PROGRAMS += t-reftable-readwrite
 UNIT_TEST_PROGRAMS += t-reftable-record
 UNIT_TEST_PROGRAMS += t-reftable-stack
 UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
t/meson.build +1 -1
index 6a22bd2790..7722d177e2 100644
@@ -13,6 +13,7 @@ clar_test_suites = [
   'unit-tests/u-reftable-merged.c',
   'unit-tests/u-reftable-pq.c',
   'unit-tests/u-reftable-reader.c',
+  'unit-tests/u-reftable-readwrite.c',
   'unit-tests/u-reftable-tree.c',
   'unit-tests/u-strbuf.c',
   'unit-tests/u-strcmp-offset.c',
@@ -59,7 +60,6 @@ clar_unit_tests = executable('unit-tests',
 test('unit-tests', clar_unit_tests)
 
 unit_test_programs = [
-  'unit-tests/t-reftable-readwrite.c',
   'unit-tests/t-reftable-record.c',
   'unit-tests/t-reftable-stack.c',
 ]
t/unit-tests/t-reftable-readwrite.c deleted +0 -985

985 lines not on this page · raw message

t/unit-tests/u-reftable-readwrite.c new file +870 -0

870 lines not on this page · raw message

Signature · 1 line
2.43.0
#19 lore raw

Re: [PATCH v2 07/10] t/unit-tests: convert reftable readwrite test to use clar

Quoted 30 lines · Seyi Kuforiji
t/unit-tests/u-reftable-readwrite.c new file +24 -0
new file mode 100644
index 0000000000..3d6bdcfceb
@@ -0,0 +1,870 @@
+/*
+Copyright 2020 Google LLC
+
+Use of this source code is governed by a BSD-style
+license that can be found in the LICENSE file or at
+https://developers.google.com/open-source/licenses/bsd
+*/
+
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
+#include "unit-test.h"
+#include "lib-reftable.h"
+#include "reftable/basics.h"
+#include "reftable/blocksource.h"
+#include "reftable/reader.h"
+#include "reftable/reftable-error.h"
+#include "reftable/reftable-writer.h"
+#include "strbuf.h"
+
+static const int update_index = 5;
+
+void test_reftable_readwrite__buffer(void)
+{
+	struct reftable_buf buf = REFTABLE_BUF_INIT;

t/unit-tests/u-reftable-readwrite.c line 34

Quoted 10 lines
t/unit-tests/u-reftable-readwrite.c new file +10 -0
+	struct reftable_block_source source = { 0 };
+	struct reftable_block out = { 0 };
+	int n;
+	uint8_t in[] = "hello";
+	cl_assert(reftable_buf_add(&buf, in, sizeof(in)) == 0);
+	block_source_from_buf(&source, &buf);
+	cl_assert_equal_i(block_source_size(&source), 6);
+	n = block_source_read_block(&source, &out, 0, sizeof(in));
+	cl_assert_equal_i(n, sizeof(in));
+	cl_assert(memcmp(in, out.data, n) == 0);

It feels inconsisetnt that we use cl_assert_equal_i() to check for n but cl_assert(... == 0) here.

Patrick

#20 lore raw

PATCH v2 8/10 t/unit-tests: convert reftable record test to use clar

In reply to Seyi Kuforiji

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

---
 Makefile                         |   2 +-
 t/meson.build                    |   2 +-
 t/unit-tests/t-reftable-record.c | 585 -------------------------------
 t/unit-tests/u-reftable-record.c | 565 +++++++++++++++++++++++++++++
 4 files changed, 567 insertions(+), 587 deletions(-)
 delete mode 100644 t/unit-tests/t-reftable-record.c
 create mode 100644 t/unit-tests/u-reftable-record.c
Makefile +1 -1
index 88b6851b37..cd9db9adf1 100644
@@ -1368,6 +1368,7 @@ CLAR_TEST_SUITES += u-reftable-merged
 CLAR_TEST_SUITES += u-reftable-pq
 CLAR_TEST_SUITES += u-reftable-reader
 CLAR_TEST_SUITES += u-reftable-readwrite
+CLAR_TEST_SUITES += u-reftable-record
 CLAR_TEST_SUITES += u-reftable-tree
 CLAR_TEST_SUITES += u-strbuf
 CLAR_TEST_SUITES += u-strcmp-offset
@@ -1380,7 +1381,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
 
-UNIT_TEST_PROGRAMS += t-reftable-record
 UNIT_TEST_PROGRAMS += t-reftable-stack
 UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
 UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
t/meson.build +1 -1
index 7722d177e2..756cb2a2dd 100644
@@ -14,6 +14,7 @@ clar_test_suites = [
   'unit-tests/u-reftable-pq.c',
   'unit-tests/u-reftable-reader.c',
   'unit-tests/u-reftable-readwrite.c',
+  'unit-tests/u-reftable-record.c',
   'unit-tests/u-reftable-tree.c',
   'unit-tests/u-strbuf.c',
   'unit-tests/u-strcmp-offset.c',
@@ -60,7 +61,6 @@ clar_unit_tests = executable('unit-tests',
 test('unit-tests', clar_unit_tests)
 
 unit_test_programs = [
-  'unit-tests/t-reftable-record.c',
   'unit-tests/t-reftable-stack.c',
 ]
 
t/unit-tests/t-reftable-record.c deleted +0 -585

585 lines not on this page · raw message

t/unit-tests/u-reftable-record.c new file +565 -0

565 lines not on this page · raw message

Signature · 1 line
2.43.0
#21 lore raw

PATCH v2 9/10 t/unit-tests: convert reftable stack test to use clar

In reply to Seyi Kuforiji

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

This marks the end of all unit tests migrated away from the unit-tests/t-*.c pattern, there are no longer any files matching that glob. Remove the sanity check for t-*.c files to prevent Meson configuration errors during CI and local builds.

---
 Makefile                        |    2 +-
 t/meson.build                   |    3 +-
 t/unit-tests/t-reftable-stack.c | 1451 -------------------------------
 t/unit-tests/u-reftable-stack.c | 1247 ++++++++++++++++++++++++++
 4 files changed, 1249 insertions(+), 1454 deletions(-)
 delete mode 100644 t/unit-tests/t-reftable-stack.c
 create mode 100644 t/unit-tests/u-reftable-stack.c
Makefile +1 -1
index cd9db9adf1..0b42893611 100644
@@ -1369,6 +1369,7 @@ CLAR_TEST_SUITES += u-reftable-pq
 CLAR_TEST_SUITES += u-reftable-reader
 CLAR_TEST_SUITES += u-reftable-readwrite
 CLAR_TEST_SUITES += u-reftable-record
+CLAR_TEST_SUITES += u-reftable-stack
 CLAR_TEST_SUITES += u-reftable-tree
 CLAR_TEST_SUITES += u-strbuf
 CLAR_TEST_SUITES += u-strcmp-offset
@@ -1381,7 +1382,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
 
-UNIT_TEST_PROGRAMS += t-reftable-stack
 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
t/meson.build +1 -2
index 756cb2a2dd..8fa00fc9ef 100644
@@ -15,6 +15,7 @@ clar_test_suites = [
   'unit-tests/u-reftable-reader.c',
   'unit-tests/u-reftable-readwrite.c',
   'unit-tests/u-reftable-record.c',
+  'unit-tests/u-reftable-stack.c',
   'unit-tests/u-reftable-tree.c',
   'unit-tests/u-strbuf.c',
   'unit-tests/u-strcmp-offset.c',
@@ -61,7 +62,6 @@ clar_unit_tests = executable('unit-tests',
 test('unit-tests', clar_unit_tests)
 
 unit_test_programs = [
-  'unit-tests/t-reftable-stack.c',
 ]
 
 foreach unit_test_program : unit_test_programs
@@ -1102,7 +1102,6 @@ integration_tests = [
 # sufficient to catch missing test suites in our CI though.
 foreach glob, tests : {
   't[0-9][0-9][0-9][0-9]-*.sh': integration_tests,
-  'unit-tests/t-*.c': unit_test_programs,
   'unit-tests/u-*.c': clar_test_suites,
 }
   actual_tests = run_command(shell, '-c', 'ls ' + glob,
t/unit-tests/t-reftable-stack.c deleted +0 -1451

1,451 lines not on this page · raw message

t/unit-tests/u-reftable-stack.c new file +1247 -0

1,247 lines not on this page · raw message

Signature · 1 line
2.43.0
#22 lore raw

Re: [PATCH v2 09/10] t/unit-tests: convert reftable stack test to use clar

t/meson.build integration_tests = [ · line 1107

Quoted 12 lines · Seyi Kuforiji
t/meson.build +0 -1
index 756cb2a2dd..8fa00fc9ef 100644
@@ -1102,7 +1102,6 @@ integration_tests = [
 # sufficient to catch missing test suites in our CI though.
 foreach glob, tests : {
   't[0-9][0-9][0-9][0-9]-*.sh': integration_tests,
-  'unit-tests/t-*.c': unit_test_programs,
   'unit-tests/u-*.c': clar_test_suites,
 }
   actual_tests = run_command(shell, '-c', 'ls ' + glob,

Okay. Ideally this would be moved into the next commit where we remove the infrastructure for our old-style unit tests, but we can't because the glob matches nothing anymore and thus causes an error.

Also, we have a "check-meson" target in "t/Makefile". Don't we have to remove unit tests from there, too?

Patrick

#23 lore raw

Re: [PATCH v2 09/10] t/unit-tests: convert reftable stack test to use clar

Quoted 19 lines · Patrick Steinhardt

t/meson.build integration_tests = [ · line 1107

Quoted 12 lines · Seyi Kuforiji
t/meson.build +0 -1
index 756cb2a2dd..8fa00fc9ef 100644
@@ -1102,7 +1102,6 @@ integration_tests = [
 # sufficient to catch missing test suites in our CI though.
 foreach glob, tests : {
   't[0-9][0-9][0-9][0-9]-*.sh': integration_tests,
-  'unit-tests/t-*.c': unit_test_programs,
   'unit-tests/u-*.c': clar_test_suites,
 }
   actual_tests = run_command(shell, '-c', 'ls ' + glob,

Okay. Ideally this would be moved into the next commit where we remove the infrastructure for our old-style unit tests, but we can't because the glob matches nothing anymore and thus causes an error.

Quoted 4 lines

Also, we have a "check-meson" target in "t/Makefile". Don't we have to remove unit tests from there, too?

Patrick

You are referring to this, yes?

`@# awk acts up when trying to match single quotes, so we use \047 instead.
    @mkdir -p mesontmp && \
    printf "%s\n" \
        "integration_tests t[0-9][0-9][0-9][0-9]-*.sh" \
        "unit_test_programs unit-tests/t-*.c" \
        "clar_test_suites unit-tests/u-*.c" | \
    while read -r variable pattern; do \`

I've hardly taken a look at the t/Makefile, given my very little interaction with the file throughout the test conversions.

Best
Seyi

#24 lore raw

Re: [PATCH v2 09/10] t/unit-tests: convert reftable stack test to use clar

Quoted 34 lines · Seyi Chamber
Quoted 19 lines · Patrick Steinhardt

t/meson.build integration_tests = [ · line 1107

Quoted 12 lines · Seyi Kuforiji
t/meson.build +0 -1
index 756cb2a2dd..8fa00fc9ef 100644
@@ -1102,7 +1102,6 @@ integration_tests = [
 # sufficient to catch missing test suites in our CI though.
 foreach glob, tests : {
   't[0-9][0-9][0-9][0-9]-*.sh': integration_tests,
-  'unit-tests/t-*.c': unit_test_programs,
   'unit-tests/u-*.c': clar_test_suites,
 }
   actual_tests = run_command(shell, '-c', 'ls ' + glob,

Okay. Ideally this would be moved into the next commit where we remove the infrastructure for our old-style unit tests, but we can't because the glob matches nothing anymore and thus causes an error.

Quoted 4 lines

Also, we have a "check-meson" target in "t/Makefile". Don't we have to remove unit tests from there, too?

Patrick

You are referring to this, yes?

`@# awk acts up when trying to match single quotes, so we use \047 instead.
    @mkdir -p mesontmp && \
    printf "%s\n" \
        "integration_tests t[0-9][0-9][0-9][0-9]-*.sh" \
        "unit_test_programs unit-tests/t-*.c" \
        "clar_test_suites unit-tests/u-*.c" | \
    while read -r variable pattern; do \`
Quoted 2 lines

I've hardly taken a look at the t/Makefile, given my very little interaction with the file throughout the test conversions.

Yes, that's the part I was referring to.

Patrick

#25 lore raw

PATCH v2 10/10 t/unit-tests: adapt lib-reftable{c,h} helper functions to clar

In reply to Seyi Kuforiji

Helper functions defined in t/unit-tests/lib-reftable.{c,h} are required for the reftable-related test files to run efficeintly. In the current implementation these functions are designed to conform with our homegrown unit-testing structure. So in other to convert the reftable test files, there is need for a clar specific implementation of these helper functions.

type cast for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++) Adapt functions in lib-reftable.{c,h} to use clar. These functions conform with the clar testing framework and become available for all reftable-related test files implemented using the clar testing framework, which requires them. This change migrates the helper functions back into lib-reftable.{c,h}.

---
 Makefile                    |  4 +-
 t/meson.build               |  4 +-
 t/unit-tests/lib-reftable.c | 26 +++++------
 t/unit-tests/lib-reftable.h |  6 +--
 t/unit-tests/unit-test.c    | 93 -------------------------------------
 t/unit-tests/unit-test.h    | 16 -------
 6 files changed, 20 insertions(+), 129 deletions(-)
Makefile +2 -2
index 0b42893611..7e646e16ee 100644
@@ -1379,12 +1379,12 @@ CLAR_TEST_SUITES += u-urlmatch-normalization
 CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
 CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
-CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
+CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
+CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 
 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
 
 # xdiff and reftable libs may in turn depend on what is in libgit.a
 GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)
t/meson.build +2 -2
index 8fa00fc9ef..7c305a90b5 100644
@@ -26,8 +26,9 @@ clar_test_suites = [
 
 clar_sources = [
   'unit-tests/clar/clar.c',
+  'unit-tests/lib-oid.c',
+  'unit-tests/lib-reftable.c',
   'unit-tests/unit-test.c',
-  'unit-tests/lib-oid.c'
 ]
 
 clar_decls_h = custom_target(
@@ -69,7 +70,6 @@ foreach unit_test_program : unit_test_programs
   unit_test = executable(unit_test_name,
     sources: [
       'unit-tests/test-lib.c',
-      'unit-tests/lib-reftable.c',
       unit_test_program,
     ],
     dependencies: [libgit_commonmain],
t/unit-tests/lib-reftable.c +13 -13
index 8a69612266..414364166f 100644
@@ -1,12 +1,12 @@
 #define DISABLE_SIGN_COMPARE_WARNINGS
 
 #include "lib-reftable.h"
-#include "test-lib.h"
+#include "unit-test.h"
 #include "reftable/constants.h"
 #include "reftable/writer.h"
 #include "strbuf.h"
 
-void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
 {
 	memset(p, (uint8_t)i, hash_size(id));
 }
@@ -22,17 +22,17 @@ static int strbuf_writer_flush(void *arg UNUSED)
 	return 0;
 }
 
-struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
 						 struct reftable_write_options *opts)
 {
 	struct reftable_writer *writer;
 	int ret = reftable_writer_new(&writer, &strbuf_writer_write, &strbuf_writer_flush,
 				      buf, opts);
-	check(!ret);
+	cl_assert(ret == 0);
 	return writer;
 }
 
-void t_reftable_write_to_buf(struct reftable_buf *buf,
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
 			     struct reftable_ref_record *refs,
 			     size_t nrefs,
 			     struct reftable_log_record *logs,
@@ -64,35 +64,35 @@ void t_reftable_write_to_buf(struct reftable_buf *buf,
 			min = ui;
 	}
 
-	writer = t_reftable_strbuf_writer(buf, &opts);
+	writer = cl_reftable_strbuf_writer(buf, &opts);
 	reftable_writer_set_limits(writer, min, max);
 
 	if (nrefs) {
 		ret = reftable_writer_add_refs(writer, refs, nrefs);
-		check_int(ret, ==, 0);
+		cl_assert_equal_i(ret, 0);
 	}
 
 	if (nlogs) {
 		ret = reftable_writer_add_logs(writer, logs, nlogs);
-		check_int(ret, ==, 0);
+		cl_assert_equal_i(ret, 0);
 	}
 
 	ret = reftable_writer_close(writer);
-	check_int(ret, ==, 0);
+	cl_assert_equal_i(ret, 0);
 
 	stats = reftable_writer_stats(writer);
-	for (size_t i = 0; i < stats->ref_stats.blocks; i++) {
+	for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++) {
 		size_t off = i * (opts.block_size ? opts.block_size
 						  : DEFAULT_BLOCK_SIZE);
 		if (!off)
 			off = header_size(opts.hash_id == REFTABLE_HASH_SHA256 ? 2 : 1);
-		check_char(buf->buf[off], ==, 'r');
+		cl_assert(buf->buf[off] == 'r');
 	}
 
 	if (nrefs)
-		check_int(stats->ref_stats.blocks, >, 0);
+		cl_assert(stats->ref_stats.blocks > 0);
 	if (nlogs)
-		check_int(stats->log_stats.blocks, >, 0);
+		cl_assert(stats->log_stats.blocks > 0);
 
 	reftable_writer_free(writer);
 }
t/unit-tests/lib-reftable.h +3 -3
index e4c360fa7e..2958db5dc0 100644
@@ -6,12 +6,12 @@
 
 struct reftable_buf;
 
-void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
 
-struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
 						 struct reftable_write_options *opts);
 
-void t_reftable_write_to_buf(struct reftable_buf *buf,
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
 			     struct reftable_ref_record *refs,
 			     size_t nrecords,
 			     struct reftable_log_record *logs,
t/unit-tests/unit-test.c +0 -93

103 lines not on this page · raw message

t/unit-tests/unit-test.h +0 -16
index fe0aebd876..85e5d6a948 100644
@@ -1,24 +1,8 @@
 #include "git-compat-util.h"
 #include "clar/clar.h"
 #include "clar-decls.h"
-#include "git-compat-util.h"
-#include "reftable/reftable-writer.h"
 #include "strbuf.h"
 
-struct reftable_buf;
-
-void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
-
-struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
-						 struct reftable_write_options *opts);
-
-void cl_reftable_write_to_buf(struct reftable_buf *buf,
-			     struct reftable_ref_record *refs,
-			     size_t nrecords,
-			     struct reftable_log_record *logs,
-			     size_t nlogs,
-			     struct reftable_write_options *opts);
-
 #define cl_failf(fmt, ...) do { \
 	char desc[4096]; \
 	snprintf(desc, sizeof(desc), fmt, __VA_ARGS__); \
Signature · 1 line
2.43.0
#26 lore raw

Re: [PATCH v2 10/10] t/unit-tests: adapt lib-reftable{c,h} helper functions to clar

Quoted 31 lines · Seyi Kuforiji

Helper functions defined in t/unit-tests/lib-reftable.{c,h} are required for the reftable-related test files to run efficeintly. In the current implementation these functions are designed to conform with our homegrown unit-testing structure. So in other to convert the reftable test files, there is need for a clar specific implementation of these helper functions.

type cast for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++) Adapt functions in lib-reftable.{c,h} to use clar. These functions conform with the clar testing framework and become available for all reftable-related test files implemented using the clar testing framework, which requires them. This change migrates the helper functions back into lib-reftable.{c,h}.

---
 Makefile                    |  4 +-
 t/meson.build               |  4 +-
 t/unit-tests/lib-reftable.c | 26 +++++------
 t/unit-tests/lib-reftable.h |  6 +--
 t/unit-tests/unit-test.c    | 93 -------------------------------------
 t/unit-tests/unit-test.h    | 16 -------
 6 files changed, 20 insertions(+), 129 deletions(-)
Makefile +0 -0
index 0b42893611..7e646e16ee 100644
@@ -1379,12 +1379,12 @@ CLAR_TEST_SUITES += u-urlmatch-normalization
 CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
 CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))

Makefile CLAR_TEST_SUITES += u-urlmatch-normalization · line 1388

Quoted 10 lines
Makefile +2 -2
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
-CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
+CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
+CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 
 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
 

UNIT_TEST_PROGS only contains the "unit-test" binary now, right? Does this mean that we can simplify build rules in our Makefile now?

Quoted 16 lines
t/meson.build +2 -1
index 8fa00fc9ef..7c305a90b5 100644
@@ -26,8 +26,9 @@ clar_test_suites = [
 
 clar_sources = [
   'unit-tests/clar/clar.c',
+  'unit-tests/lib-oid.c',
+  'unit-tests/lib-reftable.c',
   'unit-tests/unit-test.c',
-  'unit-tests/lib-oid.c'
 ]
 
 clar_decls_h = custom_target(

t/meson.build foreach unit_test_program : unit_test_programs · line 75

Quoted 7 lines
t/meson.build +0 -1
@@ -69,7 +70,6 @@ foreach unit_test_program : unit_test_programs
   unit_test = executable(unit_test_name,
     sources: [
       'unit-tests/test-lib.c',
-      'unit-tests/lib-reftable.c',
       unit_test_program,
     ],
     dependencies: [libgit_commonmain],

Can't we remove this completely? unit_test_programs is empty now, so this loop is a no-op now.

Quoted 10 lines
t/unit-tests/lib-reftable.h +1 -1
index e4c360fa7e..2958db5dc0 100644
@@ -6,12 +6,12 @@
 
 struct reftable_buf;
 
-void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);

t/unit-tests/lib-reftable.h line 17

Quoted 10 lines
t/unit-tests/lib-reftable.h +2 -2
 
-struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
 						 struct reftable_write_options *opts);
 
-void t_reftable_write_to_buf(struct reftable_buf *buf,
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
 			     struct reftable_ref_record *refs,
 			     size_t nrecords,
 			     struct reftable_log_record *logs,

It is quite weird that we declare the replacement functions in "unit-test.h" in the first commit only to remove them at a later point. It would make way more sense if we introduced the functions in "t/unit/lib-reftable.{c,h}" right from the start and then only remove the unused functions in the last step.

Patrick

#27 lore raw

Re: [PATCH v2 10/10] t/unit-tests: adapt lib-reftable{c,h} helper functions to clar

Hi Patrick,

Quoted 101 lines · Patrick Steinhardt
Quoted 31 lines · Seyi Kuforiji

Helper functions defined in t/unit-tests/lib-reftable.{c,h} are required for the reftable-related test files to run efficeintly. In the current implementation these functions are designed to conform with our homegrown unit-testing structure. So in other to convert the reftable test files, there is need for a clar specific implementation of these helper functions.

type cast for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++) Adapt functions in lib-reftable.{c,h} to use clar. These functions conform with the clar testing framework and become available for all reftable-related test files implemented using the clar testing framework, which requires them. This change migrates the helper functions back into lib-reftable.{c,h}.

---
 Makefile                    |  4 +-
 t/meson.build               |  4 +-
 t/unit-tests/lib-reftable.c | 26 +++++------
 t/unit-tests/lib-reftable.h |  6 +--
 t/unit-tests/unit-test.c    | 93 -------------------------------------
 t/unit-tests/unit-test.h    | 16 -------
 6 files changed, 20 insertions(+), 129 deletions(-)
Makefile +0 -0
index 0b42893611..7e646e16ee 100644
@@ -1379,12 +1379,12 @@ CLAR_TEST_SUITES += u-urlmatch-normalization
 CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
 CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))

Makefile CLAR_TEST_SUITES += u-urlmatch-normalization · line 1388

Quoted 10 lines
Makefile +2 -2
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
-CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
+CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
+CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 
 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
 

UNIT_TEST_PROGS only contains the "unit-test" binary now, right? Does this mean that we can simplify build rules in our Makefile now?

Quoted 16 lines
t/meson.build +2 -1
index 8fa00fc9ef..7c305a90b5 100644
@@ -26,8 +26,9 @@ clar_test_suites = [
 
 clar_sources = [
   'unit-tests/clar/clar.c',
+  'unit-tests/lib-oid.c',
+  'unit-tests/lib-reftable.c',
   'unit-tests/unit-test.c',
-  'unit-tests/lib-oid.c'
 ]
 
 clar_decls_h = custom_target(

t/meson.build foreach unit_test_program : unit_test_programs · line 75

Quoted 7 lines
t/meson.build +0 -1
@@ -69,7 +70,6 @@ foreach unit_test_program : unit_test_programs
   unit_test = executable(unit_test_name,
     sources: [
       'unit-tests/test-lib.c',
-      'unit-tests/lib-reftable.c',
       unit_test_program,
     ],
     dependencies: [libgit_commonmain],

Can't we remove this completely? unit_test_programs is empty now, so this loop is a no-op now.

Quoted 10 lines
t/unit-tests/lib-reftable.h +1 -1
index e4c360fa7e..2958db5dc0 100644
@@ -6,12 +6,12 @@
 
 struct reftable_buf;
 
-void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);

t/unit-tests/lib-reftable.h line 17

Quoted 10 lines
t/unit-tests/lib-reftable.h +2 -2
 
-struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
                                               struct reftable_write_options *opts);
 
-void t_reftable_write_to_buf(struct reftable_buf *buf,
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
                           struct reftable_ref_record *refs,
                           size_t nrecords,
                           struct reftable_log_record *logs,

It is quite weird that we declare the replacement functions in "unit-test.h" in the first commit only to remove them at a later point. It would make way more sense if we introduced the functions in "t/unit/lib-reftable.{c,h}" right from the start and then only remove the unused functions in the last step.

Quoted 1 line

Patrick

If I get it correctly, you're suggesting I have both the original functions and the clar-based variant in t/unit/lib-reftable.{c,h} right from the first commit, right?

Thanks
Seyi

#28 lore raw

Re: [PATCH v2 10/10] t/unit-tests: adapt lib-reftable{c,h} helper functions to clar

Quoted 29 lines · Seyi Chamber
Quoted 28 lines · Patrick Steinhardt
Quoted 10 lines · Seyi Kuforiji
t/unit-tests/lib-reftable.h +1 -1
index e4c360fa7e..2958db5dc0 100644
@@ -6,12 +6,12 @@
 
 struct reftable_buf;
 
-void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);

t/unit-tests/lib-reftable.h line 17

Quoted 10 lines
t/unit-tests/lib-reftable.h +2 -2
 
-struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
                                               struct reftable_write_options *opts);
 
-void t_reftable_write_to_buf(struct reftable_buf *buf,
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
                           struct reftable_ref_record *refs,
                           size_t nrecords,
                           struct reftable_log_record *logs,

It is quite weird that we declare the replacement functions in "unit-test.h" in the first commit only to remove them at a later point. It would make way more sense if we introduced the functions in "t/unit/lib-reftable.{c,h}" right from the start and then only remove the unused functions in the last step.

Quoted 4 lines
Quoted 1 line

Patrick

If I get it correctly, you're suggesting I have both the original functions and the clar-based variant in t/unit/lib-reftable.{c,h}

Yup, exactly.

Patrick

#29 lore raw

Re: [PATCH v2 10/10] t/unit-tests: adapt lib-reftable{c,h} helper functions to clar

Quoted 31 lines · Patrick Steinhardt
Quoted 29 lines · Seyi Chamber
Quoted 28 lines · Patrick Steinhardt
Quoted 10 lines · Seyi Kuforiji
t/unit-tests/lib-reftable.h +1 -1
index e4c360fa7e..2958db5dc0 100644
@@ -6,12 +6,12 @@
 
 struct reftable_buf;
 
-void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);

t/unit-tests/lib-reftable.h line 17

Quoted 10 lines
t/unit-tests/lib-reftable.h +2 -2
 
-struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
                                               struct reftable_write_options *opts);
 
-void t_reftable_write_to_buf(struct reftable_buf *buf,
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
                           struct reftable_ref_record *refs,
                           size_t nrecords,
                           struct reftable_log_record *logs,

It is quite weird that we declare the replacement functions in "unit-test.h" in the first commit only to remove them at a later point. It would make way more sense if we introduced the functions in "t/unit/lib-reftable.{c,h}" right from the start and then only remove the unused functions in the last step.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Patrick

If I get it correctly, you're suggesting I have both the original functions and the clar-based variant in t/unit/lib-reftable.{c,h}

Yup, exactly.

Patrick

Hi Patrick,

Thanks for the suggestion to move both the original t-helpers and the Clar-based cl_ versions into t/unit/lib-reftable.{c,h}.

I’ve tried doing that but ran into some build issues. The Clar-based functions use clar_assert and clar_assert_equal, which aren’t available to non-Clar tests. Since both sets of helpers would live in the same object file, this causes linker errors for binaries that don’t link against Clar.

I also hit Makefile warnings like “target 'lib-reftable.o' given more than once,” due to the object being included in both Clar and non-Clar test builds. And with all declarations in one header, non-Clar tests see prototypes for Clar-only functions they can't link.

Also facing errors like these:
LINK t/unit-tests/bin/t-reftable-basics /usr/bin/ld: t/unit-tests/lib-reftable.o: in function cl_reftable_strbuf_writer':
/home/seyik/git/t/unit-tests/lib-reftable.c:113:(.text+0x520):
undefined reference to clar__assert'

What would you recommend I do to fix this?

Thanks,
Seyi

#30 lore raw

Re: [PATCH v2 10/10] t/unit-tests: adapt lib-reftable{c,h} helper functions to clar

Quoted 57 lines · Seyi Chamber
Quoted 31 lines · Patrick Steinhardt
Quoted 29 lines · Seyi Chamber
Quoted 28 lines · Patrick Steinhardt
Quoted 10 lines · Seyi Kuforiji
t/unit-tests/lib-reftable.h +1 -1
index e4c360fa7e..2958db5dc0 100644
@@ -6,12 +6,12 @@
 
 struct reftable_buf;
 
-void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);

t/unit-tests/lib-reftable.h line 17

Quoted 10 lines
t/unit-tests/lib-reftable.h +2 -2
 
-struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
                                               struct reftable_write_options *opts);
 
-void t_reftable_write_to_buf(struct reftable_buf *buf,
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
                           struct reftable_ref_record *refs,
                           size_t nrecords,
                           struct reftable_log_record *logs,

It is quite weird that we declare the replacement functions in "unit-test.h" in the first commit only to remove them at a later point. It would make way more sense if we introduced the functions in "t/unit/lib-reftable.{c,h}" right from the start and then only remove the unused functions in the last step.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Patrick

If I get it correctly, you're suggesting I have both the original functions and the clar-based variant in t/unit/lib-reftable.{c,h}

Yup, exactly.

Patrick

Hi Patrick,

Thanks for the suggestion to move both the original t-helpers and the Clar-based cl_ versions into t/unit/lib-reftable.{c,h}.

I’ve tried doing that but ran into some build issues. The Clar-based functions use clar_assert and clar_assert_equal, which aren’t available to non-Clar tests. Since both sets of helpers would live in the same object file, this causes linker errors for binaries that don’t link against Clar.

I also hit Makefile warnings like “target 'lib-reftable.o' given more than once,” due to the object being included in both Clar and non-Clar test builds. And with all declarations in one header, non-Clar tests see prototypes for Clar-only functions they can't link.

Quoted 8 lines

Also facing errors like these:
LINK t/unit-tests/bin/t-reftable-basics /usr/bin/ld: t/unit-tests/lib-reftable.o: in function cl_reftable_strbuf_writer':
/home/seyik/git/t/unit-tests/lib-reftable.c:113:(.text+0x520):
undefined reference to clar__assert'

What would you recommend I do to fix this?

Hm. You could also have a separate "lib-reftable-clar.{c,h}" code unit that contains the new definitions that you introduce early in your series. At the end of the series you could then delete the old "lib-reftable.{c,h}" and rename "lib-reftable-clar.{c,h}" accordingly to have that name. It's requires a bit more shuffling, but given that the final commit would then be a plain rename it shouldn't be too bad, I guess.

Patrick