git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Port helper/test-ctype.c to unit-tests/t-ctype.c

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Dec 27, 2023, 14:40 UTC
Message-ID
<e1e9290f-755a-457c-911b-769a311c47fb@gmail.com>
In-Reply-To
<f743b473-40f8-423d-bf5b-d42b92e5aa1b@web.de>
On 27/12/2023 11:57, René Scharfe wrote:
Show 28 quoted lines
> Am 27.12.23 um 11:57 schrieb Christian Couder:
>> On Tue, Dec 26, 2023 at 7:46 PM Junio C Hamano <gitster@pobox.com> wrote:
>>>
>>> Achu Luma <ach.lumap@gmail.com> writes:
>>
>>>> +/* Macro to test a character type */
>>>> +#define TEST_CTYPE_FUNC(func, string)                        \
>>>> +static void test_ctype_##func(void)                          \
>>>> +{                                                            \
>>>> +     int i;                                                  \
>>>> +     for (i = 0; i < 256; i++)                               \
>>>> +             check_int(func(i), ==, is_in(string, i));       \
>>>> +}
>>>
>>> Now, we let check_int() to do the checking for each and every byte
>>> value for the class.  check_int() uses different reporting and shows
>>> the problematic value in a way that is more verbose and at the same
>>> time is a less specific and harder to understand:
>>>
>>>                  test_msg("   left: %"PRIdMAX, a);
>>>                  test_msg("  right: %"PRIdMAX, b);
>>>
>>> But that is probably the price to pay to use a more generic
>>> framework, I guess.
>>
>> I have added Phillip and Josh in Cc: as they might have ideas about this.
> 
> You can write custom messages for custom tests using test_assert().
Another possibility is to do
	for (int i = 0; i < 256; i++) {
		if (!check_int(func(i), ==, is_in(string, i))
			test_msg("       i: %02x", i);
	}

To print the character code as well as the actual and expected return values of check_int(). The funny spacing is intended to keep the output aligned. I did wonder if we should be using

	check(func(i) == is_in(string, i))

instead of check_int() but I think it is useful to have the return value printed on error in case we start returning "53" instead of "1" for "true" [1]. With the extra test_msg() above we can now see if the test fails because of a mis-categorization or because func() returned a different non-zero value when we were expecting "1".

>> Also it might not be a big issue here, but when the new unit test
>> framework was proposed, I commented on the fact that "left" and
>> "right" were perhaps a bit less explicit than "actual" and "expected".

If people are worried about this then it would be possible to change the check_xxx() macros pass the stringified relational operator into the various check_xxx_loc() functions and then print "expected" and "actual" when the operator is "==" and "left" and "right" otherwise.

Best Wishes
Phillip

[1] As an aside I wonder if the ctype functions would make good test balloons for using _Bool by changing sane_istest() to be

#define sane_istest(x,mask) ((bool)(sane_ctype[(unsigned char)(x)] & (mask)))

so that we check casting to _Bool coerces non-zero values to "1"
Previous: René ScharfeNext: Junio C Hamano
Message 5 of 24 in “Port helper/test-ctype.c to unit-tests/t-ctype.c”
  1. Port helper/test-ctype.c to unit-tests/t-ctype.cAchu Luma, Dec 21, 2023
  2. Junio C HamanoDec 26, 2023
  3. Christian CouderDec 27, 2023
  4. René ScharfeDec 27, 2023
  5. Phillip WoodDec 27, 2023
  6. Junio C HamanoDec 27, 2023
  7. René ScharfeDec 28, 2023
  8. Taylor BlauJan 2, 2024
  9. [Outreachy][PATCH v2] Port helper/test-ctype.c to unit-tests/t-ctype.cAchu Luma, Dec 30, 2023
  10. [Outreachy][PATCH v3] Port helper/test-ctype.c to unit-tests/t-ctype.cAchu Luma, Jan 1, 2024
  11. René ScharfeJan 1, 2024
  12. Junio C HamanoJan 2, 2024
  13. [Outreachy][PATCH v4] Port helper/test-ctype.c to unit-tests/t-ctype.cAchu Luma, Jan 5, 2024
  14. René ScharfeJan 7, 2024
  15. Junio C HamanoJan 8, 2024
  16. Phillip WoodJan 9, 2024
  17. Junio C HamanoJan 9, 2024
  18. [Outreachy][PATCH v5] Port helper/test-ctype.c to unit-tests/t-ctype.cAchu Luma, Jan 12, 2024
  19. Phillip WoodJan 15, 2024
  20. Junio C HamanoJan 16, 2024
  21. René ScharfeJan 16, 2024
  22. Christian CouderJan 16, 2024
  23. Junio C HamanoJan 16, 2024
  24. Josh SteadmonJan 17, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.