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

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

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jan 6, 2026, 10:59 UTC
Message-ID
<CAOLa=ZQZnYVuK8mDi6Yb8_+hqw_TMugn6i7BJCj1gbNHOruNWA@mail.gmail.com>
In-Reply-To
<20251206-b4-pks-clar-update-v2-1-9a14b10c1a36@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
> Update clar to commit 39f11fe (Merge pull request #131 from
> pks-gitlab/pks-integer-double-evaluation, 2025-12-05). This commit
> includes the following changes relevant to Git:
>
Nit: There is a newer commit merged into the clar repository, but I
don't think it is so important to include.
Show 14 quoted lines
>   - There are now typesafe integer comparison functions. Furthermore,
>     the range of comparison functions has been included to also have
>     relative comparisons, like "greater than".
>
>   - There is a new `cl_failf()` macro that allows the caller to specify
>     an error message with formatting directives.
>
>   - The TAP format has been fixed to correctly terminate YAML blocks
>     with "...\n" instead of "---\n".
>
> Note that we already had a `cl_failf()` function declared in our own
> sources. This function is equivalent to the upstreamed function, so we
> can simply drop it now.
>
[snip]
Show 5 quoted lines
> @@ -149,6 +150,7 @@ const char *cl_fixture_basename(const char *fixture_name);
>   * Forced failure/warning
>   */
>  #define cl_fail(desc) clar__fail(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, "Test failed.", desc, 1)
> +#define cl_failf(desc,...) clar__failf(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, 1, "Test failed.", desc, __VA_ARGS__)
Nit: While most of the function accept description with variable
arguments, this is the only one which has the '...f()' format explicitly
separated out. It would be nicer if we simply make this part of
'cl_fail()', no?
Show 17 quoted lines
>  #define cl_warning(desc) clar__fail(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, "Warning during test execution:", desc, 0)
>
>  #define cl_skip() clar__skip()
> @@ -168,9 +170,42 @@ const char *cl_fixture_basename(const char *fixture_name);
>  #define cl_assert_equal_wcsn(wcs1,wcs2,len) clar__assert_equal(CLAR_CURRENT_FILE,CLAR_CURRENT_FUNC,CLAR_CURRENT_LINE,"String mismatch: " #wcs1 " != " #wcs2, 1, "%.*ls", (wcs1), (wcs2), (int)(len))
>  #define cl_assert_equal_wcsn_(wcs1,wcs2,len,note) clar__assert_equal(CLAR_CURRENT_FILE,CLAR_CURRENT_FUNC,CLAR_CURRENT_LINE,"String mismatch: " #wcs1 " != " #wcs2 " (" #note ")", 1, "%.*ls", (wcs1), (wcs2), (int)(len))
>
> -#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__)
> +#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)

So we use local variables here to avoid double evaluation of the arguments passed. We also use 'intmax_t' since this would avoid any size truncation. Looks good.

