Subject: Re: [PATCH v5 9/9] t/unit-tests: convert ctype tests to use clar

From: Junio C Hamano <[email-masked]>
Date: Sat, 17 Aug 2024 23:39:05 -0700

Patrick Steinhardt <[email-masked]> writes:

> Convert the ctype tests to use the new clar unit testing framework.
>
> Signed-off-by: Patrick Steinhardt <[email-masked]>
> ---
>  Makefile                            |  2 +-
>  t/unit-tests/{t-ctype.c => ctype.c} | 71 +++++++++++++++++++++++------
>  2 files changed, 59 insertions(+), 14 deletions(-)
>  rename t/unit-tests/{t-ctype.c => ctype.c} (71%)

In 'next' we use the if_test stuff to simplify the ctype unit tests.
This gives a good example to illustrate the strengths and weakness
of these approaches.  I resolved the conflict in 'seen' with this
topic in favor of clar tests so that it becomes easier to compare.

>  #define TEST_CHAR_CLASS(class, string) do { \
>  	size_t len = ARRAY_SIZE(string) - 1 + \
>  		BUILD_ASSERT_OR_ZERO(ARRAY_SIZE(string) > 0) + \
>  		BUILD_ASSERT_OR_ZERO(sizeof(string[0]) == sizeof(char)); \
> -	int skip = test__run_begin(); \
> -	if (!skip) { \
> -		for (int i = 0; i < 256; i++) { \
> -			if (!check_int(class(i), ==, !!memchr(string, i, len)))\
> -				test_msg("      i: 0x%02x", i); \
> -		} \
> -		check(!class(EOF)); \
> -	} \
> -	test__run_end(!skip, TEST_LOCATION(), #class " works"); \
> +	for (int i = 0; i < 256; i++) \
> +		cl_assert_equal_i(class(i), !!memchr(string, i, len)); \
> +	cl_assert(!class(EOF)); \
>  } while (0)