From: Seyi Kuforiji <kuforiji98@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, phillip.wood@dunelm.org.uk,
Seyi Kuforiji <kuforiji98@gmail.com>
Subject: [PATCH v4 05/10] t/unit-tests: convert reftable pq test to use clar
Date: Thu, 5 Jun 2025 15:06:39 +0100 [thread overview]
Message-ID: <20250605140644.239199-6-kuforiji98@gmail.com> (raw)
In-Reply-To: <20250605140644.239199-1-kuforiji98@gmail.com>
Adapt reftable priority queue test file to use clar by using clar
assertions where necessary.
Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
---
Makefile | 2 +-
t/meson.build | 3 +-
.../{t-reftable-pq.c => u-reftable-pq.c} | 59 +++++++++----------
3 files changed, 30 insertions(+), 34 deletions(-)
rename t/unit-tests/{t-reftable-pq.c => u-reftable-pq.c} (64%)
diff --git a/Makefile b/Makefile
index fb0ef10ff2..3cccc73073 100644
--- a/Makefile
+++ b/Makefile
@@ -1367,6 +1367,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
@@ -1380,7 +1381,6 @@ 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-clar.o
-UNIT_TEST_PROGRAMS += t-reftable-pq
UNIT_TEST_PROGRAMS += t-reftable-readwrite
UNIT_TEST_PROGRAMS += t-reftable-record
UNIT_TEST_PROGRAMS += t-reftable-stack
diff --git a/t/meson.build b/t/meson.build
index d25dfb0c92..ac4394b7a2 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -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',
@@ -58,7 +59,7 @@ 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',
'unit-tests/t-reftable-stack.c',
diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/u-reftable-pq.c
similarity index 64%
rename from t/unit-tests/t-reftable-pq.c
rename to t/unit-tests/u-reftable-pq.c
index fb5a4eb187..d55792ca6f 100644
--- a/t/unit-tests/t-reftable-pq.c
+++ b/t/unit-tests/u-reftable-pq.c
@@ -6,7 +6,8 @@ license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
-#include "test-lib.h"
+#include "unit-test.h"
+#include "lib-reftable-clar.h"
#include "reftable/constants.h"
#include "reftable/pq.h"
#include "strbuf.h"
@@ -15,18 +16,18 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)
{
for (size_t i = 1; i < pq->len; i++) {
size_t parent = (i - 1) / 2;
- check(pq_less(&pq->heap[parent], &pq->heap[i]));
+ cl_assert(pq_less(&pq->heap[parent], &pq->heap[i]) != 0);
}
}
static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b)
{
int cmp;
- check(!reftable_record_cmp(a->rec, b->rec, &cmp));
+ cl_assert_equal_i(reftable_record_cmp(a->rec, b->rec, &cmp), 0);
return !cmp && (a->index == b->index);
}
-static void t_pq_record(void)
+void test_reftable_pq__record(void)
{
struct merged_iter_pqueue pq = { 0 };
struct reftable_record recs[54];
@@ -34,7 +35,8 @@ static void t_pq_record(void)
char *last = NULL;
for (i = 0; i < N; i++) {
- check(!reftable_record_init(&recs[i], REFTABLE_BLOCK_TYPE_REF));
+ cl_assert(!reftable_record_init(&recs[i],
+ REFTABLE_BLOCK_TYPE_REF));
recs[i].u.ref.refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i);
}
@@ -53,13 +55,13 @@ static void t_pq_record(void)
struct pq_entry top = merged_iter_pqueue_top(pq);
struct pq_entry e;
- check(!merged_iter_pqueue_remove(&pq, &e));
+ cl_assert_equal_i(merged_iter_pqueue_remove(&pq, &e), 0);
merged_iter_pqueue_check(&pq);
- check(pq_entry_equal(&top, &e));
- check(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
+ cl_assert(pq_entry_equal(&top, &e));
+ cl_assert(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
if (last)
- check_int(strcmp(last, e.rec->u.ref.refname), <, 0);
+ cl_assert(strcmp(last, e.rec->u.ref.refname) < 0);
last = e.rec->u.ref.refname;
}
@@ -68,7 +70,7 @@ static void t_pq_record(void)
merged_iter_pqueue_release(&pq);
}
-static void t_pq_index(void)
+void test_reftable_pq__index(void)
{
struct merged_iter_pqueue pq = { 0 };
struct reftable_record recs[13];
@@ -76,7 +78,8 @@ static void t_pq_index(void)
size_t N = ARRAY_SIZE(recs), i;
for (i = 0; i < N; i++) {
- check(!reftable_record_init(&recs[i], REFTABLE_BLOCK_TYPE_REF));
+ cl_assert(!reftable_record_init(&recs[i],
+ REFTABLE_BLOCK_TYPE_REF));
recs[i].u.ref.refname = (char *) "refs/heads/master";
}
@@ -96,28 +99,29 @@ static void t_pq_index(void)
struct pq_entry top = merged_iter_pqueue_top(pq);
struct pq_entry e;
- check(!merged_iter_pqueue_remove(&pq, &e));
+ cl_assert_equal_i(merged_iter_pqueue_remove(&pq, &e), 0);
merged_iter_pqueue_check(&pq);
- check(pq_entry_equal(&top, &e));
- check(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
- check_int(e.index, ==, i);
+ cl_assert(pq_entry_equal(&top, &e));
+ cl_assert(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
+ cl_assert_equal_i(e.index, i);
if (last)
- check_str(last, e.rec->u.ref.refname);
+ cl_assert_equal_s(last, e.rec->u.ref.refname);
last = e.rec->u.ref.refname;
}
merged_iter_pqueue_release(&pq);
}
-static void t_merged_iter_pqueue_top(void)
+void test_reftable_pq__merged_iter_pqueue_top(void)
{
struct merged_iter_pqueue pq = { 0 };
struct reftable_record recs[13];
size_t N = ARRAY_SIZE(recs), i;
for (i = 0; i < N; i++) {
- check(!reftable_record_init(&recs[i], REFTABLE_BLOCK_TYPE_REF));
+ cl_assert(!reftable_record_init(&recs[i],
+ REFTABLE_BLOCK_TYPE_REF));
recs[i].u.ref.refname = (char *) "refs/heads/master";
}
@@ -137,25 +141,16 @@ static void t_merged_iter_pqueue_top(void)
struct pq_entry top = merged_iter_pqueue_top(pq);
struct pq_entry e;
- check(!merged_iter_pqueue_remove(&pq, &e));
+ cl_assert_equal_i(merged_iter_pqueue_remove(&pq, &e), 0);
merged_iter_pqueue_check(&pq);
- check(pq_entry_equal(&top, &e));
- check(reftable_record_equal(top.rec, &recs[i], REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(pq_entry_equal(&top, &e) != 0);
+ cl_assert(reftable_record_equal(top.rec, &recs[i], REFTABLE_HASH_SIZE_SHA1) != 0);
for (size_t j = 0; i < pq.len; j++) {
- check(pq_less(&top, &pq.heap[j]));
- check_int(top.index, >, j);
+ cl_assert(pq_less(&top, &pq.heap[j]) != 0);
+ cl_assert(top.index > j);
}
}
merged_iter_pqueue_release(&pq);
}
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
- TEST(t_pq_record(), "pq works with record-based comparison");
- TEST(t_pq_index(), "pq works with index-based comparison");
- TEST(t_merged_iter_pqueue_top(), "merged_iter_pqueue_top works");
-
- return test_done();
-}
--
2.43.0
next prev parent reply other threads:[~2025-06-05 14:08 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 14:06 [PATCH v4 00/10] t/unit-tests: convert unit-tests to use clar Seyi Kuforiji
2025-06-05 14:06 ` [PATCH v4 01/10] t/unit-tests: implement clar specific reftable test helper functions Seyi Kuforiji
2025-06-05 14:06 ` [PATCH v4 02/10] t/unit-tests: convert reftable basics test to use clar test framework Seyi Kuforiji
2025-06-05 14:06 ` [PATCH v4 03/10] t/unit-tests: convert reftable block test to use clar Seyi Kuforiji
2025-06-05 14:06 ` [PATCH v4 04/10] t/unit-tests: convert reftable merged " Seyi Kuforiji
2025-06-05 14:06 ` Seyi Kuforiji [this message]
2025-06-05 14:06 ` [PATCH v4 06/10] t/unit-tests: convert reftable table " Seyi Kuforiji
2025-06-05 17:04 ` Junio C Hamano
2025-06-05 14:06 ` [PATCH v4 07/10] t/unit-tests: convert reftable readwrite " Seyi Kuforiji
2025-06-05 14:06 ` [PATCH v4 08/10] t/unit-tests: convert reftable record " Seyi Kuforiji
2025-06-05 14:06 ` [PATCH v4 09/10] t/unit-tests: convert reftable stack " Seyi Kuforiji
2025-07-24 6:47 ` Patrick Steinhardt
2025-06-05 14:06 ` [PATCH v4 10/10] t/unit-tests: finalize migration of reftable-related tests Seyi Kuforiji
2025-07-23 21:30 ` [PATCH v4 00/10] t/unit-tests: convert unit-tests to use clar Junio C Hamano
2025-07-24 6:47 ` Patrick Steinhardt
2025-07-24 13:28 ` [PATCH v5 0/5] " Seyi Kufoiji
2025-07-24 13:28 ` [PATCH v5 1/5] t/unit-tests: convert reftable table test " Seyi Kufoiji
2025-07-24 13:28 ` [PATCH v5 2/5] t/unit-tests: convert reftable readwrite " Seyi Kufoiji
2025-07-24 13:28 ` [PATCH v5 3/5] t/unit-tests: convert reftable record " Seyi Kufoiji
2025-07-24 13:28 ` [PATCH v5 4/5] t/unit-tests: convert reftable stack " Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 00/10] t/unit-tests: convert unit-tests " Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 01/10] t/unit-tests: implement clar specific reftable test helper functions Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 02/10] t/unit-tests: convert reftable basics test to use clar test framework Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 03/10] t/unit-tests: convert reftable block test to use clar Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 04/10] t/unit-tests: convert reftable merged " Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 05/10] t/unit-tests: convert reftable pq " Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 06/10] t/unit-tests: convert reftable table " Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 07/10] t/unit-tests: convert reftable readwrite " Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 08/10] t/unit-tests: convert reftable record " Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 09/10] t/unit-tests: convert reftable stack " Seyi Kufoiji
2025-07-24 14:28 ` [PATCH v5 10/10] t/unit-tests: finalize migration of reftable-related tests Seyi Kufoiji
2025-07-24 14:41 ` [PATCH v5 00/10] t/unit-tests: convert unit-tests to use clar Patrick Steinhardt
2025-07-24 18:48 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250605140644.239199-6-kuforiji98@gmail.com \
--to=kuforiji98@gmail.com \
--cc=git@vger.kernel.org \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).