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 v2 4/4] t/unit-tests: convert strcmp-offset test to use clar test framework
Date: Fri, 31 Jan 2025 23:14:20 +0100 [thread overview]
Message-ID: <20250131221420.38161-5-kuforiji98@gmail.com> (raw)
In-Reply-To: <20250131221420.38161-1-kuforiji98@gmail.com>
Adapt strcmp-offset test script to clar framework by using clar
assertions where necessary. Introduce `test_strcmp_offset__empty()` to
verify `check_strcmp_offset()` behavior when both input strings are
empty. This ensures the function correctly handles edge cases and
returns expected values.
Mentored-by: Patrick Steinhardt <ps@pks•im>
Signed-off-by: Seyi Kuforiji <kuforiji98@gmail•com>
---
Makefile | 2 +-
t/meson.build | 2 +-
.../{t-strcmp-offset.c => u-strcmp-offset.c} | 36 ++++++++++++-------
3 files changed, 25 insertions(+), 15 deletions(-)
rename t/unit-tests/{t-strcmp-offset.c => u-strcmp-offset.c} (39%)
diff --git a/Makefile b/Makefile
index 358193597f..76b5de4fdd 100644
--- a/Makefile
+++ b/Makefile
@@ -1345,6 +1345,7 @@ CLAR_TEST_SUITES += u-mem-pool
CLAR_TEST_SUITES += u-prio-queue
CLAR_TEST_SUITES += u-reftable-tree
CLAR_TEST_SUITES += u-strbuf
+CLAR_TEST_SUITES += u-strcmp-offset
CLAR_TEST_SUITES += u-strvec
CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
@@ -1362,7 +1363,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader
UNIT_TEST_PROGRAMS += t-reftable-readwrite
UNIT_TEST_PROGRAMS += t-reftable-record
UNIT_TEST_PROGRAMS += t-reftable-stack
-UNIT_TEST_PROGRAMS += t-strcmp-offset
UNIT_TEST_PROGRAMS += t-trailer
UNIT_TEST_PROGRAMS += t-urlmatch-normalization
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
diff --git a/t/meson.build b/t/meson.build
index 6cb72842b1..3935782bbb 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -7,6 +7,7 @@ clar_test_suites = [
'unit-tests/u-prio-queue.c',
'unit-tests/u-reftable-tree.c',
'unit-tests/u-strbuf.c',
+ 'unit-tests/u-strcmp-offset.c',
'unit-tests/u-strvec.c',
]
@@ -58,7 +59,6 @@ unit_test_programs = [
'unit-tests/t-reftable-readwrite.c',
'unit-tests/t-reftable-record.c',
'unit-tests/t-reftable-stack.c',
- 'unit-tests/t-strcmp-offset.c',
'unit-tests/t-trailer.c',
'unit-tests/t-urlmatch-normalization.c',
]
diff --git a/t/unit-tests/t-strcmp-offset.c b/t/unit-tests/u-strcmp-offset.c
similarity index 39%
rename from t/unit-tests/t-strcmp-offset.c
rename to t/unit-tests/u-strcmp-offset.c
index 6880f21161..7e8e9acf3c 100644
--- a/t/unit-tests/t-strcmp-offset.c
+++ b/t/unit-tests/u-strcmp-offset.c
@@ -1,4 +1,4 @@
-#include "test-lib.h"
+#include "unit-test.h"
#include "read-cache-ll.h"
static void check_strcmp_offset(const char *string1, const char *string2,
@@ -15,21 +15,31 @@ static void check_strcmp_offset(const char *string1, const char *string2,
result > 0 ? 1 :
0);
- check_int(result, ==, expect_result);
- check_uint((uintmax_t)offset, ==, expect_offset);
+ cl_assert_equal_i(result, expect_result);
+ cl_assert_equal_i((uintmax_t)offset, expect_offset);
}
-#define TEST_STRCMP_OFFSET(string1, string2, expect_result, expect_offset) \
- TEST(check_strcmp_offset(string1, string2, expect_result, \
- expect_offset), \
- "strcmp_offset(%s, %s) works", #string1, #string2)
+void test_strcmp_offset__empty(void)
+{
+ check_strcmp_offset("", "", 0, 0);
+}
+
+void test_strcmp_offset__equal(void)
+{
+ check_strcmp_offset("abc", "abc", 0, 3);
+}
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
+void test_strcmp_offset__different(void)
{
- TEST_STRCMP_OFFSET("abc", "abc", 0, 3);
- TEST_STRCMP_OFFSET("abc", "def", -1, 0);
- TEST_STRCMP_OFFSET("abc", "abz", -1, 2);
- TEST_STRCMP_OFFSET("abc", "abcdef", -1, 3);
+ check_strcmp_offset("abc", "def", -1, 0);
+}
- return test_done();
+void test_strcmp_offset__mismatch(void)
+{
+ check_strcmp_offset("abc", "abz", -1, 2);
+}
+
+void test_strcmp_offset__different_length(void)
+{
+ check_strcmp_offset("abc", "abcdef", -1, 3);
}
--
2.47.0.86.g15030f9556
next prev parent reply other threads:[~2025-01-31 22:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 9:13 [PATCH 0/4] t/unit-tests: convert unit-tests to use clar Seyi Kuforiji
2025-01-30 9:13 ` [PATCH 1/4] t/unit-tests: convert hashmap test to clar framework Seyi Kuforiji
2025-01-31 11:43 ` Patrick Steinhardt
2025-01-30 9:13 ` [PATCH 2/4] t/unit-tests: adapt example decorate " Seyi Kuforiji
2025-01-31 11:43 ` Patrick Steinhardt
2025-01-30 9:13 ` [PATCH 3/4] t/unit-tests: convert strbuf " Seyi Kuforiji
2025-01-31 11:43 ` Patrick Steinhardt
2025-01-30 9:13 ` [PATCH 4/4] t/unit-tests: convert strcmp-offset " Seyi Kuforiji
2025-01-31 11:44 ` Patrick Steinhardt
2025-01-31 11:43 ` [PATCH 0/4] t/unit-tests: convert unit-tests to use clar Patrick Steinhardt
2025-01-31 22:14 ` [PATCH v2 " Seyi Kuforiji
2025-01-31 22:14 ` [PATCH v2 1/4] t/unit-tests: convert hashmap test to use clar test framework Seyi Kuforiji
2025-01-31 23:03 ` Junio C Hamano
2025-02-02 11:09 ` phillip.wood123
2025-02-03 7:30 ` Patrick Steinhardt
2025-02-03 14:56 ` phillip.wood123
2025-01-31 22:14 ` [PATCH v2 2/4] t/unit-tests: adapt example decorate " Seyi Kuforiji
2025-01-31 22:14 ` [PATCH v2 3/4] t/unit-tests: convert strbuf " Seyi Kuforiji
2025-02-02 14:38 ` Phillip Wood
2025-01-31 22:14 ` Seyi Kuforiji [this message]
2025-01-31 23:06 ` [PATCH v2 0/4] t/unit-tests: convert unit-tests to use clar 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=20250131221420.38161-5-kuforiji98@gmail.com \
--to=kuforiji98@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=phillip.wood@dunelm$(echo .)org.uk \
--cc=ps@pks$(echo .)im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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