Subject: Re: [PATCH 1/2] u-string-list: add unit tests for string-list methods

From: Junio C Hamano <[email-masked]>
Date: Sun, 25 Jan 2026 23:12:27 -0800

Amisha Chhajed <[email-masked]> writes:

> Unit tests in u-string-list.c does not cover several methods
> in string-list, this gap in coverage makes it difficult to
> ensure no regressions are introduced in future changes.
>
> Add unit tests for the following methods to enhance coverage:
> string_list_remove_empty_items()
> unsorted_string_list_has_string()
> unsorted_string_list_delete_item()
> string_list_has_string()
> string_list_insert()
> string_list_sort()
> string_list_remove()
>
> Signed-off-by: Amisha Chhajed <[email-masked]>
> ---
>  t/unit-tests/u-string-list.c | 197 +++++++++++++++++++++++++++++++++++
>  1 file changed, 197 insertions(+)
>
> diff --git a/t/unit-tests/u-string-list.c b/t/unit-tests/u-string-list.c
> index a2457d7b1e..6b4b858330 100644
> --- a/t/unit-tests/u-string-list.c
> +++ b/t/unit-tests/u-string-list.c
> @@ -243,6 +243,133 @@ void test_string_list__filter(void)
> ...
> +static void t_string_list_insert(struct string_list *expected_strings, ...)
> +{
> +	struct string_list strings_to_insert = STRING_LIST_INIT_DUP;
> +	struct string_list list = STRING_LIST_INIT_DUP;
> +	va_list ap;
> +
> +	va_start(ap, expected_strings);
> +	t_vcreate_string_list_dup(&strings_to_insert, 0, ap);
> +	va_end(ap);
> +
> +	for (int i = 0; i < strings_to_insert.nr; i++) {

As strings_to_insert.nr is of type size_t, even though int is plenty
large enough in practice, the compiler will complain.

> +		string_list_insert(&list, strings_to_insert.items[i].string);
> +	}

Also, lose the {} around a single statement block.