t/unit-tests: convert reftable stack test to use clar
Adapt reftable stack test file to use clar by using clar assertions where necessary. This marks the end of all unit tests migrated away from the `unit-tests/t-*.c` pattern, there are no longer any files matching that glob. Remove the sanity check for `t-*.c` files to prevent Meson configuration errors during CI and local builds. Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Seyi Kuforiji committed
Jul 24, 2025 at 15:28 UTC
1cfd187fc12b1c82e4e0d0c86c580ee1e2d7e0ba
3 files changed
+332
-454
Makefile
+1
-1
@@ -1369,6 +1369,7 @@ CLAR_TEST_SUITES += u-reftable-block
1369
CLAR_TEST_SUITES += u-reftable-merged
1370
CLAR_TEST_SUITES += u-reftable-pq
1371
CLAR_TEST_SUITES += u-reftable-readwrite
1372
+CLAR_TEST_SUITES += u-reftable-stack
1373
CLAR_TEST_SUITES += u-reftable-table
1374
CLAR_TEST_SUITES += u-reftable-tree
1375
CLAR_TEST_SUITES += u-strbuf
@@ -1383,7 +1384,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
1384
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
1385
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable-clar.o
1386
1386
-UNIT_TEST_PROGRAMS += t-reftable-stack
1387
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
1388
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
1389
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
t/meson.build
+1
-3
@@ -14,6 +14,7 @@ clar_test_suites = [
14
'unit-tests/u-reftable-pq.c',
15
'unit-tests/u-reftable-readwrite.c',
16
'unit-tests/u-reftable-record.c',
17
+ 'unit-tests/u-reftable-stack.c',
18
'unit-tests/u-reftable-table.c',
19
'unit-tests/u-reftable-tree.c',
20
'unit-tests/u-strbuf.c',
@@ -62,7 +63,6 @@ clar_unit_tests = executable('unit-tests',
63
test('unit-tests', clar_unit_tests)
64
65
unit_test_programs = [
65
- 'unit-tests/t-reftable-stack.c',
66
]
67
68
foreach unit_test_program : unit_test_programs
@@ -1164,8 +1164,6 @@ benchmarks = [
1164
# sufficient to catch missing test suites in our CI though.
1165
foreach glob, tests : {
1166
't[0-9][0-9][0-9][0-9]-*.sh': integration_tests,
1167
- 'perf/p[0-9][0-9][0-9][0-9]-*.sh': benchmarks,
1168
- 'unit-tests/t-*.c': unit_test_programs,
1167
'unit-tests/u-*.c': clar_test_suites,
1168
}
1169
actual_tests = run_command(shell, '-c', 'ls ' + glob,
t/unit-tests/u-reftable-stack.c
renamed
+330
-450
@@ -8,9 +8,9 @@ https://developers.google.com/open-source/licenses/bsd
8
9
#define DISABLE_SIGN_COMPARE_WARNINGS
10
11
-#include "test-lib.h"
12
-#include "lib-reftable.h"
11
+#include "unit-test.h"
12
#include "dir.h"
13
+#include "lib-reftable-clar.h"
14
#include "reftable/merged.h"
15
#include "reftable/reftable-error.h"
16
#include "reftable/stack.h"
@@ -70,11 +70,11 @@ static char *get_tmp_template(int linenumber)
70
static char *get_tmp_dir(int linenumber)
71
{
72
char *dir = get_tmp_template(linenumber);
73
- check(mkdtemp(dir) != NULL);
73
+ cl_assert(mkdtemp(dir) != NULL);
74
return dir;
75
}
76
77
-static void t_read_file(void)
77
+void test_reftable_stack__read_file(void)
78
{
79
char *fn = get_tmp_template(__LINE__);
80
struct tempfile *tmp = mks_tempfile(fn);
@@ -84,17 +84,17 @@ static void t_read_file(void)
84
char **names = NULL;
85
const char *want[] = { "line1", "line2", "line3" };
86
87
- check_int(fd, >, 0);
87
+ cl_assert(fd > 0);
88
n = write_in_full(fd, out, strlen(out));
89
- check_int(n, ==, strlen(out));
89
+ cl_assert_equal_i(n, strlen(out));
90
err = close(fd);
91
- check_int(err, >=, 0);
91
+ cl_assert(err >= 0);
92
93
err = read_lines(fn, &names);
94
- check(!err);
94
+ cl_assert(!err);
95
96
for (size_t i = 0; names[i]; i++)
97
- check_str(want[i], names[i]);
97
+ cl_assert_equal_s(want[i], names[i]);
98
free_names(names);
99
(void) remove(fn);
100
delete_tempfile(&tmp);
@@ -103,8 +103,8 @@ static void t_read_file(void)
103
static int write_test_ref(struct reftable_writer *wr, void *arg)
104
{
105
struct reftable_ref_record *ref = arg;
106
- check(!reftable_writer_set_limits(wr, ref->update_index,
107
- ref->update_index));
106
+ cl_assert_equal_i(reftable_writer_set_limits(wr,
107
+ ref->update_index, ref->update_index), 0);
108
return reftable_writer_add_ref(wr, ref);
109
}
110
@@ -112,7 +112,6 @@ static void write_n_ref_tables(struct reftable_stack *st,
112
size_t n)
113
{
114
int disable_auto_compact;
115
- int err;
115
116
disable_auto_compact = st->opts.disable_auto_compact;
117
st->opts.disable_auto_compact = 1;
@@ -126,10 +125,10 @@ static void write_n_ref_tables(struct reftable_stack *st,
125
126
snprintf(buf, sizeof(buf), "refs/heads/branch-%04"PRIuMAX, (uintmax_t)i);
127
ref.refname = buf;
129
- t_reftable_set_hash(ref.value.val1, i, REFTABLE_HASH_SHA1);
128
+ cl_reftable_set_hash(ref.value.val1, i, REFTABLE_HASH_SHA1);
129
131
- err = reftable_stack_add(st, &write_test_ref, &ref);
132
- check(!err);
130
+ cl_assert_equal_i(reftable_stack_add(st,
131
+ &write_test_ref, &ref), 0);
132
}
133
134
st->opts.disable_auto_compact = disable_auto_compact;
@@ -144,12 +143,13 @@ static int write_test_log(struct reftable_writer *wr, void *arg)
143
{
144
struct write_log_arg *wla = arg;
145
147
- check(!reftable_writer_set_limits(wr, wla->update_index,
148
- wla->update_index));
146
+ cl_assert_equal_i(reftable_writer_set_limits(wr,
147
+ wla->update_index,
148
+ wla->update_index), 0);
149
return reftable_writer_add_log(wr, wla->log);
150
}
151
152
-static void t_reftable_stack_add_one(void)
152
+void test_reftable_stack__add_one(void)
153
{
154
char *dir = get_tmp_dir(__LINE__);
155
struct reftable_buf scratch = REFTABLE_BUF_INIT;
@@ -158,7 +158,6 @@ static void t_reftable_stack_add_one(void)
158
.default_permissions = 0660,
159
};
160
struct reftable_stack *st = NULL;
161
- int err;
161
struct reftable_ref_record ref = {
162
.refname = (char *) "HEAD",
163
.update_index = 1,
@@ -167,32 +166,37 @@ static void t_reftable_stack_add_one(void)
166
};
167
struct reftable_ref_record dest = { 0 };
168
struct stat stat_result = { 0 };
169
+ int err;
170
+
171
err = reftable_new_stack(&st, dir, &opts);
171
- check(!err);
172
+ cl_assert(!err);
173
174
err = reftable_stack_add(st, write_test_ref, &ref);
174
- check(!err);
175
+ cl_assert(!err);
176
177
err = reftable_stack_read_ref(st, ref.refname, &dest);
177
- check(!err);
178
- check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
179
- check_int(st->tables_len, >, 0);
178
+ cl_assert(!err);
179
+ cl_assert(reftable_ref_record_equal(&ref, &dest,
180
+ REFTABLE_HASH_SIZE_SHA1));
181
+ cl_assert(st->tables_len > 0);
182
183
#ifndef GIT_WINDOWS_NATIVE
182
- check(!reftable_buf_addstr(&scratch, dir));
183
- check(!reftable_buf_addstr(&scratch, "/tables.list"));
184
- err = stat(scratch.buf, &stat_result);
185
- check(!err);
186
- check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
184
+ cl_assert_equal_i(reftable_buf_addstr(&scratch, dir), 0);
185
+ cl_assert_equal_i(reftable_buf_addstr(&scratch,
186
+ "/tables.list"), 0);
187
+ cl_assert_equal_i(stat(scratch.buf, &stat_result), 0);
188
+ cl_assert_equal_i((stat_result.st_mode & 0777),
189
+ opts.default_permissions);
190
191
reftable_buf_reset(&scratch);
189
- check(!reftable_buf_addstr(&scratch, dir));
190
- check(!reftable_buf_addstr(&scratch, "/"));
192
+ cl_assert_equal_i(reftable_buf_addstr(&scratch, dir), 0);
193
+ cl_assert_equal_i(reftable_buf_addstr(&scratch, "/"), 0);
194
/* do not try at home; not an external API for reftable. */
192
- check(!reftable_buf_addstr(&scratch, st->tables[0]->name));
195
+ cl_assert(!reftable_buf_addstr(&scratch, st->tables[0]->name));
196
err = stat(scratch.buf, &stat_result);
194
- check(!err);
195
- check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
197
+ cl_assert(!err);
198
+ cl_assert_equal_i((stat_result.st_mode & 0777),
199
+ opts.default_permissions);
200
#else
201
(void) stat_result;
202
#endif
@@ -204,14 +208,13 @@ static void t_reftable_stack_add_one(void)
208
umask(mask);
209
}
210
207
-static void t_reftable_stack_uptodate(void)
211
+void test_reftable_stack__uptodate(void)
212
{
213
struct reftable_write_options opts = { 0 };
214
struct reftable_stack *st1 = NULL;
215
struct reftable_stack *st2 = NULL;
216
char *dir = get_tmp_dir(__LINE__);
217
214
- int err;
218
struct reftable_ref_record ref1 = {
219
.refname = (char *) "HEAD",
220
.update_index = 1,
@@ -229,34 +232,25 @@ static void t_reftable_stack_uptodate(void)
232
/* simulate multi-process access to the same stack
233
by creating two stacks for the same directory.
234
*/
232
- err = reftable_new_stack(&st1, dir, &opts);
233
- check(!err);
234
-
235
- err = reftable_new_stack(&st2, dir, &opts);
236
- check(!err);
237
-
238
- err = reftable_stack_add(st1, write_test_ref, &ref1);
239
- check(!err);
240
-
241
- err = reftable_stack_add(st2, write_test_ref, &ref2);
242
- check_int(err, ==, REFTABLE_OUTDATED_ERROR);
243
-
244
- err = reftable_stack_reload(st2);
245
- check(!err);
246
-
247
- err = reftable_stack_add(st2, write_test_ref, &ref2);
248
- check(!err);
235
+ cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
236
+ cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
237
+ cl_assert_equal_i(reftable_stack_add(st1, write_test_ref,
238
+ &ref1), 0);
239
+ cl_assert_equal_i(reftable_stack_add(st2, write_test_ref,
240
+ &ref2), REFTABLE_OUTDATED_ERROR);
241
+ cl_assert_equal_i(reftable_stack_reload(st2), 0);
242
+ cl_assert_equal_i(reftable_stack_add(st2, write_test_ref,
243
+ &ref2), 0);
244
reftable_stack_destroy(st1);
245
reftable_stack_destroy(st2);
246
clear_dir(dir);
247
}
248
254
-static void t_reftable_stack_transaction_api(void)
249
+void test_reftable_stack__transaction_api(void)
250
{
251
char *dir = get_tmp_dir(__LINE__);
252
struct reftable_write_options opts = { 0 };
253
struct reftable_stack *st = NULL;
259
- int err;
254
struct reftable_addition *add = NULL;
255
256
struct reftable_ref_record ref = {
@@ -267,37 +261,32 @@ static void t_reftable_stack_transaction_api(void)
261
};
262
struct reftable_ref_record dest = { 0 };
263
270
- err = reftable_new_stack(&st, dir, &opts);
271
- check(!err);
264
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
265
266
reftable_addition_destroy(add);
267
275
- err = reftable_stack_new_addition(&add, st, 0);
276
- check(!err);
277
-
278
- err = reftable_addition_add(add, write_test_ref, &ref);
279
- check(!err);
280
-
281
- err = reftable_addition_commit(add);
282
- check(!err);
268
+ cl_assert_equal_i(reftable_stack_new_addition(&add, st, 0), 0);
269
+ cl_assert_equal_i(reftable_addition_add(add, write_test_ref,
270
+ &ref), 0);
271
+ cl_assert_equal_i(reftable_addition_commit(add), 0);
272
273
reftable_addition_destroy(add);
274
286
- err = reftable_stack_read_ref(st, ref.refname, &dest);
287
- check(!err);
288
- check_int(REFTABLE_REF_SYMREF, ==, dest.value_type);
289
- check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
275
+ cl_assert_equal_i(reftable_stack_read_ref(st, ref.refname,
276
+ &dest), 0);
277
+ cl_assert_equal_i(REFTABLE_REF_SYMREF, dest.value_type);
278
+ cl_assert(reftable_ref_record_equal(&ref, &dest,
279
+ REFTABLE_HASH_SIZE_SHA1) != 0);
280
281
reftable_ref_record_release(&dest);
282
reftable_stack_destroy(st);
283
clear_dir(dir);
284
}
285
296
-static void t_reftable_stack_transaction_with_reload(void)
286
+void test_reftable_stack__transaction_with_reload(void)
287
{
288
char *dir = get_tmp_dir(__LINE__);
289
struct reftable_stack *st1 = NULL, *st2 = NULL;
300
- int err;
290
struct reftable_addition *add = NULL;
291
struct reftable_ref_record refs[2] = {
292
{
@@ -315,17 +304,12 @@ static void t_reftable_stack_transaction_with_reload(void)
304
};
305
struct reftable_ref_record ref = { 0 };
306
318
- err = reftable_new_stack(&st1, dir, NULL);
319
- check(!err);
320
- err = reftable_new_stack(&st2, dir, NULL);
321
- check(!err);
322
-
323
- err = reftable_stack_new_addition(&add, st1, 0);
324
- check(!err);
325
- err = reftable_addition_add(add, write_test_ref, &refs[0]);
326
- check(!err);
327
- err = reftable_addition_commit(add);
328
- check(!err);
307
+ cl_assert_equal_i(reftable_new_stack(&st1, dir, NULL), 0);
308
+ cl_assert_equal_i(reftable_new_stack(&st2, dir, NULL), 0);
309
+ cl_assert_equal_i(reftable_stack_new_addition(&add, st1, 0), 0);
310
+ cl_assert_equal_i(reftable_addition_add(add, write_test_ref,
311
+ &refs[0]), 0);
312
+ cl_assert_equal_i(reftable_addition_commit(add), 0);
313
reftable_addition_destroy(add);
314
315
/*
@@ -333,20 +317,20 @@ static void t_reftable_stack_transaction_with_reload(void)
317
* create the addition and lock the stack by default, but allow the
318
* reload to happen when REFTABLE_STACK_NEW_ADDITION_RELOAD is set.
319
*/
336
- err = reftable_stack_new_addition(&add, st2, 0);
337
- check_int(err, ==, REFTABLE_OUTDATED_ERROR);
338
- err = reftable_stack_new_addition(&add, st2, REFTABLE_STACK_NEW_ADDITION_RELOAD);
339
- check(!err);
340
- err = reftable_addition_add(add, write_test_ref, &refs[1]);
341
- check(!err);
342
- err = reftable_addition_commit(add);
343
- check(!err);
320
+ cl_assert_equal_i(reftable_stack_new_addition(&add, st2, 0),
321
+ REFTABLE_OUTDATED_ERROR);
322
+ cl_assert_equal_i(reftable_stack_new_addition(&add, st2,
323
+ REFTABLE_STACK_NEW_ADDITION_RELOAD), 0);
324
+ cl_assert_equal_i(reftable_addition_add(add, write_test_ref,
325
+ &refs[1]), 0);
326
+ cl_assert_equal_i(reftable_addition_commit(add), 0);
327
reftable_addition_destroy(add);
328
329
for (size_t i = 0; i < ARRAY_SIZE(refs); i++) {
347
- err = reftable_stack_read_ref(st2, refs[i].refname, &ref);
348
- check(!err);
349
- check(reftable_ref_record_equal(&refs[i], &ref, REFTABLE_HASH_SIZE_SHA1));
330
+ cl_assert_equal_i(reftable_stack_read_ref(st2,
331
+ refs[i].refname, &ref) , 0);
332
+ cl_assert(reftable_ref_record_equal(&refs[i], &ref,
333
+ REFTABLE_HASH_SIZE_SHA1) != 0);
334
}
335
336
reftable_ref_record_release(&ref);
@@ -355,17 +339,15 @@ static void t_reftable_stack_transaction_with_reload(void)
339
clear_dir(dir);
340
}
341
358
-static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
342
+void test_reftable_stack__transaction_api_performs_auto_compaction(void)
343
{
344
char *dir = get_tmp_dir(__LINE__);
345
struct reftable_write_options opts = {0};
346
struct reftable_addition *add = NULL;
347
struct reftable_stack *st = NULL;
348
size_t n = 20;
365
- int err;
349
367
- err = reftable_new_stack(&st, dir, &opts);
368
- check(!err);
350
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
351
352
for (size_t i = 0; i <= n; i++) {
353
struct reftable_ref_record ref = {
@@ -385,14 +367,11 @@ static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
367
*/
368
st->opts.disable_auto_compact = i != n;
369
388
- err = reftable_stack_new_addition(&add, st, 0);
389
- check(!err);
390
-
391
- err = reftable_addition_add(add, write_test_ref, &ref);
392
- check(!err);
393
-
394
- err = reftable_addition_commit(add);
395
- check(!err);
370
+ cl_assert_equal_i(reftable_stack_new_addition(&add,
371
+ st, 0), 0);
372
+ cl_assert_equal_i(reftable_addition_add(add,
373
+ write_test_ref, &ref), 0);
374
+ cl_assert_equal_i(reftable_addition_commit(add), 0);
375
376
reftable_addition_destroy(add);
377
@@ -402,16 +381,16 @@ static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
381
* all tables in the stack.
382
*/
383
if (i != n)
405
- check_int(st->merged->tables_len, ==, i + 1);
384
+ cl_assert_equal_i(st->merged->tables_len, i + 1);
385
else
407
- check_int(st->merged->tables_len, ==, 1);
386
+ cl_assert_equal_i(st->merged->tables_len, 1);
387
}
388
389
reftable_stack_destroy(st);
390
clear_dir(dir);
391
}
392
414
-static void t_reftable_stack_auto_compaction_fails_gracefully(void)
393
+void test_reftable_stack__auto_compaction_fails_gracefully(void)
394
{
395
struct reftable_ref_record ref = {
396
.refname = (char *) "refs/heads/master",
@@ -425,32 +404,31 @@ static void t_reftable_stack_auto_compaction_fails_gracefully(void)
404
char *dir = get_tmp_dir(__LINE__);
405
int err;
406
428
- err = reftable_new_stack(&st, dir, &opts);
429
- check(!err);
430
-
431
- err = reftable_stack_add(st, write_test_ref, &ref);
432
- check(!err);
433
- check_int(st->merged->tables_len, ==, 1);
434
- check_int(st->stats.attempts, ==, 0);
435
- check_int(st->stats.failures, ==, 0);
407
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
408
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
409
+ &ref), 0);
410
+ cl_assert_equal_i(st->merged->tables_len, 1);
411
+ cl_assert_equal_i(st->stats.attempts, 0);
412
+ cl_assert_equal_i(st->stats.failures, 0);
413
414
/*
415
* Lock the newly written table such that it cannot be compacted.
416
* Adding a new table to the stack should not be impacted by this, even
417
* though auto-compaction will now fail.
418
*/
442
- check(!reftable_buf_addstr(&table_path, dir));
443
- check(!reftable_buf_addstr(&table_path, "/"));
444
- check(!reftable_buf_addstr(&table_path, st->tables[0]->name));
445
- check(!reftable_buf_addstr(&table_path, ".lock"));
419
+ cl_assert(!reftable_buf_addstr(&table_path, dir));
420
+ cl_assert(!reftable_buf_addstr(&table_path, "/"));
421
+ cl_assert(!reftable_buf_addstr(&table_path,
422
+ st->tables[0]->name));
423
+ cl_assert(!reftable_buf_addstr(&table_path, ".lock"));
424
write_file_buf(table_path.buf, "", 0);
425
426
ref.update_index = 2;
427
err = reftable_stack_add(st, write_test_ref, &ref);
450
- check(!err);
451
- check_int(st->merged->tables_len, ==, 2);
452
- check_int(st->stats.attempts, ==, 1);
453
- check_int(st->stats.failures, ==, 1);
428
+ cl_assert(!err);
429
+ cl_assert_equal_i(st->merged->tables_len, 2);
430
+ cl_assert_equal_i(st->stats.attempts, 1);
431
+ cl_assert_equal_i(st->stats.failures, 1);
432
433
reftable_stack_destroy(st);
434
reftable_buf_release(&table_path);
@@ -462,12 +440,11 @@ static int write_error(struct reftable_writer *wr UNUSED, void *arg)
440
return *((int *)arg);
441
}
442
465
-static void t_reftable_stack_update_index_check(void)
443
+void test_reftable_stack__update_index_check(void)
444
{
445
char *dir = get_tmp_dir(__LINE__);
446
struct reftable_write_options opts = { 0 };
447
struct reftable_stack *st = NULL;
470
- int err;
448
struct reftable_ref_record ref1 = {
449
.refname = (char *) "name1",
450
.update_index = 1,
@@ -481,39 +458,33 @@ static void t_reftable_stack_update_index_check(void)
458
.value.symref = (char *) "master",
459
};
460
484
- err = reftable_new_stack(&st, dir, &opts);
485
- check(!err);
486
-
487
- err = reftable_stack_add(st, write_test_ref, &ref1);
488
- check(!err);
489
-
490
- err = reftable_stack_add(st, write_test_ref, &ref2);
491
- check_int(err, ==, REFTABLE_API_ERROR);
461
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
462
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
463
+ &ref1), 0);
464
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
465
+ &ref2), REFTABLE_API_ERROR);
466
reftable_stack_destroy(st);
467
clear_dir(dir);
468
}
469
496
-static void t_reftable_stack_lock_failure(void)
470
+void test_reftable_stack__lock_failure(void)
471
{
472
char *dir = get_tmp_dir(__LINE__);
473
struct reftable_write_options opts = { 0 };
474
struct reftable_stack *st = NULL;
501
- int err, i;
475
+ int i;
476
503
- err = reftable_new_stack(&st, dir, &opts);
504
- check(!err);
505
- for (i = -1; i != REFTABLE_EMPTY_TABLE_ERROR; i--) {
506
- err = reftable_stack_add(st, write_error, &i);
507
- check_int(err, ==, i);
508
- }
477
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
478
+ for (i = -1; i != REFTABLE_EMPTY_TABLE_ERROR; i--)
479
+ cl_assert_equal_i(reftable_stack_add(st, write_error,
480
+ &i), i);
481
482
reftable_stack_destroy(st);
483
clear_dir(dir);
484
}
485
514
-static void t_reftable_stack_add(void)
486
+void test_reftable_stack__add(void)
487
{
516
- int err = 0;
488
struct reftable_write_options opts = {
489
.exact_log_message = 1,
490
.default_permissions = 0660,
@@ -526,9 +497,10 @@ static void t_reftable_stack_add(void)
497
struct reftable_buf path = REFTABLE_BUF_INIT;
498
struct stat stat_result;
499
size_t i, N = ARRAY_SIZE(refs);
500
+ int err;
501
502
err = reftable_new_stack(&st, dir, &opts);
531
- check(!err);
503
+ cl_assert(!err);
504
505
for (i = 0; i < N; i++) {
506
char buf[256];
@@ -536,66 +508,66 @@ static void t_reftable_stack_add(void)
508
refs[i].refname = xstrdup(buf);
509
refs[i].update_index = i + 1;
510
refs[i].value_type = REFTABLE_REF_VAL1;
539
- t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
511
+ cl_reftable_set_hash(refs[i].value.val1, i,
512
+ REFTABLE_HASH_SHA1);
513
514
logs[i].refname = xstrdup(buf);
515
logs[i].update_index = N + i + 1;
516
logs[i].value_type = REFTABLE_LOG_UPDATE;
517
logs[i].value.update.email = xstrdup("identity@invalid");
545
- t_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1);
518
+ cl_reftable_set_hash(logs[i].value.update.new_hash, i,
519
+ REFTABLE_HASH_SHA1);
520
}
521
548
- for (i = 0; i < N; i++) {
549
- int err = reftable_stack_add(st, write_test_ref, &refs[i]);
550
- check(!err);
551
- }
522
+ for (i = 0; i < N; i++)
523
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
524
+ &refs[i]), 0);
525
526
for (i = 0; i < N; i++) {
527
struct write_log_arg arg = {
528
.log = &logs[i],
529
.update_index = reftable_stack_next_update_index(st),
530
};
558
- int err = reftable_stack_add(st, write_test_log, &arg);
559
- check(!err);
531
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
532
+ &arg), 0);
533
}
534
562
- err = reftable_stack_compact_all(st, NULL);
563
- check(!err);
535
+ cl_assert_equal_i(reftable_stack_compact_all(st, NULL), 0);
536
537
for (i = 0; i < N; i++) {
538
struct reftable_ref_record dest = { 0 };
539
568
- int err = reftable_stack_read_ref(st, refs[i].refname, &dest);
569
- check(!err);
570
- check(reftable_ref_record_equal(&dest, refs + i,
571
- REFTABLE_HASH_SIZE_SHA1));
540
+ cl_assert_equal_i(reftable_stack_read_ref(st,
541
+ refs[i].refname, &dest), 0);
542
+ cl_assert(reftable_ref_record_equal(&dest, refs + i,
543
+ REFTABLE_HASH_SIZE_SHA1) != 0);
544
reftable_ref_record_release(&dest);
545
}
546
547
for (i = 0; i < N; i++) {
548
struct reftable_log_record dest = { 0 };
577
- int err = reftable_stack_read_log(st, refs[i].refname, &dest);
578
- check(!err);
579
- check(reftable_log_record_equal(&dest, logs + i,
580
- REFTABLE_HASH_SIZE_SHA1));
549
+ cl_assert_equal_i(reftable_stack_read_log(st,
550
+ refs[i].refname, &dest), 0);
551
+ cl_assert(reftable_log_record_equal(&dest, logs + i,
552
+ REFTABLE_HASH_SIZE_SHA1) != 0);
553
reftable_log_record_release(&dest);
554
}
555
556
#ifndef GIT_WINDOWS_NATIVE
585
- check(!reftable_buf_addstr(&path, dir));
586
- check(!reftable_buf_addstr(&path, "/tables.list"));
587
- err = stat(path.buf, &stat_result);
588
- check(!err);
589
- check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
557
+ cl_assert_equal_i(reftable_buf_addstr(&path, dir), 0);
558
+ cl_assert_equal_i(reftable_buf_addstr(&path, "/tables.list"), 0);
559
+ cl_assert_equal_i(stat(path.buf, &stat_result), 0);
560
+ cl_assert_equal_i((stat_result.st_mode & 0777), opts.default_permissions);
561
562
reftable_buf_reset(&path);
592
- check(!reftable_buf_addstr(&path, dir));
593
- check(!reftable_buf_addstr(&path, "/"));
563
+ cl_assert_equal_i(reftable_buf_addstr(&path, dir), 0);
564
+ cl_assert_equal_i(reftable_buf_addstr(&path, "/"), 0);
565
/* do not try at home; not an external API for reftable. */
595
- check(!reftable_buf_addstr(&path, st->tables[0]->name));
566
+ cl_assert(!reftable_buf_addstr(&path, st->tables[0]->name));
567
err = stat(path.buf, &stat_result);
597
- check(!err);
598
- check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
568
+ cl_assert(!err);
569
+ cl_assert_equal_i((stat_result.st_mode & 0777),
570
+ opts.default_permissions);
571
#else
572
(void) stat_result;
573
#endif
@@ -610,7 +582,7 @@ static void t_reftable_stack_add(void)
582
clear_dir(dir);
583
}
584
613
-static void t_reftable_stack_iterator(void)
585
+void test_reftable_stack__iterator(void)
586
{
587
struct reftable_write_options opts = { 0 };
588
struct reftable_stack *st = NULL;
@@ -621,27 +593,27 @@ static void t_reftable_stack_iterator(void)
593
size_t N = ARRAY_SIZE(refs), i;
594
int err;
595
624
- err = reftable_new_stack(&st, dir, &opts);
625
- check(!err);
596
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
597
598
for (i = 0; i < N; i++) {
599
refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
600
refs[i].update_index = i + 1;
601
refs[i].value_type = REFTABLE_REF_VAL1;
631
- t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
602
+ cl_reftable_set_hash(refs[i].value.val1, i,
603
+ REFTABLE_HASH_SHA1);
604
605
logs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
606
logs[i].update_index = i + 1;
607
logs[i].value_type = REFTABLE_LOG_UPDATE;
608
logs[i].value.update.email = xstrdup("johndoe@invalid");
609
logs[i].value.update.message = xstrdup("commit\n");
638
- t_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1);
610
+ cl_reftable_set_hash(logs[i].value.update.new_hash, i,
611
+ REFTABLE_HASH_SHA1);
612
}
613
641
- for (i = 0; i < N; i++) {
642
- err = reftable_stack_add(st, write_test_ref, &refs[i]);
643
- check(!err);
644
- }
614
+ for (i = 0; i < N; i++)
615
+ cl_assert_equal_i(reftable_stack_add(st,
616
+ write_test_ref, &refs[i]), 0);
617
618
for (i = 0; i < N; i++) {
619
struct write_log_arg arg = {
@@ -649,8 +621,8 @@ static void t_reftable_stack_iterator(void)
621
.update_index = reftable_stack_next_update_index(st),
622
};
623
652
- err = reftable_stack_add(st, write_test_log, &arg);
653
- check(!err);
624
+ cl_assert_equal_i(reftable_stack_add(st,
625
+ write_test_log, &arg), 0);
626
}
627
628
reftable_stack_init_ref_iterator(st, &it);
@@ -661,16 +633,16 @@ static void t_reftable_stack_iterator(void)
633
err = reftable_iterator_next_ref(&it, &ref);
634
if (err > 0)
635
break;
664
- check(!err);
665
- check(reftable_ref_record_equal(&ref, &refs[i], REFTABLE_HASH_SIZE_SHA1));
636
+ cl_assert(!err);
637
+ cl_assert(reftable_ref_record_equal(&ref, &refs[i],
638
+ REFTABLE_HASH_SIZE_SHA1) != 0);
639
reftable_ref_record_release(&ref);
640
}
668
- check_int(i, ==, N);
641
+ cl_assert_equal_i(i, N);
642
643
reftable_iterator_destroy(&it);
644
672
- err = reftable_stack_init_log_iterator(st, &it);
673
- check(!err);
645
+ cl_assert_equal_i(reftable_stack_init_log_iterator(st, &it), 0);
646
647
reftable_iterator_seek_log(&it, logs[0].refname);
648
for (i = 0; ; i++) {
@@ -679,11 +651,12 @@ static void t_reftable_stack_iterator(void)
651
err = reftable_iterator_next_log(&it, &log);
652
if (err > 0)
653
break;
682
- check(!err);
683
- check(reftable_log_record_equal(&log, &logs[i], REFTABLE_HASH_SIZE_SHA1));
654
+ cl_assert(!err);
655
+ cl_assert(reftable_log_record_equal(&log, &logs[i],
656
+ REFTABLE_HASH_SIZE_SHA1) != 0);
657
reftable_log_record_release(&log);
658
}
686
- check_int(i, ==, N);
659
+ cl_assert_equal_i(i, N);
660
661
reftable_stack_destroy(st);
662
reftable_iterator_destroy(&it);
@@ -694,9 +667,8 @@ static void t_reftable_stack_iterator(void)
667
clear_dir(dir);
668
}
669
697
-static void t_reftable_stack_log_normalize(void)
670
+void test_reftable_stack__log_normalize(void)
671
{
699
- int err = 0;
672
struct reftable_write_options opts = {
673
0,
674
};
@@ -721,28 +693,26 @@ static void t_reftable_stack_log_normalize(void)
693
.update_index = 1,
694
};
695
724
- err = reftable_new_stack(&st, dir, &opts);
725
- check(!err);
696
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
697
698
input.value.update.message = (char *) "one\ntwo";
728
- err = reftable_stack_add(st, write_test_log, &arg);
729
- check_int(err, ==, REFTABLE_API_ERROR);
699
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
700
+ &arg), REFTABLE_API_ERROR);
701
702
input.value.update.message = (char *) "one";
732
- err = reftable_stack_add(st, write_test_log, &arg);
733
- check(!err);
734
-
735
- err = reftable_stack_read_log(st, input.refname, &dest);
736
- check(!err);
737
- check_str(dest.value.update.message, "one\n");
703
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
704
+ &arg), 0);
705
+ cl_assert_equal_i(reftable_stack_read_log(st, input.refname,
706
+ &dest), 0);
707
+ cl_assert_equal_s(dest.value.update.message, "one\n");
708
709
input.value.update.message = (char *) "two\n";
710
arg.update_index = 2;
741
- err = reftable_stack_add(st, write_test_log, &arg);
742
- check(!err);
743
- err = reftable_stack_read_log(st, input.refname, &dest);
744
- check(!err);
745
- check_str(dest.value.update.message, "two\n");
711
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
712
+ &arg), 0);
713
+ cl_assert_equal_i(reftable_stack_read_log(st, input.refname,
714
+ &dest), 0);
715
+ cl_assert_equal_s(dest.value.update.message, "two\n");
716
717
/* cleanup */
718
reftable_stack_destroy(st);
@@ -750,20 +720,18 @@ static void t_reftable_stack_log_normalize(void)
720
clear_dir(dir);
721
}
722
753
-static void t_reftable_stack_tombstone(void)
723
+void test_reftable_stack__tombstone(void)
724
{
725
char *dir = get_tmp_dir(__LINE__);
726
struct reftable_write_options opts = { 0 };
727
struct reftable_stack *st = NULL;
758
- int err;
728
struct reftable_ref_record refs[2] = { 0 };
729
struct reftable_log_record logs[2] = { 0 };
730
size_t i, N = ARRAY_SIZE(refs);
731
struct reftable_ref_record dest = { 0 };
732
struct reftable_log_record log_dest = { 0 };
733
765
- err = reftable_new_stack(&st, dir, &opts);
766
- check(!err);
734
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
735
736
/* even entries add the refs, odd entries delete them. */
737
for (i = 0; i < N; i++) {
@@ -772,8 +740,8 @@ static void t_reftable_stack_tombstone(void)
740
refs[i].update_index = i + 1;
741
if (i % 2 == 0) {
742
refs[i].value_type = REFTABLE_REF_VAL1;
775
- t_reftable_set_hash(refs[i].value.val1, i,
776
- REFTABLE_HASH_SHA1);
743
+ cl_reftable_set_hash(refs[i].value.val1, i,
744
+ REFTABLE_HASH_SHA1);
745
}
746
747
logs[i].refname = xstrdup(buf);
@@ -785,42 +753,36 @@ static void t_reftable_stack_tombstone(void)
753
logs[i].update_index = 1;
754
if (i % 2 == 0) {
755
logs[i].value_type = REFTABLE_LOG_UPDATE;
788
- t_reftable_set_hash(logs[i].value.update.new_hash, i,
789
- REFTABLE_HASH_SHA1);
756
+ cl_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1);
757
logs[i].value.update.email =
758
xstrdup("identity@invalid");
759
}
760
}
794
- for (i = 0; i < N; i++) {
795
- int err = reftable_stack_add(st, write_test_ref, &refs[i]);
796
- check(!err);
797
- }
761
+ for (i = 0; i < N; i++)
762
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref, &refs[i]), 0);
763
764
for (i = 0; i < N; i++) {
765
struct write_log_arg arg = {
766
.log = &logs[i],
767
.update_index = reftable_stack_next_update_index(st),
768
};
804
- int err = reftable_stack_add(st, write_test_log, &arg);
805
- check(!err);
769
+ cl_assert_equal_i(reftable_stack_add(st,
770
+ write_test_log, &arg), 0);
771
}
772
808
- err = reftable_stack_read_ref(st, "branch", &dest);
809
- check_int(err, ==, 1);
773
+ cl_assert_equal_i(reftable_stack_read_ref(st, "branch",
774
+ &dest), 1);
775
reftable_ref_record_release(&dest);
776
812
- err = reftable_stack_read_log(st, "branch", &log_dest);
813
- check_int(err, ==, 1);
777
+ cl_assert_equal_i(reftable_stack_read_log(st, "branch",
778
+ &log_dest), 1);
779
reftable_log_record_release(&log_dest);
780
816
- err = reftable_stack_compact_all(st, NULL);
817
- check(!err);
818
-
819
- err = reftable_stack_read_ref(st, "branch", &dest);
820
- check_int(err, ==, 1);
821
-
822
- err = reftable_stack_read_log(st, "branch", &log_dest);
823
- check_int(err, ==, 1);
781
+ cl_assert_equal_i(reftable_stack_compact_all(st, NULL), 0);
782
+ cl_assert_equal_i(reftable_stack_read_ref(st, "branch",
783
+ &dest), 1);
784
+ cl_assert_equal_i(reftable_stack_read_log(st, "branch",
785
+ &log_dest), 1);
786
reftable_ref_record_release(&dest);
787
reftable_log_record_release(&log_dest);
788
@@ -833,12 +795,11 @@ static void t_reftable_stack_tombstone(void)
795
clear_dir(dir);
796
}
797
836
-static void t_reftable_stack_hash_id(void)
798
+void test_reftable_stack__hash_id(void)
799
{
800
char *dir = get_tmp_dir(__LINE__);
801
struct reftable_write_options opts = { 0 };
802
struct reftable_stack *st = NULL;
841
- int err;
803
804
struct reftable_ref_record ref = {
805
.refname = (char *) "master",
@@ -852,62 +813,57 @@ static void t_reftable_stack_hash_id(void)
813
struct reftable_stack *st_default = NULL;
814
struct reftable_ref_record dest = { 0 };
815
855
- err = reftable_new_stack(&st, dir, &opts);
856
- check(!err);
857
-
858
- err = reftable_stack_add(st, write_test_ref, &ref);
859
- check(!err);
816
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
817
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
818
+ &ref), 0);
819
820
/* can't read it with the wrong hash ID. */
862
- err = reftable_new_stack(&st32, dir, &opts32);
863
- check_int(err, ==, REFTABLE_FORMAT_ERROR);
821
+ cl_assert_equal_i(reftable_new_stack(&st32, dir,
822
+ &opts32), REFTABLE_FORMAT_ERROR);
823
824
/* check that we can read it back with default opts too. */
866
- err = reftable_new_stack(&st_default, dir, &opts_default);
867
- check(!err);
868
-
869
- err = reftable_stack_read_ref(st_default, "master", &dest);
870
- check(!err);
871
-
872
- check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
825
+ cl_assert_equal_i(reftable_new_stack(&st_default, dir,
826
+ &opts_default), 0);
827
+ cl_assert_equal_i(reftable_stack_read_ref(st_default, "master",
828
+ &dest), 0);
829
+ cl_assert(reftable_ref_record_equal(&ref, &dest,
830
+ REFTABLE_HASH_SIZE_SHA1) != 0);
831
reftable_ref_record_release(&dest);
832
reftable_stack_destroy(st);
833
reftable_stack_destroy(st_default);
834
clear_dir(dir);
835
}
836
879
-static void t_suggest_compaction_segment(void)
837
+void test_reftable_stack__suggest_compaction_segment(void)
838
{
839
uint64_t sizes[] = { 512, 64, 17, 16, 9, 9, 9, 16, 2, 16 };
840
struct segment min =
841
suggest_compaction_segment(sizes, ARRAY_SIZE(sizes), 2);
884
- check_int(min.start, ==, 1);
885
- check_int(min.end, ==, 10);
842
+ cl_assert_equal_i(min.start, 1);
843
+ cl_assert_equal_i(min.end, 10);
844
}
845
888
-static void t_suggest_compaction_segment_nothing(void)
846
+void test_reftable_stack__suggest_compaction_segment_nothing(void)
847
{
848
uint64_t sizes[] = { 64, 32, 16, 8, 4, 2 };
849
struct segment result =
850
suggest_compaction_segment(sizes, ARRAY_SIZE(sizes), 2);
893
- check_int(result.start, ==, result.end);
851
+ cl_assert_equal_i(result.start, result.end);
852
}
853
896
-static void t_reflog_expire(void)
854
+void test_reftable_stack__reflog_expire(void)
855
{
856
char *dir = get_tmp_dir(__LINE__);
857
struct reftable_write_options opts = { 0 };
858
struct reftable_stack *st = NULL;
859
struct reftable_log_record logs[20] = { 0 };
860
size_t i, N = ARRAY_SIZE(logs) - 1;
903
- int err;
861
struct reftable_log_expiry_config expiry = {
862
.time = 10,
863
};
864
struct reftable_log_record log = { 0 };
865
909
- err = reftable_new_stack(&st, dir, &opts);
910
- check(!err);
866
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
867
868
for (i = 1; i <= N; i++) {
869
char buf[256];
@@ -918,8 +874,8 @@ static void t_reflog_expire(void)
874
logs[i].value_type = REFTABLE_LOG_UPDATE;
875
logs[i].value.update.time = i;
876
logs[i].value.update.email = xstrdup("identity@invalid");
921
- t_reftable_set_hash(logs[i].value.update.new_hash, i,
922
- REFTABLE_HASH_SHA1);
877
+ cl_reftable_set_hash(logs[i].value.update.new_hash, i,
878
+ REFTABLE_HASH_SHA1);
879
}
880
881
for (i = 1; i <= N; i++) {
@@ -927,31 +883,23 @@ static void t_reflog_expire(void)
883
.log = &logs[i],
884
.update_index = reftable_stack_next_update_index(st),
885
};
930
- int err = reftable_stack_add(st, write_test_log, &arg);
931
- check(!err);
886
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
887
+ &arg), 0);
888
}
889
934
- err = reftable_stack_compact_all(st, NULL);
935
- check(!err);
936
-
937
- err = reftable_stack_compact_all(st, &expiry);
938
- check(!err);
939
-
940
- err = reftable_stack_read_log(st, logs[9].refname, &log);
941
- check_int(err, ==, 1);
942
-
943
- err = reftable_stack_read_log(st, logs[11].refname, &log);
944
- check(!err);
890
+ cl_assert_equal_i(reftable_stack_compact_all(st, NULL), 0);
891
+ cl_assert_equal_i(reftable_stack_compact_all(st, &expiry), 0);
892
+ cl_assert_equal_i(reftable_stack_read_log(st, logs[9].refname,
893
+ &log), 1);
894
+ cl_assert_equal_i(reftable_stack_read_log(st, logs[11].refname,
895
+ &log), 0);
896
897
expiry.min_update_index = 15;
947
- err = reftable_stack_compact_all(st, &expiry);
948
- check(!err);
949
-
950
- err = reftable_stack_read_log(st, logs[14].refname, &log);
951
- check_int(err, ==, 1);
952
-
953
- err = reftable_stack_read_log(st, logs[16].refname, &log);
954
- check(!err);
898
+ cl_assert_equal_i(reftable_stack_compact_all(st, &expiry), 0);
899
+ cl_assert_equal_i(reftable_stack_read_log(st, logs[14].refname,
900
+ &log), 1);
901
+ cl_assert_equal_i(reftable_stack_read_log(st, logs[16].refname,
902
+ &log), 0);
903
904
/* cleanup */
905
reftable_stack_destroy(st);
@@ -963,26 +911,21 @@ static void t_reflog_expire(void)
911
912
static int write_nothing(struct reftable_writer *wr, void *arg UNUSED)
913
{
966
- check(!reftable_writer_set_limits(wr, 1, 1));
914
+ cl_assert_equal_i(reftable_writer_set_limits(wr, 1, 1), 0);
915
return 0;
916
}
917
970
-static void t_empty_add(void)
918
+void test_reftable_stack__empty_add(void)
919
{
920
struct reftable_write_options opts = { 0 };
921
struct reftable_stack *st = NULL;
974
- int err;
922
char *dir = get_tmp_dir(__LINE__);
923
struct reftable_stack *st2 = NULL;
924
978
- err = reftable_new_stack(&st, dir, &opts);
979
- check(!err);
980
-
981
- err = reftable_stack_add(st, write_nothing, NULL);
982
- check(!err);
983
-
984
- err = reftable_new_stack(&st2, dir, &opts);
985
- check(!err);
925
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
926
+ cl_assert_equal_i(reftable_stack_add(st, write_nothing,
927
+ NULL), 0);
928
+ cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
929
clear_dir(dir);
930
reftable_stack_destroy(st);
931
reftable_stack_destroy(st2);
@@ -998,18 +941,17 @@ static int fastlogN(uint64_t sz, uint64_t N)
941
return l - 1;
942
}
943
1001
-static void t_reftable_stack_auto_compaction(void)
944
+void test_reftable_stack__auto_compaction(void)
945
{
946
struct reftable_write_options opts = {
947
.disable_auto_compact = 1,
948
};
949
struct reftable_stack *st = NULL;
950
char *dir = get_tmp_dir(__LINE__);
1008
- int err;
951
size_t i, N = 100;
952
+ int err;
953
1011
- err = reftable_new_stack(&st, dir, &opts);
1012
- check(!err);
954
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
955
956
for (i = 0; i < N; i++) {
957
char name[100];
@@ -1022,32 +964,31 @@ static void t_reftable_stack_auto_compaction(void)
964
snprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i);
965
966
err = reftable_stack_add(st, write_test_ref, &ref);
1025
- check(!err);
967
+ cl_assert(!err);
968
969
err = reftable_stack_auto_compact(st);
1028
- check(!err);
1029
- check(i < 2 || st->merged->tables_len < 2 * fastlogN(i, 2));
970
+ cl_assert(!err);
971
+ cl_assert(i < 2 || st->merged->tables_len < 2 * fastlogN(i, 2));
972
}
973
1032
- check_int(reftable_stack_compaction_stats(st)->entries_written, <,
1033
- (uint64_t)(N * fastlogN(N, 2)));
974
+ cl_assert(reftable_stack_compaction_stats(st)->entries_written <
975
+ (uint64_t)(N * fastlogN(N, 2)));
976
977
reftable_stack_destroy(st);
978
clear_dir(dir);
979
}
980
1039
-static void t_reftable_stack_auto_compaction_factor(void)
981
+void test_reftable_stack__auto_compaction_factor(void)
982
{
983
struct reftable_write_options opts = {
984
.auto_compaction_factor = 5,
985
};
986
struct reftable_stack *st = NULL;
987
char *dir = get_tmp_dir(__LINE__);
1046
- int err;
988
size_t N = 100;
989
+ int err;
990
1049
- err = reftable_new_stack(&st, dir, &opts);
1050
- check(!err);
991
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
992
993
for (size_t i = 0; i < N; i++) {
994
char name[20];
@@ -1059,16 +1000,16 @@ static void t_reftable_stack_auto_compaction_factor(void)
1000
xsnprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i);
1001
1002
err = reftable_stack_add(st, &write_test_ref, &ref);
1062
- check(!err);
1003
+ cl_assert(!err);
1004
1064
- check(i < 5 || st->merged->tables_len < 5 * fastlogN(i, 5));
1005
+ cl_assert(i < 5 || st->merged->tables_len < 5 * fastlogN(i, 5));
1006
}
1007
1008
reftable_stack_destroy(st);
1009
clear_dir(dir);
1010
}
1011
1071
-static void t_reftable_stack_auto_compaction_with_locked_tables(void)
1012
+void test_reftable_stack__auto_compaction_with_locked_tables(void)
1013
{
1014
struct reftable_write_options opts = {
1015
.disable_auto_compact = 1,
@@ -1078,21 +1019,20 @@ static void t_reftable_stack_auto_compaction_with_locked_tables(void)
1019
char *dir = get_tmp_dir(__LINE__);
1020
int err;
1021
1081
- err = reftable_new_stack(&st, dir, &opts);
1082
- check(!err);
1022
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
1023
1024
write_n_ref_tables(st, 5);
1085
- check_int(st->merged->tables_len, ==, 5);
1025
+ cl_assert_equal_i(st->merged->tables_len, 5);
1026
1027
/*
1028
* Given that all tables we have written should be roughly the same
1029
* size, we expect that auto-compaction will want to compact all of the
1030
* tables. Locking any of the tables will keep it from doing so.
1031
*/
1092
- check(!reftable_buf_addstr(&buf, dir));
1093
- check(!reftable_buf_addstr(&buf, "/"));
1094
- check(!reftable_buf_addstr(&buf, st->tables[2]->name));
1095
- check(!reftable_buf_addstr(&buf, ".lock"));
1032
+ cl_assert(!reftable_buf_addstr(&buf, dir));
1033
+ cl_assert(!reftable_buf_addstr(&buf, "/"));
1034
+ cl_assert(!reftable_buf_addstr(&buf, st->tables[2]->name));
1035
+ cl_assert(!reftable_buf_addstr(&buf, ".lock"));
1036
write_file_buf(buf.buf, "", 0);
1037
1038
/*
@@ -1102,25 +1042,23 @@ static void t_reftable_stack_auto_compaction_with_locked_tables(void)
1042
* only compact the newest two tables.
1043
*/
1044
err = reftable_stack_auto_compact(st);
1105
- check(!err);
1106
- check_int(st->stats.failures, ==, 0);
1107
- check_int(st->merged->tables_len, ==, 4);
1045
+ cl_assert(!err);
1046
+ cl_assert_equal_i(st->stats.failures, 0);
1047
+ cl_assert_equal_i(st->merged->tables_len, 4);
1048
1049
reftable_stack_destroy(st);
1050
reftable_buf_release(&buf);
1051
clear_dir(dir);
1052
}
1053
1114
-static void t_reftable_stack_add_performs_auto_compaction(void)
1054
+void test_reftable_stack__add_performs_auto_compaction(void)
1055
{
1056
struct reftable_write_options opts = { 0 };
1057
struct reftable_stack *st = NULL;
1058
char *dir = get_tmp_dir(__LINE__);
1119
- int err;
1059
size_t i, n = 20;
1060
1122
- err = reftable_new_stack(&st, dir, &opts);
1123
- check(!err);
1061
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
1062
1063
for (i = 0; i <= n; i++) {
1064
struct reftable_ref_record ref = {
@@ -1140,8 +1078,8 @@ static void t_reftable_stack_add_performs_auto_compaction(void)
1078
snprintf(buf, sizeof(buf), "branch-%04"PRIuMAX, (uintmax_t)i);
1079
ref.refname = buf;
1080
1143
- err = reftable_stack_add(st, write_test_ref, &ref);
1144
- check(!err);
1081
+ cl_assert_equal_i(reftable_stack_add(st,
1082
+ write_test_ref, &ref), 0);
1083
1084
/*
1085
* The stack length should grow continuously for all runs where
@@ -1149,16 +1087,16 @@ static void t_reftable_stack_add_performs_auto_compaction(void)
1087
* all tables in the stack.
1088
*/
1089
if (i != n)
1152
- check_int(st->merged->tables_len, ==, i + 1);
1090
+ cl_assert_equal_i(st->merged->tables_len, i + 1);
1091
else
1154
- check_int(st->merged->tables_len, ==, 1);
1092
+ cl_assert_equal_i(st->merged->tables_len, 1);
1093
}
1094
1095
reftable_stack_destroy(st);
1096
clear_dir(dir);
1097
}
1098
1161
-static void t_reftable_stack_compaction_with_locked_tables(void)
1099
+void test_reftable_stack__compaction_with_locked_tables(void)
1100
{
1101
struct reftable_write_options opts = {
1102
.disable_auto_compact = 1,
@@ -1168,17 +1106,16 @@ static void t_reftable_stack_compaction_with_locked_tables(void)
1106
char *dir = get_tmp_dir(__LINE__);
1107
int err;
1108
1171
- err = reftable_new_stack(&st, dir, &opts);
1172
- check(!err);
1109
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
1110
1111
write_n_ref_tables(st, 3);
1175
- check_int(st->merged->tables_len, ==, 3);
1112
+ cl_assert_equal_i(st->merged->tables_len, 3);
1113
1114
/* Lock one of the tables that we're about to compact. */
1178
- check(!reftable_buf_addstr(&buf, dir));
1179
- check(!reftable_buf_addstr(&buf, "/"));
1180
- check(!reftable_buf_addstr(&buf, st->tables[1]->name));
1181
- check(!reftable_buf_addstr(&buf, ".lock"));
1115
+ cl_assert(!reftable_buf_addstr(&buf, dir));
1116
+ cl_assert(!reftable_buf_addstr(&buf, "/"));
1117
+ cl_assert(!reftable_buf_addstr(&buf, st->tables[1]->name));
1118
+ cl_assert(!reftable_buf_addstr(&buf, ".lock"));
1119
write_file_buf(buf.buf, "", 0);
1120
1121
/*
@@ -1186,36 +1123,31 @@ static void t_reftable_stack_compaction_with_locked_tables(void)
1123
* compact all tables.
1124
*/
1125
err = reftable_stack_compact_all(st, NULL);
1189
- check_int(err, ==, REFTABLE_LOCK_ERROR);
1190
- check_int(st->stats.failures, ==, 1);
1191
- check_int(st->merged->tables_len, ==, 3);
1126
+ cl_assert_equal_i(err, REFTABLE_LOCK_ERROR);
1127
+ cl_assert_equal_i(st->stats.failures, 1);
1128
+ cl_assert_equal_i(st->merged->tables_len, 3);
1129
1130
reftable_stack_destroy(st);
1131
reftable_buf_release(&buf);
1132
clear_dir(dir);
1133
}
1134
1198
-static void t_reftable_stack_compaction_concurrent(void)
1135
+void test_reftable_stack__compaction_concurrent(void)
1136
{
1137
struct reftable_write_options opts = { 0 };
1138
struct reftable_stack *st1 = NULL, *st2 = NULL;
1139
char *dir = get_tmp_dir(__LINE__);
1203
- int err;
1140
1205
- err = reftable_new_stack(&st1, dir, &opts);
1206
- check(!err);
1141
+ cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
1142
write_n_ref_tables(st1, 3);
1143
1209
- err = reftable_new_stack(&st2, dir, &opts);
1210
- check(!err);
1211
-
1212
- err = reftable_stack_compact_all(st1, NULL);
1213
- check(!err);
1144
+ cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
1145
+ cl_assert_equal_i(reftable_stack_compact_all(st1, NULL), 0);
1146
1147
reftable_stack_destroy(st1);
1148
reftable_stack_destroy(st2);
1149
1218
- check_int(count_dir_entries(dir), ==, 2);
1150
+ cl_assert_equal_i(count_dir_entries(dir), 2);
1151
clear_dir(dir);
1152
}
1153
@@ -1228,32 +1160,24 @@ static void unclean_stack_close(struct reftable_stack *st)
1160
REFTABLE_FREE_AND_NULL(st->tables);
1161
}
1162
1231
-static void t_reftable_stack_compaction_concurrent_clean(void)
1163
+void test_reftable_stack__compaction_concurrent_clean(void)
1164
{
1165
struct reftable_write_options opts = { 0 };
1166
struct reftable_stack *st1 = NULL, *st2 = NULL, *st3 = NULL;
1167
char *dir = get_tmp_dir(__LINE__);
1236
- int err;
1168
1238
- err = reftable_new_stack(&st1, dir, &opts);
1239
- check(!err);
1169
+ cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
1170
write_n_ref_tables(st1, 3);
1171
1242
- err = reftable_new_stack(&st2, dir, &opts);
1243
- check(!err);
1244
-
1245
- err = reftable_stack_compact_all(st1, NULL);
1246
- check(!err);
1172
+ cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
1173
+ cl_assert_equal_i(reftable_stack_compact_all(st1, NULL), 0);
1174
1175
unclean_stack_close(st1);
1176
unclean_stack_close(st2);
1177
1251
- err = reftable_new_stack(&st3, dir, &opts);
1252
- check(!err);
1253
-
1254
- err = reftable_stack_clean(st3);
1255
- check(!err);
1256
- check_int(count_dir_entries(dir), ==, 2);
1178
+ cl_assert_equal_i(reftable_new_stack(&st3, dir, &opts), 0);
1179
+ cl_assert_equal_i(reftable_stack_clean(st3), 0);
1180
+ cl_assert_equal_i(count_dir_entries(dir), 2);
1181
1182
reftable_stack_destroy(st1);
1183
reftable_stack_destroy(st2);
@@ -1262,7 +1186,7 @@ static void t_reftable_stack_compaction_concurrent_clean(void)
1186
clear_dir(dir);
1187
}
1188
1265
-static void t_reftable_stack_read_across_reload(void)
1189
+void test_reftable_stack__read_across_reload(void)
1190
{
1191
struct reftable_write_options opts = { 0 };
1192
struct reftable_stack *st1 = NULL, *st2 = NULL;
@@ -1272,37 +1196,35 @@ static void t_reftable_stack_read_across_reload(void)
1196
int err;
1197
1198
/* Create a first stack and set up an iterator for it. */
1275
- err = reftable_new_stack(&st1, dir, &opts);
1276
- check(!err);
1199
+ cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
1200
write_n_ref_tables(st1, 2);
1278
- check_int(st1->merged->tables_len, ==, 2);
1201
+ cl_assert_equal_i(st1->merged->tables_len, 2);
1202
reftable_stack_init_ref_iterator(st1, &it);
1280
- err = reftable_iterator_seek_ref(&it, "");
1281
- check(!err);
1203
+ cl_assert_equal_i(reftable_iterator_seek_ref(&it, ""), 0);
1204
1205
/* Set up a second stack for the same directory and compact it. */
1206
err = reftable_new_stack(&st2, dir, &opts);
1285
- check(!err);
1286
- check_int(st2->merged->tables_len, ==, 2);
1207
+ cl_assert(!err);
1208
+ cl_assert_equal_i(st2->merged->tables_len, 2);
1209
err = reftable_stack_compact_all(st2, NULL);
1288
- check(!err);
1289
- check_int(st2->merged->tables_len, ==, 1);
1210
+ cl_assert(!err);
1211
+ cl_assert_equal_i(st2->merged->tables_len, 1);
1212
1213
/*
1214
* Verify that we can continue to use the old iterator even after we
1215
* have reloaded its stack.
1216
*/
1217
err = reftable_stack_reload(st1);
1296
- check(!err);
1297
- check_int(st1->merged->tables_len, ==, 1);
1218
+ cl_assert(!err);
1219
+ cl_assert_equal_i(st1->merged->tables_len, 1);
1220
err = reftable_iterator_next_ref(&it, &rec);
1299
- check(!err);
1300
- check_str(rec.refname, "refs/heads/branch-0000");
1221
+ cl_assert(!err);
1222
+ cl_assert_equal_s(rec.refname, "refs/heads/branch-0000");
1223
err = reftable_iterator_next_ref(&it, &rec);
1302
- check(!err);
1303
- check_str(rec.refname, "refs/heads/branch-0001");
1224
+ cl_assert(!err);
1225
+ cl_assert_equal_s(rec.refname, "refs/heads/branch-0001");
1226
err = reftable_iterator_next_ref(&it, &rec);
1305
- check_int(err, >, 0);
1227
+ cl_assert(err > 0);
1228
1229
reftable_ref_record_release(&rec);
1230
reftable_iterator_destroy(&it);
@@ -1311,7 +1233,7 @@ static void t_reftable_stack_read_across_reload(void)
1233
clear_dir(dir);
1234
}
1235
1314
-static void t_reftable_stack_reload_with_missing_table(void)
1236
+void test_reftable_stack__reload_with_missing_table(void)
1237
{
1238
struct reftable_write_options opts = { 0 };
1239
struct reftable_stack *st = NULL;
@@ -1322,46 +1244,40 @@ static void t_reftable_stack_reload_with_missing_table(void)
1244
int err;
1245
1246
/* Create a first stack and set up an iterator for it. */
1325
- err = reftable_new_stack(&st, dir, &opts);
1326
- check(!err);
1247
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
1248
write_n_ref_tables(st, 2);
1328
- check_int(st->merged->tables_len, ==, 2);
1249
+ cl_assert_equal_i(st->merged->tables_len, 2);
1250
reftable_stack_init_ref_iterator(st, &it);
1330
- err = reftable_iterator_seek_ref(&it, "");
1331
- check(!err);
1251
+ cl_assert_equal_i(reftable_iterator_seek_ref(&it, ""), 0);
1252
1253
/*
1254
* Update the tables.list file with some garbage data, while reusing
1255
* our old tables. This should trigger a partial reload of the stack,
1256
* where we try to reuse our old tables.
1257
*/
1338
- check(!reftable_buf_addstr(&content, st->tables[0]->name));
1339
- check(!reftable_buf_addstr(&content, "\n"));
1340
- check(!reftable_buf_addstr(&content, st->tables[1]->name));
1341
- check(!reftable_buf_addstr(&content, "\n"));
1342
- check(!reftable_buf_addstr(&content, "garbage\n"));
1343
- check(!reftable_buf_addstr(&table_path, st->list_file));
1344
- check(!reftable_buf_addstr(&table_path, ".lock"));
1258
+ cl_assert(!reftable_buf_addstr(&content, st->tables[0]->name));
1259
+ cl_assert(!reftable_buf_addstr(&content, "\n"));
1260
+ cl_assert(!reftable_buf_addstr(&content, st->tables[1]->name));
1261
+ cl_assert(!reftable_buf_addstr(&content, "\n"));
1262
+ cl_assert(!reftable_buf_addstr(&content, "garbage\n"));
1263
+ cl_assert(!reftable_buf_addstr(&table_path, st->list_file));
1264
+ cl_assert(!reftable_buf_addstr(&table_path, ".lock"));
1265
write_file_buf(table_path.buf, content.buf, content.len);
1346
- err = rename(table_path.buf, st->list_file);
1347
- check(!err);
1266
+ cl_assert_equal_i(rename(table_path.buf, st->list_file), 0);
1267
1268
err = reftable_stack_reload(st);
1350
- check_int(err, ==, -4);
1351
- check_int(st->merged->tables_len, ==, 2);
1269
+ cl_assert_equal_i(err, -4);
1270
+ cl_assert_equal_i(st->merged->tables_len, 2);
1271
1272
/*
1273
* Even though the reload has failed, we should be able to continue
1274
* using the iterator.
1275
*/
1357
- err = reftable_iterator_next_ref(&it, &rec);
1358
- check(!err);
1359
- check_str(rec.refname, "refs/heads/branch-0000");
1360
- err = reftable_iterator_next_ref(&it, &rec);
1361
- check(!err);
1362
- check_str(rec.refname, "refs/heads/branch-0001");
1363
- err = reftable_iterator_next_ref(&it, &rec);
1364
- check_int(err, >, 0);
1276
+ cl_assert_equal_i(reftable_iterator_next_ref(&it, &rec), 0);
1277
+ cl_assert_equal_s(rec.refname, "refs/heads/branch-0000");
1278
+ cl_assert_equal_i(reftable_iterator_next_ref(&it, &rec), 0);
1279
+ cl_assert_equal_s(rec.refname, "refs/heads/branch-0001");
1280
+ cl_assert(reftable_iterator_next_ref(&it, &rec) > 0);
1281
1282
reftable_ref_record_release(&rec);
1283
reftable_iterator_destroy(&it);
@@ -1374,12 +1290,13 @@ static void t_reftable_stack_reload_with_missing_table(void)
1290
static int write_limits_after_ref(struct reftable_writer *wr, void *arg)
1291
{
1292
struct reftable_ref_record *ref = arg;
1377
- check(!reftable_writer_set_limits(wr, ref->update_index, ref->update_index));
1378
- check(!reftable_writer_add_ref(wr, ref));
1293
+ cl_assert_equal_i(reftable_writer_set_limits(wr,
1294
+ ref->update_index, ref->update_index), 0);
1295
+ cl_assert_equal_i(reftable_writer_add_ref(wr, ref), 0);
1296
return reftable_writer_set_limits(wr, ref->update_index, ref->update_index);
1297
}
1298
1382
-static void t_reftable_invalid_limit_updates(void)
1299
+void test_reftable_stack__invalid_limit_updates(void)
1300
{
1301
struct reftable_ref_record ref = {
1302
.refname = (char *) "HEAD",
@@ -1393,59 +1310,22 @@ static void t_reftable_invalid_limit_updates(void)
1310
struct reftable_addition *add = NULL;
1311
char *dir = get_tmp_dir(__LINE__);
1312
struct reftable_stack *st = NULL;
1396
- int err;
1313
1398
- err = reftable_new_stack(&st, dir, &opts);
1399
- check(!err);
1314
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
1315
1316
reftable_addition_destroy(add);
1317
1403
- err = reftable_stack_new_addition(&add, st, 0);
1404
- check(!err);
1318
+ cl_assert_equal_i(reftable_stack_new_addition(&add, st, 0), 0);
1319
1320
/*
1321
* write_limits_after_ref also updates the update indexes after adding
1322
* the record. This should cause an err to be returned, since the limits
1323
* must be set at the start.
1324
*/
1411
- err = reftable_addition_add(add, write_limits_after_ref, &ref);
1412
- check_int(err, ==, REFTABLE_API_ERROR);
1325
+ cl_assert_equal_i(reftable_addition_add(add,
1326
+ write_limits_after_ref, &ref), REFTABLE_API_ERROR);
1327
1328
reftable_addition_destroy(add);
1329
reftable_stack_destroy(st);
1330
clear_dir(dir);
1331
}
1418
-
1419
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
1420
-{
1421
- TEST(t_empty_add(), "empty addition to stack");
1422
- TEST(t_read_file(), "read_lines works");
1423
- TEST(t_reflog_expire(), "expire reflog entries");
1424
- TEST(t_reftable_invalid_limit_updates(), "prevent limit updates after adding records");
1425
- TEST(t_reftable_stack_add(), "add multiple refs and logs to stack");
1426
- TEST(t_reftable_stack_add_one(), "add a single ref record to stack");
1427
- TEST(t_reftable_stack_add_performs_auto_compaction(), "addition to stack triggers auto-compaction");
1428
- TEST(t_reftable_stack_auto_compaction(), "stack must form geometric sequence after compaction");
1429
- TEST(t_reftable_stack_auto_compaction_factor(), "auto-compaction with non-default geometric factor");
1430
- TEST(t_reftable_stack_auto_compaction_fails_gracefully(), "failure on auto-compaction");
1431
- TEST(t_reftable_stack_auto_compaction_with_locked_tables(), "auto compaction with locked tables");
1432
- TEST(t_reftable_stack_compaction_concurrent(), "compaction with concurrent stack");
1433
- TEST(t_reftable_stack_compaction_concurrent_clean(), "compaction with unclean stack shutdown");
1434
- TEST(t_reftable_stack_compaction_with_locked_tables(), "compaction with locked tables");
1435
- TEST(t_reftable_stack_hash_id(), "read stack with wrong hash ID");
1436
- TEST(t_reftable_stack_iterator(), "log and ref iterator for reftable stack");
1437
- TEST(t_reftable_stack_lock_failure(), "stack addition with lockfile failure");
1438
- TEST(t_reftable_stack_log_normalize(), "log messages should be normalized");
1439
- TEST(t_reftable_stack_read_across_reload(), "stack iterators work across reloads");
1440
- TEST(t_reftable_stack_reload_with_missing_table(), "stack iteration with garbage tables");
1441
- TEST(t_reftable_stack_tombstone(), "'tombstone' refs in stack");
1442
- TEST(t_reftable_stack_transaction_api(), "update transaction to stack");
1443
- TEST(t_reftable_stack_transaction_with_reload(), "transaction with reload");
1444
- TEST(t_reftable_stack_transaction_api_performs_auto_compaction(), "update transaction triggers auto-compaction");
1445
- TEST(t_reftable_stack_update_index_check(), "update transactions with equal update indices");
1446
- TEST(t_reftable_stack_uptodate(), "stack must be reloaded before ref update");
1447
- TEST(t_suggest_compaction_segment(), "suggest_compaction_segment with basic input");
1448
- TEST(t_suggest_compaction_segment_nothing(), "suggest_compaction_segment with pre-compacted input");
1449
-
1450
- return test_done();
1451
-}