From: Junio C Hamano <gitster@pobox.com>
To: Seyi Kuforiji <kuforiji98@gmail.com>
Cc: git@vger.kernel.org, ps@pks.im, phillip.wood@dunelm.org.uk
Subject: Re: [PATCH v3] t/unit-tests: convert hash to use clar test framework
Date: Thu, 09 Jan 2025 08:14:45 -0800 [thread overview]
Message-ID: <xmqqmsg0j762.fsf@gitster.g> (raw)
In-Reply-To: <20250109140952.5267-1-kuforiji98@gmail.com> (Seyi Kuforiji's message of "Thu, 9 Jan 2025 15:09:52 +0100")
Seyi Kuforiji <kuforiji98@gmail.com> writes:
> Adapt the hash test functions to clar framework by using clar
> assertions where necessary. Following the consensus to convert
> the unit-tests scripts found in the t/unit-tests folder to clar driven by
> Patrick Steinhardt. Test functions are structured as a standalone to
> test individual hash string and literal case.
>
> Mentored-by: Patrick Steinhardt <ps@pks.im>
> Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
The change to the test program was a very pleasant read. It was
trivially obvious that the new version faithfully rewrites the
original. E.g., ...
> static void check_hash_data(const void *data, size_t data_length,
> const char *expected_hashes[])
> {
> - if (!check(data != NULL)) {
> - test_msg("BUG: NULL data pointer provided");
> - return;
> - }
> + cl_assert(data != NULL);
... instead of using check() and giving message with test_msg(), the
clar framework gives cl_assert() for us to use.
And ...
> #define TEST_HASH_STR(data, expected_sha1, expected_sha256) do { \
> const char *expected_hashes[] = { expected_sha1, expected_sha256 }; \
> - TEST(check_hash_data(data, strlen(data), expected_hashes), \
> - "SHA1 and SHA256 (%s) works", #data); \
> + check_hash_data(data, strlen(data), expected_hashes); \
... instead of TEST() macro with the title string, we call the
underlying test function. The loss of the message does not hurt us,
as both the test suite name and name of each test are shown by the
clar framework.
> -int cmd_main(int argc UNUSED, const char **argv UNUSED)
> +void test_hash__empty_string(void)
> {
> - struct strbuf aaaaaaaaaa_100000 = STRBUF_INIT;
> - struct strbuf alphabet_100000 = STRBUF_INIT;
> -
> - strbuf_addstrings(&aaaaaaaaaa_100000, "aaaaaaaaaa", 100000);
> - strbuf_addstrings(&alphabet_100000, "abcdefghijklmnopqrstuvwxyz", 100000);
> -
> TEST_HASH_STR("",
> "da39a3ee5e6b4b0d3255bfef95601890afd80709",
> "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
> +}
And the fact that the body of each test function are unchanged from
the original helps to build confidence in the faithfulness of the
conversion.
The strbuf allocation is lost from here, and clean-up is lost from
the end of the file, and they are done in the function that needs
the strbuf, which also contributes to the clarity of the new
version.
Nicely done. Will queue.
Thanks.
prev parent reply other threads:[~2025-01-09 16:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-07 9:19 [PATCH 0/2] t/unit-tests: convert hash tests to use clar Seyi Kuforiji
2025-01-07 9:19 ` [PATCH 1/2] t/unit-tests: match functions signature with trailing code Seyi Kuforiji
2025-01-07 18:16 ` Junio C Hamano
2025-01-07 18:41 ` Junio C Hamano
2025-01-08 6:14 ` Patrick Steinhardt
2025-01-08 8:31 ` Seyi Chamber
2025-01-08 15:27 ` Junio C Hamano
2025-01-08 16:15 ` Patrick Steinhardt
2025-01-07 9:19 ` [PATCH 2/2] t/unit-tests: convert hash to use clar test framework Seyi Kuforiji
2025-01-08 12:03 ` [PATCH v2 0/1] " Seyi Kuforiji
2025-01-08 12:03 ` [PATCH v2 1/1] " Seyi Kuforiji
2025-01-08 15:35 ` Junio C Hamano
2025-01-09 7:30 ` Seyi Chamber
2025-01-08 15:28 ` [PATCH v2 0/1] " Junio C Hamano
2025-01-09 7:21 ` Seyi Chamber
2025-01-09 14:09 ` [PATCH v3] " Seyi Kuforiji
2025-01-09 15:10 ` Patrick Steinhardt
2025-01-09 16:14 ` Junio C Hamano [this message]
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=xmqqmsg0j762.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=kuforiji98@gmail.com \
--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).