git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Seyi Kuforiji <kuforiji98@gmail.com>
Cc: git@vger.kernel.org, phillip.wood@dunelm.org.uk
Subject: Re: [PATCH 3/4] t/unit-tests: convert strbuf test to clar framework
Date: Fri, 31 Jan 2025 12:43:59 +0100	[thread overview]
Message-ID: <Z5y3f1B450LZOp3v@pks.im> (raw)
In-Reply-To: <20250130091334.39922-4-kuforiji98@gmail.com>

On Thu, Jan 30, 2025 at 10:13:33AM +0100, Seyi Kuforiji wrote:
> Adapt strbuf test script to clar framework by using clar assertions
> where necessary. Test functions are created as standalone to test
> different test cases.

Same comment here regarding the second sentence.

> diff --git a/t/unit-tests/u-strbuf.c b/t/unit-tests/u-strbuf.c
> new file mode 100644
> index 0000000000..fec3c768d2
> --- /dev/null
> +++ b/t/unit-tests/u-strbuf.c
> @@ -0,0 +1,121 @@
> +#include "unit-test.h"
> +#include "strbuf.h"

It's somewhat sad that Git doesn't not think of this as a rename, as it
would've made the diff easier to read. You might want to try using
`git format-patch --find-renames=20' to ask Git to still consider this a
rename.

[snip]
> +static void assert_sane_strbuf(struct strbuf *buf)
> +{
> +	/* Initialized strbufs should always have a non-NULL buffer */
> +	cl_assert(buf->buf != NULL);
> +	/* Buffers should always be NUL-terminated */
> +	cl_assert(buf->buf[buf->len] == '\0');
> +	/*
> +	 * Freshly-initialized strbufs may not have a dynamically allocated
> +	 * buffer
> +	 */
> +	if (buf->len == 0 && buf->alloc == 0)
> +		return;
> +	/* alloc must be at least one byte larger than len */
> +	cl_assert(buf->len < buf->alloc);

I think this condition can be simplified a bit:

        /*
         * In case the buffer contains anything, `alloc` must alloc must
         * be at least one byte larger than `len`.
         */
        if (buf->len)
            cl_assert(buf->len < buf->alloc);

> +void test_strbuf__add_empty_char(void)
> +{
> +	setup(t_addch, "");
> +}
> +
> +void test_strbuf__add_multi_char(void)

Nit: I think "add_multi_char" is slightly misleading. What this test
exercises is that we can append to a non-empty buffer. So maybe
"append_char" would be a better fit?

> +{
> +	setup_populated(t_addch, "initial value", "a");
> +}
> +
> +void test_strbuf__add_single_str(void)
> +{
> +	setup(t_addstr, "hello there");
> +}
> +
> +void test_strbuf__add_multi_str(void)

Similarly, we could name this "append_str".

> +{
> +	setup_populated(t_addstr, "initial value", "hello there");
> +}

Patrick

  reply	other threads:[~2025-01-31 11:44 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 [this message]
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   ` [PATCH v2 4/4] t/unit-tests: convert strcmp-offset " Seyi Kuforiji
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=Z5y3f1B450LZOp3v@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=kuforiji98@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    /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).