Re: [PATCH v5 9/9] t/unit-tests: convert ctype tests to use clar
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 18, 2024, 06:39 UTC
- Message-ID
- <xmqqo75qgws6.fsf@gitster.g>
- In-Reply-To
- <ca09d19fd51cd4b3072b339f483b6b6d6e467b56.1723791831.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 8 quoted lines
> Convert the ctype tests to use the new clar unit testing framework.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> 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.
Show 17 quoted lines
> #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)