Show 31 quoted lines
> +#define cl_assert_equal_i_(i1, i2, ...)    cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_EQ, #i1 " == " #i2, __VA_ARGS__)
> +#define cl_assert_equal_i(i1, i2)          cl_assert_compare_i (i1, i2, CLAR_COMPARISON_EQ, #i1 " == " #i2, "%"PRIdMAX " != %"PRIdMAX)
> +#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))
> +#define cl_assert_lt_i_(i1, i2, ...) cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_LT, #i1 " < " #i2, __VA_ARGS__)
> +#define cl_assert_lt_i(i1, i2)       cl_assert_compare_i (i1, i2, CLAR_COMPARISON_LT, #i1 " < " #i2, "%"PRIdMAX " >= %"PRIdMAX)
> +#define cl_assert_le_i_(i1, i2, ...) cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_LE, #i1 " <= " #i2, __VA_ARGS__)
> +#define cl_assert_le_i(i1, i2)       cl_assert_compare_i (i1, i2, CLAR_COMPARISON_LE, #i1 " <= " #i2, "%"PRIdMAX " > %"PRIdMAX)
> +#define cl_assert_gt_i_(i1, i2, ...) cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_GT, #i1 " > " #i2, __VA_ARGS__)
> +#define cl_assert_gt_i(i1, i2)       cl_assert_compare_i (i1, i2, CLAR_COMPARISON_GT, #i1 " > " #i2, "%"PRIdMAX " <= %"PRIdMAX)
> +#define cl_assert_ge_i_(i1, i2, ...) cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_GE, #i1 " >= " #i2, __VA_ARGS__)
> +#define cl_assert_ge_i(i1, i2)       cl_assert_compare_i (i1, i2, CLAR_COMPARISON_GE, #i1 " >= " #i2, "%"PRIdMAX " < %"PRIdMAX)
> +
> +#define cl_assert_compare_u_(u1, u2, cmp, error, ...) clar__assert_compare_u(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, 1, cmp, \
> +									     (u1), (u2), "Expected comparison to hold: " error, __VA_ARGS__)
> +#define cl_assert_compare_u(u1, u2, cmp, error, fmt) do { \
> +	uintmax_t v1 = (u1), v2 = (u2); \
> +	clar__assert_compare_u(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, 1, cmp, \
> +			       v1, v2, "Expected comparison to hold: " error, fmt, v1, v2); \
> +} while (0)
> +#define cl_assert_equal_u_(u1, u2, ...) cl_assert_compare_u_(u1, u2, CLAR_COMPARISON_EQ, #u1 " == " #u2, __VA_ARGS__)
> +#define cl_assert_equal_u(u1, u2)       cl_assert_compare_u (u1, u2, CLAR_COMPARISON_EQ, #u1 " == " #u2, "%"PRIuMAX " != %"PRIuMAX)
> +#define cl_assert_lt_u_(u1, u2, ...) cl_assert_compare_u_(u1, u2, CLAR_COMPARISON_LT, #u1 " < " #u2, __VA_ARGS__)
> +#define cl_assert_lt_u(u1, u2)       cl_assert_compare_u (u1, u2, CLAR_COMPARISON_LT, #u1 " < " #u2, "%"PRIuMAX " >= %"PRIuMAX)
> +#define cl_assert_le_u_(u1, u2, ...) cl_assert_compare_u_(u1, u2, CLAR_COMPARISON_LE, #u1 " <= " #u2, __VA_ARGS__)
> +#define cl_assert_le_u(u1, u2)       cl_assert_compare_u (u1, u2, CLAR_COMPARISON_LE, #u1 " <= " #u2, "%"PRIuMAX " > %"PRIuMAX)
> +#define cl_assert_gt_u_(u1, u2, ...) cl_assert_compare_u_(u1, u2, CLAR_COMPARISON_GT, #u1 " > " #u2, __VA_ARGS__)
> +#define cl_assert_gt_u(u1, u2)       cl_assert_compare_u (u1, u2, CLAR_COMPARISON_GT, #u1 " > " #u2, "%"PRIuMAX " <= %"PRIuMAX)
> +#define cl_assert_ge_u_(u1, u2, ...) cl_assert_compare_u_(u1, u2, CLAR_COMPARISON_GE, #u1 " >= " #u2, __VA_ARGS__)
> +#define cl_assert_ge_u(u1, u2)       cl_assert_compare_u (u1, u2, CLAR_COMPARISON_GE, #u1 " >= " #u2, "%"PRIuMAX " < %"PRIuMAX)
>
>  #define cl_assert_equal_b(b1,b2) clar__assert_equal(CLAR_CURRENT_FILE,CLAR_CURRENT_FUNC,CLAR_CURRENT_LINE,#b1 " != " #b2, 1, "%d", (int)((b1) != 0),(int)((b2) != 0))
[snip]
[1]: https://github.com/clar-test/clar/commits/main/
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 10 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.