t/unit-tests: update clar to 39f11fe

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: - 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. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 6, 2025 at 12:47 UTC d5e4aef3586c07c31e3e4d76ce7fdf0f9843314f
12 files changed +508 -59
t/unit-tests/clar/.github/workflows/ci.yml
+1 -1
@@ -53,7 +53,7 @@ jobs:
53 if: matrix.platform.image == 'i386/debian:latest'
54 run: apt -q update && apt -q -y install cmake gcc libc6-amd64 lib64stdc++6 make python3
55 - name: Check out
56 - uses: actions/checkout@v4
56 + uses: actions/checkout@v6
57 - name: Build
58 shell: bash
59 run: |
t/unit-tests/clar/clar.c
+141 -5
@@ -24,6 +24,14 @@
24 #include <sys/types.h>
25 #include <sys/stat.h>
26
27 +#ifndef va_copy
28 +# ifdef __va_copy
29 +# define va_copy(dst, src) __va_copy(dst, src)
30 +# else
31 +# define va_copy(dst, src) ((dst) = (src))
32 +# endif
33 +#endif
34 +
35 #if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_WCHAR__)
36 /*
37 * uClibc can optionally be built without wchar support, in which case
@@ -76,8 +84,10 @@
84 # define S_ISDIR(x) ((x & _S_IFDIR) != 0)
85 # endif
86 # define p_snprintf(buf,sz,fmt,...) _snprintf_s(buf,sz,_TRUNCATE,fmt,__VA_ARGS__)
87 +# define p_vsnprintf _vsnprintf
88 # else
89 # define p_snprintf snprintf
90 +# define p_vsnprintf vsnprintf
91 # endif
92
93 # define localtime_r(timer, buf) (localtime_s(buf, timer) == 0 ? buf : NULL)
@@ -86,6 +96,7 @@
96 # include <unistd.h>
97 # define _MAIN_CC
98 # define p_snprintf snprintf
99 +# define p_vsnprintf vsnprintf
100 typedef struct stat STAT_T;
101 #endif
102
@@ -699,13 +710,14 @@ void clar__skip(void)
710 abort_test();
711 }
712
702 -void clar__fail(
713 +static void clar__failv(
714 const char *file,
715 const char *function,
716 size_t line,
717 + int should_abort,
718 const char *error_msg,
719 const char *description,
708 - int should_abort)
720 + va_list args)
721 {
722 struct clar_error *error;
723
@@ -725,9 +737,19 @@ void clar__fail(
737 error->line_number = _clar.invoke_line ? _clar.invoke_line : line;
738 error->error_msg = error_msg;
739
728 - if (description != NULL &&
729 - (error->description = strdup(description)) == NULL)
730 - clar_abort("Failed to allocate description.\n");
740 + if (description != NULL) {
741 + va_list args_copy;
742 + int len;
743 +
744 + va_copy(args_copy, args);
745 + if ((len = p_vsnprintf(NULL, 0, description, args_copy)) < 0)
746 + clar_abort("Failed to compute description.");
747 + va_end(args_copy);
748 +
749 + if ((error->description = calloc(1, len + 1)) == NULL)
750 + clar_abort("Failed to allocate buffer.");
751 + p_vsnprintf(error->description, len + 1, description, args);
752 + }
753
754 _clar.total_errors++;
755 _clar.last_report->status = CL_TEST_FAILURE;
@@ -736,6 +758,34 @@ void clar__fail(
758 abort_test();
759 }
760
761 +void clar__failf(
762 + const char *file,
763 + const char *function,
764 + size_t line,
765 + int should_abort,
766 + const char *error_msg,
767 + const char *description,
768 + ...)
769 +{
770 + va_list args;
771 + va_start(args, description);
772 + clar__failv(file, function, line, should_abort, error_msg,
773 + description, args);
774 + va_end(args);
775 +}
776 +
777 +void clar__fail(
778 + const char *file,
779 + const char *function,
780 + size_t line,
781 + const char *error_msg,
782 + const char *description,
783 + int should_abort)
784 +{
785 + clar__failf(file, function, line, should_abort, error_msg,
786 + description ? "%s" : NULL, description);
787 +}
788 +
789 void clar__assert(
790 int condition,
791 const char *file,
@@ -889,6 +939,92 @@ void clar__assert_equal(
939 clar__fail(file, function, line, err, buf, should_abort);
940 }
941
942 +void clar__assert_compare_i(
943 + const char *file,
944 + const char *func,
945 + size_t line,
946 + int should_abort,
947 + enum clar_comparison cmp,
948 + intmax_t value1,
949 + intmax_t value2,
950 + const char *error,
951 + const char *description,
952 + ...)
953 +{
954 + int fulfilled;
955 + switch (cmp) {
956 + case CLAR_COMPARISON_EQ:
957 + fulfilled = value1 == value2;
958 + break;
959 + case CLAR_COMPARISON_LT:
960 + fulfilled = value1 < value2;
961 + break;
962 + case CLAR_COMPARISON_LE:
963 + fulfilled = value1 <= value2;
964 + break;
965 + case CLAR_COMPARISON_GT:
966 + fulfilled = value1 > value2;
967 + break;
968 + case CLAR_COMPARISON_GE:
969 + fulfilled = value1 >= value2;
970 + break;
971 + default:
972 + cl_assert(0);
973 + return;
974 + }
975 +
976 + if (!fulfilled) {
977 + va_list args;
978 + va_start(args, description);
979 + clar__failv(file, func, line, should_abort, error,
980 + description, args);
981 + va_end(args);
982 + }
983 +}
984 +
985 +void clar__assert_compare_u(
986 + const char *file,
987 + const char *func,
988 + size_t line,
989 + int should_abort,
990 + enum clar_comparison cmp,
991 + uintmax_t value1,
992 + uintmax_t value2,
993 + const char *error,
994 + const char *description,
995 + ...)
996 +{
997 + int fulfilled;
998 + switch (cmp) {
999 + case CLAR_COMPARISON_EQ:
1000 + fulfilled = value1 == value2;
1001 + break;
1002 + case CLAR_COMPARISON_LT:
1003 + fulfilled = value1 < value2;
1004 + break;
1005 + case CLAR_COMPARISON_LE:
1006 + fulfilled = value1 <= value2;
1007 + break;
1008 + case CLAR_COMPARISON_GT:
1009 + fulfilled = value1 > value2;
1010 + break;
1011 + case CLAR_COMPARISON_GE:
1012 + fulfilled = value1 >= value2;
1013 + break;
1014 + default:
1015 + cl_assert(0);
1016 + return;
1017 + }
1018 +
1019 + if (!fulfilled) {
1020 + va_list args;
1021 + va_start(args, description);
1022 + clar__failv(file, func, line, should_abort, error,
1023 + description, args);
1024 + va_end(args);
1025 + }
1026 +}
1027 +
1028 void cl_set_cleanup(void (*cleanup)(void *), void *opaque)
1029 {
1030 _clar.local_cleanup = cleanup;
t/unit-tests/clar/clar.h
+79 -3
@@ -7,6 +7,7 @@
7 #ifndef __CLAR_TEST_H__
8 #define __CLAR_TEST_H__
9
10 +#include <inttypes.h>
11 #include <stdlib.h>
12 #include <limits.h>
13
@@ -149,6 +150,7 @@ const char *cl_fixture_basename(const char *fixture_name);
150 * Forced failure/warning
151 */
152 #define cl_fail(desc) clar__fail(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, "Test failed.", desc, 1)
153 +#define cl_failf(desc,...) clar__failf(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, 1, "Test failed.", desc, __VA_ARGS__)
154 #define cl_warning(desc) clar__fail(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, "Warning during test execution:", desc, 0)
155
156 #define cl_skip() clar__skip()
@@ -168,9 +170,42 @@ const char *cl_fixture_basename(const char *fixture_name);
170 #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))
171 #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))
172
171 -#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))
172 -#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))
173 -#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))
173 +#define cl_assert_compare_i_(i1, i2, cmp, error, ...) clar__assert_compare_i(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, 1, cmp, \
174 + (i1), (i2), "Expected comparison to hold: " error, __VA_ARGS__)
175 +#define cl_assert_compare_i(i1, i2, cmp, error, fmt) do { \
176 + intmax_t v1 = (i1), v2 = (i2); \
177 + clar__assert_compare_i(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, 1, cmp, \
178 + v1, v2, "Expected comparison to hold: " error, fmt, v1, v2); \
179 +} while (0)
180 +#define cl_assert_equal_i_(i1, i2, ...) cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_EQ, #i1 " == " #i2, __VA_ARGS__)
181 +#define cl_assert_equal_i(i1, i2) cl_assert_compare_i (i1, i2, CLAR_COMPARISON_EQ, #i1 " == " #i2, "%"PRIdMAX " != %"PRIdMAX)
182 +#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))
183 +#define cl_assert_lt_i_(i1, i2, ...) cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_LT, #i1 " < " #i2, __VA_ARGS__)
184 +#define cl_assert_lt_i(i1, i2) cl_assert_compare_i (i1, i2, CLAR_COMPARISON_LT, #i1 " < " #i2, "%"PRIdMAX " >= %"PRIdMAX)
185 +#define cl_assert_le_i_(i1, i2, ...) cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_LE, #i1 " <= " #i2, __VA_ARGS__)
186 +#define cl_assert_le_i(i1, i2) cl_assert_compare_i (i1, i2, CLAR_COMPARISON_LE, #i1 " <= " #i2, "%"PRIdMAX " > %"PRIdMAX)
187 +#define cl_assert_gt_i_(i1, i2, ...) cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_GT, #i1 " > " #i2, __VA_ARGS__)
188 +#define cl_assert_gt_i(i1, i2) cl_assert_compare_i (i1, i2, CLAR_COMPARISON_GT, #i1 " > " #i2, "%"PRIdMAX " <= %"PRIdMAX)
189 +#define cl_assert_ge_i_(i1, i2, ...) cl_assert_compare_i_(i1, i2, CLAR_COMPARISON_GE, #i1 " >= " #i2, __VA_ARGS__)
190 +#define cl_assert_ge_i(i1, i2) cl_assert_compare_i (i1, i2, CLAR_COMPARISON_GE, #i1 " >= " #i2, "%"PRIdMAX " < %"PRIdMAX)
191 +
192 +#define cl_assert_compare_u_(u1, u2, cmp, error, ...) clar__assert_compare_u(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, 1, cmp, \
193 + (u1), (u2), "Expected comparison to hold: " error, __VA_ARGS__)
194 +#define cl_assert_compare_u(u1, u2, cmp, error, fmt) do { \
195 + uintmax_t v1 = (u1), v2 = (u2); \
196 + clar__assert_compare_u(CLAR_CURRENT_FILE, CLAR_CURRENT_FUNC, CLAR_CURRENT_LINE, 1, cmp, \
197 + v1, v2, "Expected comparison to hold: " error, fmt, v1, v2); \
198 +} while (0)
199 +#define cl_assert_equal_u_(u1, u2, ...) cl_assert_compare_u_(u1, u2, CLAR_COMPARISON_EQ, #u1 " == " #u2, __VA_ARGS__)
200 +#define cl_assert_equal_u(u1, u2) cl_assert_compare_u (u1, u2, CLAR_COMPARISON_EQ, #u1 " == " #u2, "%"PRIuMAX " != %"PRIuMAX)
201 +#define cl_assert_lt_u_(u1, u2, ...) cl_assert_compare_u_(u1, u2, CLAR_COMPARISON_LT, #u1 " < " #u2, __VA_ARGS__)
202 +#define cl_assert_lt_u(u1, u2) cl_assert_compare_u (u1, u2, CLAR_COMPARISON_LT, #u1 " < " #u2, "%"PRIuMAX " >= %"PRIuMAX)
203 +#define cl_assert_le_u_(u1, u2, ...) cl_assert_compare_u_(u1, u2, CLAR_COMPARISON_LE, #u1 " <= " #u2, __VA_ARGS__)
204 +#define cl_assert_le_u(u1, u2) cl_assert_compare_u (u1, u2, CLAR_COMPARISON_LE, #u1 " <= " #u2, "%"PRIuMAX " > %"PRIuMAX)
205 +#define cl_assert_gt_u_(u1, u2, ...) cl_assert_compare_u_(u1, u2, CLAR_COMPARISON_GT, #u1 " > " #u2, __VA_ARGS__)
206 +#define cl_assert_gt_u(u1, u2) cl_assert_compare_u (u1, u2, CLAR_COMPARISON_GT, #u1 " > " #u2, "%"PRIuMAX " <= %"PRIuMAX)
207 +#define cl_assert_ge_u_(u1, u2, ...) cl_assert_compare_u_(u1, u2, CLAR_COMPARISON_GE, #u1 " >= " #u2, __VA_ARGS__)
208 +#define cl_assert_ge_u(u1, u2) cl_assert_compare_u (u1, u2, CLAR_COMPARISON_GE, #u1 " >= " #u2, "%"PRIuMAX " < %"PRIuMAX)
209
210 #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))
211
@@ -186,6 +221,15 @@ void clar__fail(
221 const char *description,
222 int should_abort);
223
224 +void clar__failf(
225 + const char *file,
226 + const char *func,
227 + size_t line,
228 + int should_abort,
229 + const char *error,
230 + const char *description,
231 + ...);
232 +
233 void clar__assert(
234 int condition,
235 const char *file,
@@ -204,6 +248,38 @@ void clar__assert_equal(
248 const char *fmt,
249 ...);
250
251 +enum clar_comparison {
252 + CLAR_COMPARISON_EQ,
253 + CLAR_COMPARISON_LT,
254 + CLAR_COMPARISON_LE,
255 + CLAR_COMPARISON_GT,
256 + CLAR_COMPARISON_GE,
257 +};
258 +
259 +void clar__assert_compare_i(
260 + const char *file,
261 + const char *func,
262 + size_t line,
263 + int should_abort,
264 + enum clar_comparison cmp,
265 + intmax_t value1,
266 + intmax_t value2,
267 + const char *error,
268 + const char *description,
269 + ...);
270 +
271 +void clar__assert_compare_u(
272 + const char *file,
273 + const char *func,
274 + size_t line,
275 + int should_abort,
276 + enum clar_comparison cmp,
277 + uintmax_t value1,
278 + uintmax_t value2,
279 + const char *error,
280 + const char *description,
281 + ...);
282 +
283 void clar__set_invokepoint(
284 const char *file,
285 const char *func,
t/unit-tests/clar/clar/print.h
+1 -1
@@ -164,7 +164,7 @@ static void clar_print_tap_ontest(const char *suite_name, const char *test_name,
164 printf(" file: '"); print_escaped(error->file); printf("'\n");
165 printf(" line: %" PRIuMAX "\n", error->line_number);
166 printf(" function: '%s'\n", error->function);
167 - printf(" ---\n");
167 + printf(" ...\n");
168 }
169
170 break;
t/unit-tests/clar/test/expected/quiet
+35 -5
@@ -18,27 +18,57 @@ combined::strings_with_length [file:42]
18
19 5) Failure:
20 combined::int [file:42]
21 - 101 != value ("extra note on failing test")
21 + Expected comparison to hold: 101 == value
22 101 != 100
23
24 6) Failure:
25 +combined::int_note [file:42]
26 + Expected comparison to hold: 101 == value
27 + extra note on failing test
28 +
29 + 7) Failure:
30 combined::int_fmt [file:42]
26 - 022 != value
31 + Expected comparison to hold: 022 == value
32 0022 != 0144
33
29 - 7) Failure:
34 + 8) Failure:
35 combined::bool [file:42]
36 0 != value
37 0 != 1
38
34 - 8) Failure:
39 + 9) Failure:
40 combined::multiline_description [file:42]
41 Function call failed: -1
42 description line 1
43 description line 2
44
40 - 9) Failure:
45 + 10) Failure:
46 combined::null_string [file:42]
47 String mismatch: "expected" != actual ("this one fails")
48 'expected' != NULL
49
50 + 11) Failure:
51 +combined::failf [file:42]
52 + Test failed.
53 + some reason: foo
54 +
55 + 12) Failure:
56 +combined::compare_i [file:42]
57 + Expected comparison to hold: two < 1
58 + 2 >= 1
59 +
60 + 13) Failure:
61 +combined::compare_i_with_format [file:42]
62 + Expected comparison to hold: two < 1
63 + foo: bar
64 +
65 + 14) Failure:
66 +combined::compare_u [file:42]
67 + Expected comparison to hold: two < 1
68 + 2 >= 1
69 +
70 + 15) Failure:
71 +combined::compare_u_with_format [file:42]
72 + Expected comparison to hold: two < 1
73 + foo: bar
74 +
t/unit-tests/clar/test/expected/summary_with_filename
+36 -6
@@ -1,6 +1,6 @@
1 Loaded 1 suites:
2 Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')
3 -FFFFFFFFF
3 +FFFFFFFFFFFFFFF
4
5 1) Failure:
6 combined::1 [file:42]
@@ -22,28 +22,58 @@ combined::strings_with_length [file:42]
22
23 5) Failure:
24 combined::int [file:42]
25 - 101 != value ("extra note on failing test")
25 + Expected comparison to hold: 101 == value
26 101 != 100
27
28 6) Failure:
29 +combined::int_note [file:42]
30 + Expected comparison to hold: 101 == value
31 + extra note on failing test
32 +
33 + 7) Failure:
34 combined::int_fmt [file:42]
30 - 022 != value
35 + Expected comparison to hold: 022 == value
36 0022 != 0144
37
33 - 7) Failure:
38 + 8) Failure:
39 combined::bool [file:42]
40 0 != value
41 0 != 1
42
38 - 8) Failure:
43 + 9) Failure:
44 combined::multiline_description [file:42]
45 Function call failed: -1
46 description line 1
47 description line 2
48
44 - 9) Failure:
49 + 10) Failure:
50 combined::null_string [file:42]
51 String mismatch: "expected" != actual ("this one fails")
52 'expected' != NULL
53
54 + 11) Failure:
55 +combined::failf [file:42]
56 + Test failed.
57 + some reason: foo
58 +
59 + 12) Failure:
60 +combined::compare_i [file:42]
61 + Expected comparison to hold: two < 1
62 + 2 >= 1
63 +
64 + 13) Failure:
65 +combined::compare_i_with_format [file:42]
66 + Expected comparison to hold: two < 1
67 + foo: bar
68 +
69 + 14) Failure:
70 +combined::compare_u [file:42]
71 + Expected comparison to hold: two < 1
72 + 2 >= 1
73 +
74 + 15) Failure:
75 +combined::compare_u_with_format [file:42]
76 + Expected comparison to hold: two < 1
77 + foo: bar
78 +
79 written summary file to different.xml
t/unit-tests/clar/test/expected/summary_without_filename
+36 -6
@@ -1,6 +1,6 @@
1 Loaded 1 suites:
2 Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')
3 -FFFFFFFFF
3 +FFFFFFFFFFFFFFF
4
5 1) Failure:
6 combined::1 [file:42]
@@ -22,28 +22,58 @@ combined::strings_with_length [file:42]
22
23 5) Failure:
24 combined::int [file:42]
25 - 101 != value ("extra note on failing test")
25 + Expected comparison to hold: 101 == value
26 101 != 100
27
28 6) Failure:
29 +combined::int_note [file:42]
30 + Expected comparison to hold: 101 == value
31 + extra note on failing test
32 +
33 + 7) Failure:
34 combined::int_fmt [file:42]
30 - 022 != value
35 + Expected comparison to hold: 022 == value
36 0022 != 0144
37
33 - 7) Failure:
38 + 8) Failure:
39 combined::bool [file:42]
40 0 != value
41 0 != 1
42
38 - 8) Failure:
43 + 9) Failure:
44 combined::multiline_description [file:42]
45 Function call failed: -1
46 description line 1
47 description line 2
48
44 - 9) Failure:
49 + 10) Failure:
50 combined::null_string [file:42]
51 String mismatch: "expected" != actual ("this one fails")
52 'expected' != NULL
53
54 + 11) Failure:
55 +combined::failf [file:42]
56 + Test failed.
57 + some reason: foo
58 +
59 + 12) Failure:
60 +combined::compare_i [file:42]
61 + Expected comparison to hold: two < 1
62 + 2 >= 1
63 +
64 + 13) Failure:
65 +combined::compare_i_with_format [file:42]
66 + Expected comparison to hold: two < 1
67 + foo: bar
68 +
69 + 14) Failure:
70 +combined::compare_u [file:42]
71 + Expected comparison to hold: two < 1
72 + 2 >= 1
73 +
74 + 15) Failure:
75 +combined::compare_u_with_format [file:42]
76 + Expected comparison to hold: two < 1
77 + foo: bar
78 +
79 written summary file to summary.xml
t/unit-tests/clar/test/expected/tap
+74 -14
@@ -8,7 +8,7 @@ not ok 1 - combined::1
8 file: 'file'
9 line: 42
10 function: 'func'
11 - ---
11 + ...
12 not ok 2 - combined::2
13 ---
14 reason: |
@@ -17,7 +17,7 @@ not ok 2 - combined::2
17 file: 'file'
18 line: 42
19 function: 'func'
20 - ---
20 + ...
21 not ok 3 - combined::strings
22 ---
23 reason: |
@@ -27,7 +27,7 @@ not ok 3 - combined::strings
27 file: 'file'
28 line: 42
29 function: 'func'
30 - ---
30 + ...
31 not ok 4 - combined::strings_with_length
32 ---
33 reason: |
@@ -37,28 +37,38 @@ not ok 4 - combined::strings_with_length
37 file: 'file'
38 line: 42
39 function: 'func'
40 - ---
40 + ...
41 not ok 5 - combined::int
42 ---
43 reason: |
44 - 101 != value ("extra note on failing test")
44 + Expected comparison to hold: 101 == value
45 101 != 100
46 at:
47 file: 'file'
48 line: 42
49 function: 'func'
50 + ...
51 +not ok 6 - combined::int_note
52 ---
51 -not ok 6 - combined::int_fmt
53 + reason: |
54 + Expected comparison to hold: 101 == value
55 + extra note on failing test
56 + at:
57 + file: 'file'
58 + line: 42
59 + function: 'func'
60 + ...
61 +not ok 7 - combined::int_fmt
62 ---
63 reason: |
54 - 022 != value
64 + Expected comparison to hold: 022 == value
65 0022 != 0144
66 at:
67 file: 'file'
68 line: 42
69 function: 'func'
60 - ---
61 -not ok 7 - combined::bool
70 + ...
71 +not ok 8 - combined::bool
72 ---
73 reason: |
74 0 != value
@@ -67,8 +77,8 @@ not ok 7 - combined::bool
77 file: 'file'
78 line: 42
79 function: 'func'
70 - ---
71 -not ok 8 - combined::multiline_description
80 + ...
81 +not ok 9 - combined::multiline_description
82 ---
83 reason: |
84 Function call failed: -1
@@ -78,8 +88,8 @@ not ok 8 - combined::multiline_description
88 file: 'file'
89 line: 42
90 function: 'func'
81 - ---
82 -not ok 9 - combined::null_string
91 + ...
92 +not ok 10 - combined::null_string
93 ---
94 reason: |
95 String mismatch: "expected" != actual ("this one fails")
@@ -88,5 +98,55 @@ not ok 9 - combined::null_string
98 file: 'file'
99 line: 42
100 function: 'func'
101 + ...
102 +not ok 11 - combined::failf
103 + ---
104 + reason: |
105 + Test failed.
106 + some reason: foo
107 + at:
108 + file: 'file'
109 + line: 42
110 + function: 'func'
111 + ...
112 +not ok 12 - combined::compare_i
113 ---
92 -1..9
114 + reason: |
115 + Expected comparison to hold: two < 1
116 + 2 >= 1
117 + at:
118 + file: 'file'
119 + line: 42
120 + function: 'func'
121 + ...
122 +not ok 13 - combined::compare_i_with_format
123 + ---
124 + reason: |
125 + Expected comparison to hold: two < 1
126 + foo: bar
127 + at:
128 + file: 'file'
129 + line: 42
130 + function: 'func'
131 + ...
132 +not ok 14 - combined::compare_u
133 + ---
134 + reason: |
135 + Expected comparison to hold: two < 1
136 + 2 >= 1
137 + at:
138 + file: 'file'
139 + line: 42
140 + function: 'func'
141 + ...
142 +not ok 15 - combined::compare_u_with_format
143 + ---
144 + reason: |
145 + Expected comparison to hold: two < 1
146 + foo: bar
147 + at:
148 + file: 'file'
149 + line: 42
150 + function: 'func'
151 + ...
152 +1..15
t/unit-tests/clar/test/expected/without_arguments
+36 -6
@@ -1,6 +1,6 @@
1 Loaded 1 suites:
2 Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')
3 -FFFFFFFFF
3 +FFFFFFFFFFFFFFF
4
5 1) Failure:
6 combined::1 [file:42]
@@ -22,27 +22,57 @@ combined::strings_with_length [file:42]
22
23 5) Failure:
24 combined::int [file:42]
25 - 101 != value ("extra note on failing test")
25 + Expected comparison to hold: 101 == value
26 101 != 100
27
28 6) Failure:
29 +combined::int_note [file:42]
30 + Expected comparison to hold: 101 == value
31 + extra note on failing test
32 +
33 + 7) Failure:
34 combined::int_fmt [file:42]
30 - 022 != value
35 + Expected comparison to hold: 022 == value
36 0022 != 0144
37
33 - 7) Failure:
38 + 8) Failure:
39 combined::bool [file:42]
40 0 != value
41 0 != 1
42
38 - 8) Failure:
43 + 9) Failure:
44 combined::multiline_description [file:42]
45 Function call failed: -1
46 description line 1
47 description line 2
48
44 - 9) Failure:
49 + 10) Failure:
50 combined::null_string [file:42]
51 String mismatch: "expected" != actual ("this one fails")
52 'expected' != NULL
53
54 + 11) Failure:
55 +combined::failf [file:42]
56 + Test failed.
57 + some reason: foo
58 +
59 + 12) Failure:
60 +combined::compare_i [file:42]
61 + Expected comparison to hold: two < 1
62 + 2 >= 1
63 +
64 + 13) Failure:
65 +combined::compare_i_with_format [file:42]
66 + Expected comparison to hold: two < 1
67 + foo: bar
68 +
69 + 14) Failure:
70 +combined::compare_u [file:42]
71 + Expected comparison to hold: two < 1
72 + 2 >= 1
73 +
74 + 15) Failure:
75 +combined::compare_u_with_format [file:42]
76 + Expected comparison to hold: two < 1
77 + foo: bar
78 +
t/unit-tests/clar/test/selftest.c
+5 -5
@@ -298,7 +298,7 @@ void test_selftest__help(void)
298
299 void test_selftest__without_arguments(void)
300 {
301 - cl_invoke(assert_output("combined", "without_arguments", 9, NULL));
301 + cl_invoke(assert_output("combined", "without_arguments", 15, NULL));
302 }
303
304 void test_selftest__specific_test(void)
@@ -313,12 +313,12 @@ void test_selftest__stop_on_failure(void)
313
314 void test_selftest__quiet(void)
315 {
316 - cl_invoke(assert_output("combined", "quiet", 9, "-q", NULL));
316 + cl_invoke(assert_output("combined", "quiet", 15, "-q", NULL));
317 }
318
319 void test_selftest__tap(void)
320 {
321 - cl_invoke(assert_output("combined", "tap", 9, "-t", NULL));
321 + cl_invoke(assert_output("combined", "tap", 15, "-t", NULL));
322 }
323
324 void test_selftest__suite_names(void)
@@ -329,7 +329,7 @@ void test_selftest__suite_names(void)
329 void test_selftest__summary_without_filename(void)
330 {
331 struct stat st;
332 - cl_invoke(assert_output("combined", "summary_without_filename", 9, "-r", NULL));
332 + cl_invoke(assert_output("combined", "summary_without_filename", 15, "-r", NULL));
333 /* The summary contains timestamps, so we cannot verify its contents. */
334 cl_must_pass(stat("summary.xml", &st));
335 }
@@ -337,7 +337,7 @@ void test_selftest__summary_without_filename(void)
337 void test_selftest__summary_with_filename(void)
338 {
339 struct stat st;
340 - cl_invoke(assert_output("combined", "summary_with_filename", 9, "-rdifferent.xml", NULL));
340 + cl_invoke(assert_output("combined", "summary_with_filename", 15, "-rdifferent.xml", NULL));
341 /* The summary contains timestamps, so we cannot verify its contents. */
342 cl_must_pass(stat("different.xml", &st));
343 }
t/unit-tests/clar/test/suites/combined.c
+64 -1
@@ -55,7 +55,12 @@ void test_combined__strings_with_length(void)
55 void test_combined__int(void)
56 {
57 int value = 100;
58 - cl_assert_equal_i(100, value);
58 + cl_assert_equal_i(101, value);
59 +}
60 +
61 +void test_combined__int_note(void)
62 +{
63 + int value = 100;
64 cl_assert_equal_i_(101, value, "extra note on failing test");
65 }
66
@@ -83,3 +88,61 @@ void test_combined__null_string(void)
88 cl_assert_equal_s(actual, actual);
89 cl_assert_equal_s_("expected", actual, "this one fails");
90 }
91 +
92 +void test_combined__failf(void)
93 +{
94 + cl_failf("some reason: %s", "foo");
95 +}
96 +
97 +void test_combined__compare_i(void)
98 +{
99 + int one = 1, two = 2;
100 +
101 + cl_assert_equal_i(one, 1);
102 + cl_assert_equal_i(one, 1);
103 + cl_assert_equal_i_(one, 1, "format");
104 + cl_assert_lt_i(one, 2);
105 + cl_assert_lt_i_(one, 2, "format");
106 + cl_assert_le_i(one, 2);
107 + cl_assert_le_i(two, 2);
108 + cl_assert_le_i_(two, 2, "format");
109 + cl_assert_gt_i(two, 1);
110 + cl_assert_gt_i_(two, 1, "format");
111 + cl_assert_ge_i(two, 2);
112 + cl_assert_ge_i(3, two);
113 + cl_assert_ge_i_(3, two, "format");
114 +
115 + cl_assert_lt_i(two, 1); /* this one fails */
116 +}
117 +
118 +void test_combined__compare_i_with_format(void)
119 +{
120 + int two = 2;
121 + cl_assert_lt_i_(two, 1, "foo: %s", "bar");
122 +}
123 +
124 +void test_combined__compare_u(void)
125 +{
126 + unsigned one = 1, two = 2;
127 +
128 + cl_assert_equal_u(one, 1);
129 + cl_assert_equal_u_(one, 1, "format");
130 + cl_assert_lt_u(one, 2);
131 + cl_assert_lt_u_(one, 2, "format");
132 + cl_assert_le_u(one, 2);
133 + cl_assert_le_u(two, 2);
134 + cl_assert_le_u_(two, 2, "format");
135 + cl_assert_gt_u(two, 1);
136 + cl_assert_gt_u_(two, 1, "format");
137 + cl_assert_ge_u(two, 2);
138 + cl_assert_ge_u(3, two);
139 + cl_assert_ge_u_(3, two, "format");
140 +
141 + cl_assert_lt_u(two, 1); /* this one fails */
142 +}
143 +
144 +void test_combined__compare_u_with_format(void)
145 +{
146 + unsigned two = 2;
147 + cl_assert_lt_u_(two, 1, "foo: %s", "bar");
148 +}
t/unit-tests/unit-test.h
-6
@@ -7,9 +7,3 @@
7 #else
8 # include GIT_CLAR_DECLS_H
9 #endif
10 -
11 -#define cl_failf(fmt, ...) do { \
12 - char desc[4096]; \
13 - snprintf(desc, sizeof(desc), fmt, __VA_ARGS__); \
14 - clar__fail(__FILE__, __func__, __LINE__, "Test failed.", desc, 1); \
15 -} while (0)