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
René Scharfe <l.s.r@web.de>
Date
Dec 28, 2023, 16:05 UTC
Message-ID
<e01be0ec-a054-42a1-8abe-6891c04b59a2@web.de>
In-Reply-To
<xmqqcyurky00.fsf@gitster.g>
Am 28.12.23 um 00:48 schrieb Junio C Hamano:
Show 27 quoted lines
> René Scharfe <l.s.r@web.de> writes:
>
>>> 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".
>>
>> True.
>> ...
>> The added repetition is a bit grating.  With a bit of setup, loop
>> unrolling and stringification you can retain the property of only having
>> to mention the class name once.  Demo patch below.
>
> Nice.
>
> This (and your mempool thing) being one of the early efforts to
> adopt the unit-test framework outside the initial set of sample
> tests, it is understandable that we might find what framework offers
> is still lacking.  But at the same time, while the macro tricks
> demonstrated here are all amusing to read and admire, it feels a bit
> too much to expect that the test writers are willing to invent
> something like these every time they want to test.
>
> Being a relatively faithful conversion of the original ctype tests,
> with its thorough enumeration of test samples and expected output,
> is what makes this test program require these macro tricks, and it
> does not have much to do with the features (or lack thereof) of the
> framework, I guess.
*nod*
Show 29 quoted lines
>
>> +struct ctype {
>> +	const char *name;
>> +	const char *expect;
>> +	int actual[256];
>> +};
>> +
>> +static void test_ctype(const struct ctype *class)
>> +{
>> +	for (int i = 0; i < 256; i++) {
>> +		int expect = is_in(class->expect, i);
>> +		int actual = class->actual[i];
>> +		int res = test_assert(TEST_LOCATION(), class->name,
>> +				      actual == expect);
>> +		if (!res)
>> +			test_msg("%s classifies char %d (0x%02x) wrongly",
>> +				 class->name, i, i);
>> +	}
>>  }
>
> Somehow, the "test_assert" does not seem to be adding much value
> here (i.e. we can do "res = (actual == expect)" there).  Is this
> because we want to be able to report success, too?
>
>     ... goes and looks at test_assert() ...
>
> Ah, is it because we want to be able to "skip" (which pretends that
> the assert() was satisified).  OK, but then the error reporting from
> it is redundant with our own test_msg().

True, the test_msg() emits the old message here, but it doesn't have to report that the check failed anymore, because test_assert() already covers that part. It would only have to report the misclassified character and perhaps the expected result.

René
Previous: Junio C HamanoNext: Taylor Blau
Message 7 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.