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

Re: [PATCH v2 1/4] t/unit-tests: convert hashmap test to use clar test framework

From
Pphillip.wood123@gmail.com <phillip.wood123@gmail.com>
Date
Feb 3, 2025, 14:56 UTC
Message-ID
<288fbcf3-f6c1-46e4-8124-f4e566abe8af@gmail.com>
In-Reply-To
<Z6Bwr6hM54nu8nSS@pks.im>
Hi Patrick
On 03/02/2025 07:30, Patrick Steinhardt wrote:
Show 24 quoted lines
> On Sun, Feb 02, 2025 at 11:09:25AM +0000, phillip.wood123@gmail.com wrote:
>> On 31/01/2025 22:14, Seyi Kuforiji wrote:
> 
>> diff --git a/t/unit-tests/clar/clar.c b/t/unit-tests/clar/clar.c
>> index d54e4553674..16f86c952f7 100644
>> --- a/t/unit-tests/clar/clar.c
>> +++ b/t/unit-tests/clar/clar.c
>> @@ -754,7 +754,12 @@ void clar__assert_equal(
>>                                   p_snprintf(buf, sizeof(buf), "'%s' != '%s' (at byte %d)",
>>                                           s1, s2, pos);
>>                           } else {
>> -                                p_snprintf(buf, sizeof(buf), "'%s' != '%s'", s1, s2);
>> +                                const char *q1 = s1 ? "'" : "";
>> +                                const char *q2 = s2 ? "'" : "";
>> +                                s1 = s1 ? s1 : "NULL";
>> +                                s2 = s2 ? s2 : "NULL";
>> +                                p_snprintf(buf, sizeof(buf), "%s%s%s != %s%s%s",
>> +                                           q1, s1, q1, q2, s2, q2);
>>                           }
>>                   }
>>           }
> 
> Would you mind creating an upstream pull request with these changes? I'm
> happy to review, and then we can update our embedded version of clar.
I've opened a PR at https://github.com/clar-test/clar/pull/114
Show 16 quoted lines
>>>    	for (size_t i = 0; i < ARRAY_SIZE(query); i++) {
>>>    		entry = get_test_entry(map, query[i][0], ignore_case);
>>> -		if (check(entry != NULL))
>>> -			check_str(get_value(entry), query[i][1]);
>>> -		else
>>> -			test_msg("query key: %s", query[i][0]);
>>
>> It is a shame that we're removing all of the helpful debugging messages
>> from this test. It would be much nicer if we could keep them by using an
>> if statement and cl_failf() as we do in u-ctype.c
> 
> I honestly think that the debug messages don't add much and only add to
> the noise. You shouldn't ever see them, and if you do something is
> broken and you'll likely end up pulling out the debugger anyway. So I'm
> more in the camp of writing unit tests in a concise way rather than the
> needlessly-verbose style we previously had.

If I'm firing up the debugger I'd rather as much detail as I can about what went wrong so I can see where to set my breakpoints. Otherwise I need to waste time repeating the test to find out exactly what went wrong before I can make any progress. My experience with debugging our integration tests is that those tests that take care to print helpful diagnostic messages when they fail are a lot easier to debug than those that don't.

Best Wishes
Phillip
Previous: Patrick SteinhardtNext: Seyi Kuforiji
Message 16 of 21 in “t/unit-tests: convert unit-tests to use clar”
  1. 0/4 t/unit-tests: convert unit-tests to use clarSeyi Kuforiji, Jan 30, 2025
  2. 1/4 t/unit-tests: convert hashmap test to clar frameworkSeyi Kuforiji, Jan 30, 2025
  3. Patrick SteinhardtJan 31, 2025
  4. 2/4 t/unit-tests: adapt example decorate test to clar frameworkSeyi Kuforiji, Jan 30, 2025
  5. Patrick SteinhardtJan 31, 2025
  6. 3/4 t/unit-tests: convert strbuf test to clar frameworkSeyi Kuforiji, Jan 30, 2025
  7. Patrick SteinhardtJan 31, 2025
  8. 4/4 t/unit-tests: convert strcmp-offset test to clar frameworkSeyi Kuforiji, Jan 30, 2025
  9. Patrick SteinhardtJan 31, 2025
  10. Patrick SteinhardtJan 31, 2025
  11. 0/4 t/unit-tests: convert unit-tests to use clarSeyi Kuforiji, Jan 31, 2025
  12. 1/4 t/unit-tests: convert hashmap test to use clar test frameworkSeyi Kuforiji, Jan 31, 2025
  13. Junio C HamanoJan 31, 2025
  14. phillip.wood123@gmail.comFeb 2, 2025
  15. Patrick SteinhardtFeb 3, 2025
  16. phillip.wood123@gmail.comFeb 3, 2025
  17. 2/4 t/unit-tests: adapt example decorate test to use clar test frameworkSeyi Kuforiji, Jan 31, 2025
  18. 3/4 t/unit-tests: convert strbuf test to use clar test frameworkSeyi Kuforiji, Jan 31, 2025
  19. Phillip WoodFeb 2, 2025
  20. 4/4 t/unit-tests: convert strcmp-offset test to use clar test frameworkSeyi Kuforiji, Jan 31, 2025
  21. Junio C HamanoJan 31, 2025

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.