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

Re: [PATCH 1/2] t/unit-tests: update clar to 39f11fe

From
Jeff King <peff@peff.net>
Date
Dec 5, 2025, 18:40 UTC
Message-ID
<20251205184020.GB33447@coredump.intra.peff.net>
In-Reply-To
<20251205-b4-pks-clar-update-v1-1-fd70aac2ab90@pks.im>
On Fri, Dec 05, 2025 at 01:57:52PM +0100, Patrick Steinhardt wrote:
Show 5 quoted lines
> -#define cl_assert_equal_i(i1,i2) clar__assert_equal(CLAR_CURRENT_FILE,CLAR_CURRENT_FUNC,CLAR_CURRENT_LINE,#i1 " != " #i2, 1, "%d", (int)(i1), (int)(i2))
> -#define cl_assert_equal_i_(i1,i2,note) clar__assert_equal(CLAR_CURRENT_FILE,CLAR_CURRENT_FUNC,CLAR_CURRENT_LINE,#i1 " != " #i2 " (" #note ")", 1, "%d", (i1), (i2))
> -#define cl_assert_equal_i_fmt(i1,i2,fmt) clar__assert_equal(CLAR_CURRENT_FILE,CLAR_CURRENT_FUNC,CLAR_CURRENT_LINE,#i1 " != " #i2, 1, (fmt), (int)(i1), (int)(i2))
> +#define cl_assert_compare_i_(i1, i2, cmp, error, ...) clar__assert_compare_i(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, 1, cmp, \
> +									     (i1), (i2), "Expected comparison to hold: " error, __VA_ARGS__)
OK, so "i" use to always mean "int", and now...
Show 5 quoted lines
> +#define cl_assert_compare_i(i1, i2, cmp, error, fmt) do { \
> +	intmax_t v1 = (i1), v2 = (i2); \
> +	clar__assert_compare_i(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, 1, cmp, \
> +			       v1, v2, "Expected comparison to hold: " error, fmt, v1, v2); \
> +} while (0)

we use intmax_t. That seems OK, and lets us handle any size integer; the caller just needs to distinguish signed from unsigned (having "i" meaning "signed" is a little funny, but I don't have a better suggestion).

This one is a little odd, though:
> +#define cl_assert_equal_i_fmt(i1, i2, fmt) cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_EQ, #i1 " == " #i2,  fmt " != " fmt, (int)(i1), (int)(i2))

Here we still cast to int. I guess we have to in order to keep custom "%o" and friends working. They probably ought to be using PRIoMAX, but that would require changes to the tests to do so (and I wonder if we might hit any portability issues).

-Peff
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 20 in “Update clar for improved integer handling”
  1. 0/2 Update clar for improved integer handlingPatrick Steinhardt, Dec 5, 2025
  2. 1/2 t/unit-tests: update clar to 39f11fePatrick Steinhardt, Dec 5, 2025
  3. Jeff KingDec 5, 2025
  4. Patrick SteinhardtDec 6, 2025
  5. Junio C HamanoDec 6, 2025
  6. Patrick SteinhardtDec 6, 2025
  7. 2/2 t/unit-tests: demonstrate use of integer comparison assertionsPatrick Steinhardt, Dec 5, 2025
  8. 0/3 Update clar for improved integer handlingPatrick Steinhardt, Dec 6, 2025
  9. 1/3 t/unit-tests: update clar to 39f11fePatrick Steinhardt, Dec 6, 2025
  10. Karthik NayakJan 6, 2026
  11. Patrick SteinhardtJan 6, 2026
  12. Karthik NayakJan 6, 2026
  13. Jeff KingJan 7, 2026
  14. Junio C HamanoJan 8, 2026
  15. 2/3 t/unit-tests: demonstrate use of integer comparison assertionsPatrick Steinhardt, Dec 6, 2025
  16. 3/3 gitattributes: disable blank-at-eof errors for clar test expectationsPatrick Steinhardt, Dec 6, 2025
  17. Karthik NayakJan 6, 2026
  18. Patrick SteinhardtJan 6, 2026
  19. Junio C HamanoJan 7, 2026
  20. Patrick SteinhardtJan 7, 2026

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.