t: move reftable/stack_test.c to the unit testing framework

reftable/stack_test.c exercises the functions defined in reftable/stack.{c, h}. Migrate reftable/stack_test.c to the unit testing framework. Migration involves refactoring the tests to use the unit testing framework instead of reftable's test framework and renaming the tests to be in-line with unit-tests' standards. Since some of the tests use set_test_hash() defined by reftable/test_framework.{c, h} but these files are not '#included' in the test file, copy this function in the ported test file. With the migration of stack test to the unit-tests framework, "test-tool reftable" becomes a no-op. Hence, get rid of everything that uses "test-tool reftable" alongside everything that is used to implement it. While at it, alphabetically sort the cmds[] list in helper/test-tool.c by moving the entry for "dump-reftable". Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Chandra Pratap committed Sep 8, 2024 at 09:35 UTC 15e29ea1c648149304b31d662b286718d0e6fde8
9 files changed +217 -354
Makefile
+3 -9
@@ -912,7 +912,6 @@ TEST_SHELL_PATH = $(SHELL_PATH)
912 LIB_FILE = libgit.a
913 XDIFF_LIB = xdiff/lib.a
914 REFTABLE_LIB = reftable/libreftable.a
915 -REFTABLE_TEST_LIB = reftable/libreftable_test.a
915
916 GENERATED_H += command-list.h
917 GENERATED_H += config-list.h
@@ -1349,6 +1348,7 @@ UNIT_TEST_PROGRAMS += t-reftable-merged
1348 UNIT_TEST_PROGRAMS += t-reftable-pq
1349 UNIT_TEST_PROGRAMS += t-reftable-readwrite
1350 UNIT_TEST_PROGRAMS += t-reftable-record
1351 +UNIT_TEST_PROGRAMS += t-reftable-stack
1352 UNIT_TEST_PROGRAMS += t-reftable-tree
1353 UNIT_TEST_PROGRAMS += t-strbuf
1354 UNIT_TEST_PROGRAMS += t-strcmp-offset
@@ -2691,9 +2691,6 @@ REFTABLE_OBJS += reftable/stack.o
2691 REFTABLE_OBJS += reftable/tree.o
2692 REFTABLE_OBJS += reftable/writer.o
2693
2694 -REFTABLE_TEST_OBJS += reftable/stack_test.o
2695 -REFTABLE_TEST_OBJS += reftable/test_framework.o
2696 -
2694 TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
2695
2696 .PHONY: test-objs
@@ -2868,9 +2865,6 @@ $(XDIFF_LIB): $(XDIFF_OBJS)
2865 $(REFTABLE_LIB): $(REFTABLE_OBJS)
2866 $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2867
2871 -$(REFTABLE_TEST_LIB): $(REFTABLE_TEST_OBJS)
2872 - $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2873 -
2868 export DEFAULT_EDITOR DEFAULT_PAGER
2869
2870 Documentation/GIT-EXCLUDED-PROGRAMS: FORCE
@@ -3250,7 +3244,7 @@ perf: all
3244
3245 t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
3246
3253 -t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) $(REFTABLE_TEST_LIB)
3247 +t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
3248 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
3249
3250 check-sha1:: t/helper/test-tool$X
@@ -3711,7 +3705,7 @@ clean: profile-clean coverage-clean cocciclean
3705 $(RM) git.res
3706 $(RM) $(OBJECTS)
3707 $(RM) headless-git.o
3714 - $(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)
3708 + $(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB)
3709 $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS)
3710 $(RM) $(TEST_PROGRAMS)
3711 $(RM) $(FUZZ_PROGRAMS)
reftable/reftable-tests.h deleted
-14
@@ -1,14 +0,0 @@
1 -/*
2 -Copyright 2020 Google LLC
3 -
4 -Use of this source code is governed by a BSD-style
5 -license that can be found in the LICENSE file or at
6 -https://developers.google.com/open-source/licenses/bsd
7 -*/
8 -
9 -#ifndef REFTABLE_TESTS_H
10 -#define REFTABLE_TESTS_H
11 -
12 -int stack_test_main(int argc, const char **argv);
13 -
14 -#endif
reftable/test_framework.c deleted
-27
@@ -1,27 +0,0 @@
1 -/*
2 -Copyright 2020 Google LLC
3 -
4 -Use of this source code is governed by a BSD-style
5 -license that can be found in the LICENSE file or at
6 -https://developers.google.com/open-source/licenses/bsd
7 -*/
8 -
9 -#include "system.h"
10 -#include "test_framework.h"
11 -
12 -
13 -void set_test_hash(uint8_t *p, int i)
14 -{
15 - memset(p, (uint8_t)i, hash_size(GIT_SHA1_FORMAT_ID));
16 -}
17 -
18 -ssize_t strbuf_add_void(void *b, const void *data, size_t sz)
19 -{
20 - strbuf_add(b, data, sz);
21 - return sz;
22 -}
23 -
24 -int noop_flush(void *arg UNUSED)
25 -{
26 - return 0;
27 -}
reftable/test_framework.h deleted
-61
@@ -1,61 +0,0 @@
1 -/*
2 -Copyright 2020 Google LLC
3 -
4 -Use of this source code is governed by a BSD-style
5 -license that can be found in the LICENSE file or at
6 -https://developers.google.com/open-source/licenses/bsd
7 -*/
8 -
9 -#ifndef TEST_FRAMEWORK_H
10 -#define TEST_FRAMEWORK_H
11 -
12 -#include "system.h"
13 -#include "reftable-error.h"
14 -
15 -#define EXPECT_ERR(c) \
16 - do { \
17 - if (c != 0) { \
18 - fflush(stderr); \
19 - fflush(stdout); \
20 - fprintf(stderr, "%s: %d: error == %d (%s), want 0\n", \
21 - __FILE__, __LINE__, c, reftable_error_str(c)); \
22 - abort(); \
23 - } \
24 - } while (0)
25 -
26 -#define EXPECT_STREQ(a, b) \
27 - do { \
28 - if (strcmp(a, b)) { \
29 - fflush(stderr); \
30 - fflush(stdout); \
31 - fprintf(stderr, "%s:%d: %s (%s) != %s (%s)\n", __FILE__, \
32 - __LINE__, #a, a, #b, b); \
33 - abort(); \
34 - } \
35 - } while (0)
36 -
37 -#define EXPECT(c) \
38 - do { \
39 - if (!(c)) { \
40 - fflush(stderr); \
41 - fflush(stdout); \
42 - fprintf(stderr, "%s: %d: failed assertion %s\n", __FILE__, \
43 - __LINE__, #c); \
44 - abort(); \
45 - } \
46 - } while (0)
47 -
48 -#define RUN_TEST(f) \
49 - fprintf(stderr, "running %s\n", #f); \
50 - fflush(stderr); \
51 - f();
52 -
53 -void set_test_hash(uint8_t *p, int i);
54 -
55 -/* Like strbuf_add, but suitable for passing to reftable_new_writer
56 - */
57 -ssize_t strbuf_add_void(void *b, const void *data, size_t sz);
58 -
59 -int noop_flush(void *);
60 -
61 -#endif
t/helper/test-reftable.c
-8
@@ -6,16 +6,8 @@
6 #include "reftable/reftable-merged.h"
7 #include "reftable/reftable-reader.h"
8 #include "reftable/reftable-stack.h"
9 -#include "reftable/reftable-tests.h"
9 #include "test-tool.h"
10
12 -int cmd__reftable(int argc, const char **argv)
13 -{
14 - /* test from simple to complex. */
15 - stack_test_main(argc, argv);
16 - return 0;
17 -}
18 -
11 static void print_help(void)
12 {
13 printf("usage: dump [-st] arg\n\n"
t/helper/test-tool.c
+1 -2
@@ -26,6 +26,7 @@ static struct test_cmd cmds[] = {
26 { "drop-caches", cmd__drop_caches },
27 { "dump-cache-tree", cmd__dump_cache_tree },
28 { "dump-fsmonitor", cmd__dump_fsmonitor },
29 + { "dump-reftable", cmd__dump_reftable },
30 { "dump-split-index", cmd__dump_split_index },
31 { "dump-untracked-cache", cmd__dump_untracked_cache },
32 { "env-helper", cmd__env_helper },
@@ -61,9 +62,7 @@ static struct test_cmd cmds[] = {
62 { "read-graph", cmd__read_graph },
63 { "read-midx", cmd__read_midx },
64 { "ref-store", cmd__ref_store },
64 - { "reftable", cmd__reftable },
65 { "rot13-filter", cmd__rot13_filter },
66 - { "dump-reftable", cmd__dump_reftable },
66 { "regex", cmd__regex },
67 { "repository", cmd__repository },
68 { "revision-walking", cmd__revision_walking },
t/helper/test-tool.h
-1
@@ -55,7 +55,6 @@ int cmd__read_graph(int argc, const char **argv);
55 int cmd__read_midx(int argc, const char **argv);
56 int cmd__ref_store(int argc, const char **argv);
57 int cmd__rot13_filter(int argc, const char **argv);
58 -int cmd__reftable(int argc, const char **argv);
58 int cmd__regex(int argc, const char **argv);
59 int cmd__repository(int argc, const char **argv);
60 int cmd__revision_walking(int argc, const char **argv);
t/t0032-reftable-unittest.sh deleted
-16
@@ -1,16 +0,0 @@
1 -#!/bin/sh
2 -#
3 -# Copyright (c) 2020 Google LLC
4 -#
5 -
6 -test_description='reftable unittests'
7 -
8 -TEST_PASSES_SANITIZE_LEAK=true
9 -. ./test-lib.sh
10 -
11 -test_expect_success 'unittests' '
12 - TMPDIR=$(pwd) && export TMPDIR &&
13 - test-tool reftable
14 -'
15 -
16 -test_done
t/unit-tests/t-reftable-stack.c renamed
+213 -216
@@ -6,22 +6,18 @@ license that can be found in the LICENSE file or at
6 https://developers.google.com/open-source/licenses/bsd
7 */
8
9 -#include "stack.h"
10 -
11 -#include "system.h"
12 -
13 -#include "copy.h"
14 -#include "reftable-reader.h"
15 -#include "merged.h"
16 -#include "basics.h"
17 -#include "record.h"
18 -#include "test_framework.h"
19 -#include "reftable-tests.h"
20 -#include "reader.h"
21 -
22 -#include <sys/types.h>
9 +#include "test-lib.h"
10 +#include "reftable/merged.h"
11 +#include "reftable/reader.h"
12 +#include "reftable/reftable-error.h"
13 +#include "reftable/stack.h"
14 #include <dirent.h>
15
16 +static void set_test_hash(uint8_t *p, int i)
17 +{
18 + memset(p, (uint8_t)i, hash_size(GIT_SHA1_FORMAT_ID));
19 +}
20 +
21 static void clear_dir(const char *dirname)
22 {
23 struct strbuf path = STRBUF_INIT;
@@ -73,11 +69,11 @@ static char *get_tmp_template(int linenumber)
69 static char *get_tmp_dir(int linenumber)
70 {
71 char *dir = get_tmp_template(linenumber);
76 - EXPECT(mkdtemp(dir));
72 + check(mkdtemp(dir) != NULL);
73 return dir;
74 }
75
80 -static void test_read_file(void)
76 +static void t_read_file(void)
77 {
78 char *fn = get_tmp_template(__LINE__);
79 int fd = mkstemp(fn);
@@ -87,17 +83,17 @@ static void test_read_file(void)
83 const char *want[] = { "line1", "line2", "line3" };
84 int i = 0;
85
90 - EXPECT(fd > 0);
86 + check_int(fd, >, 0);
87 n = write_in_full(fd, out, strlen(out));
92 - EXPECT(n == strlen(out));
88 + check_int(n, ==, strlen(out));
89 err = close(fd);
94 - EXPECT(err >= 0);
90 + check_int(err, >=, 0);
91
92 err = read_lines(fn, &names);
97 - EXPECT_ERR(err);
93 + check(!err);
94
95 for (i = 0; names[i]; i++) {
100 - EXPECT(0 == strcmp(want[i], names[i]));
96 + check_str(want[i], names[i]);
97 }
98 free_names(names);
99 (void) remove(fn);
@@ -132,7 +128,7 @@ static void write_n_ref_tables(struct reftable_stack *st,
128 set_test_hash(ref.value.val1, i);
129
130 err = reftable_stack_add(st, &write_test_ref, &ref);
135 - EXPECT_ERR(err);
131 + check(!err);
132 }
133
134 st->opts.disable_auto_compact = disable_auto_compact;
@@ -152,7 +148,7 @@ static int write_test_log(struct reftable_writer *wr, void *arg)
148 return reftable_writer_add_log(wr, wla->log);
149 }
150
155 -static void test_reftable_stack_add_one(void)
151 +static void t_reftable_stack_add_one(void)
152 {
153 char *dir = get_tmp_dir(__LINE__);
154 struct strbuf scratch = STRBUF_INIT;
@@ -171,22 +167,22 @@ static void test_reftable_stack_add_one(void)
167 struct reftable_ref_record dest = { NULL };
168 struct stat stat_result = { 0 };
169 err = reftable_new_stack(&st, dir, &opts);
174 - EXPECT_ERR(err);
170 + check(!err);
171
172 err = reftable_stack_add(st, &write_test_ref, &ref);
177 - EXPECT_ERR(err);
173 + check(!err);
174
175 err = reftable_stack_read_ref(st, ref.refname, &dest);
180 - EXPECT_ERR(err);
181 - EXPECT(0 == strcmp("master", dest.value.symref));
182 - EXPECT(st->readers_len > 0);
176 + check(!err);
177 + check_str("master", dest.value.symref);
178 + check_int(st->readers_len, >, 0);
179
180 #ifndef GIT_WINDOWS_NATIVE
181 strbuf_addstr(&scratch, dir);
182 strbuf_addstr(&scratch, "/tables.list");
183 err = stat(scratch.buf, &stat_result);
188 - EXPECT(!err);
189 - EXPECT((stat_result.st_mode & 0777) == opts.default_permissions);
184 + check(!err);
185 + check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
186
187 strbuf_reset(&scratch);
188 strbuf_addstr(&scratch, dir);
@@ -194,8 +190,8 @@ static void test_reftable_stack_add_one(void)
190 /* do not try at home; not an external API for reftable. */
191 strbuf_addstr(&scratch, st->readers[0]->name);
192 err = stat(scratch.buf, &stat_result);
197 - EXPECT(!err);
198 - EXPECT((stat_result.st_mode & 0777) == opts.default_permissions);
193 + check(!err);
194 + check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
195 #else
196 (void) stat_result;
197 #endif
@@ -207,7 +203,7 @@ static void test_reftable_stack_add_one(void)
203 umask(mask);
204 }
205
210 -static void test_reftable_stack_uptodate(void)
206 +static void t_reftable_stack_uptodate(void)
207 {
208 struct reftable_write_options opts = { 0 };
209 struct reftable_stack *st1 = NULL;
@@ -233,28 +229,28 @@ static void test_reftable_stack_uptodate(void)
229 by creating two stacks for the same directory.
230 */
231 err = reftable_new_stack(&st1, dir, &opts);
236 - EXPECT_ERR(err);
232 + check(!err);
233
234 err = reftable_new_stack(&st2, dir, &opts);
239 - EXPECT_ERR(err);
235 + check(!err);
236
237 err = reftable_stack_add(st1, &write_test_ref, &ref1);
242 - EXPECT_ERR(err);
238 + check(!err);
239
240 err = reftable_stack_add(st2, &write_test_ref, &ref2);
245 - EXPECT(err == REFTABLE_OUTDATED_ERROR);
241 + check_int(err, ==, REFTABLE_OUTDATED_ERROR);
242
243 err = reftable_stack_reload(st2);
248 - EXPECT_ERR(err);
244 + check(!err);
245
246 err = reftable_stack_add(st2, &write_test_ref, &ref2);
251 - EXPECT_ERR(err);
247 + check(!err);
248 reftable_stack_destroy(st1);
249 reftable_stack_destroy(st2);
250 clear_dir(dir);
251 }
252
257 -static void test_reftable_stack_transaction_api(void)
253 +static void t_reftable_stack_transaction_api(void)
254 {
255 char *dir = get_tmp_dir(__LINE__);
256 struct reftable_write_options opts = { 0 };
@@ -271,32 +267,32 @@ static void test_reftable_stack_transaction_api(void)
267 struct reftable_ref_record dest = { NULL };
268
269 err = reftable_new_stack(&st, dir, &opts);
274 - EXPECT_ERR(err);
270 + check(!err);
271
272 reftable_addition_destroy(add);
273
274 err = reftable_stack_new_addition(&add, st);
279 - EXPECT_ERR(err);
275 + check(!err);
276
277 err = reftable_addition_add(add, &write_test_ref, &ref);
282 - EXPECT_ERR(err);
278 + check(!err);
279
280 err = reftable_addition_commit(add);
285 - EXPECT_ERR(err);
281 + check(!err);
282
283 reftable_addition_destroy(add);
284
285 err = reftable_stack_read_ref(st, ref.refname, &dest);
290 - EXPECT_ERR(err);
291 - EXPECT(REFTABLE_REF_SYMREF == dest.value_type);
292 - EXPECT(0 == strcmp("master", dest.value.symref));
286 + check(!err);
287 + check_int(REFTABLE_REF_SYMREF, ==, dest.value_type);
288 + check_str("master", dest.value.symref);
289
290 reftable_ref_record_release(&dest);
291 reftable_stack_destroy(st);
292 clear_dir(dir);
293 }
294
299 -static void test_reftable_stack_transaction_api_performs_auto_compaction(void)
295 +static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
296 {
297 char *dir = get_tmp_dir(__LINE__);
298 struct reftable_write_options opts = {0};
@@ -305,7 +301,7 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void)
301 int i, n = 20, err;
302
303 err = reftable_new_stack(&st, dir, &opts);
308 - EXPECT_ERR(err);
304 + check(!err);
305
306 for (i = 0; i <= n; i++) {
307 struct reftable_ref_record ref = {
@@ -326,13 +322,13 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void)
322 st->opts.disable_auto_compact = i != n;
323
324 err = reftable_stack_new_addition(&add, st);
329 - EXPECT_ERR(err);
325 + check(!err);
326
327 err = reftable_addition_add(add, &write_test_ref, &ref);
332 - EXPECT_ERR(err);
328 + check(!err);
329
330 err = reftable_addition_commit(add);
335 - EXPECT_ERR(err);
331 + check(!err);
332
333 reftable_addition_destroy(add);
334
@@ -342,16 +338,16 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void)
338 * all tables in the stack.
339 */
340 if (i != n)
345 - EXPECT(st->merged->readers_len == i + 1);
341 + check_int(st->merged->readers_len, ==, i + 1);
342 else
347 - EXPECT(st->merged->readers_len == 1);
343 + check_int(st->merged->readers_len, ==, 1);
344 }
345
346 reftable_stack_destroy(st);
347 clear_dir(dir);
348 }
349
354 -static void test_reftable_stack_auto_compaction_fails_gracefully(void)
350 +static void t_reftable_stack_auto_compaction_fails_gracefully(void)
351 {
352 struct reftable_ref_record ref = {
353 .refname = (char *) "refs/heads/master",
@@ -366,13 +362,13 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void)
362 int err;
363
364 err = reftable_new_stack(&st, dir, &opts);
369 - EXPECT_ERR(err);
365 + check(!err);
366
367 err = reftable_stack_add(st, write_test_ref, &ref);
372 - EXPECT_ERR(err);
373 - EXPECT(st->merged->readers_len == 1);
374 - EXPECT(st->stats.attempts == 0);
375 - EXPECT(st->stats.failures == 0);
368 + check(!err);
369 + check_int(st->merged->readers_len, ==, 1);
370 + check_int(st->stats.attempts, ==, 0);
371 + check_int(st->stats.failures, ==, 0);
372
373 /*
374 * Lock the newly written table such that it cannot be compacted.
@@ -384,10 +380,10 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void)
380
381 ref.update_index = 2;
382 err = reftable_stack_add(st, write_test_ref, &ref);
387 - EXPECT_ERR(err);
388 - EXPECT(st->merged->readers_len == 2);
389 - EXPECT(st->stats.attempts == 1);
390 - EXPECT(st->stats.failures == 1);
383 + check(!err);
384 + check_int(st->merged->readers_len, ==, 2);
385 + check_int(st->stats.attempts, ==, 1);
386 + check_int(st->stats.failures, ==, 1);
387
388 reftable_stack_destroy(st);
389 strbuf_release(&table_path);
@@ -399,7 +395,7 @@ static int write_error(struct reftable_writer *wr UNUSED, void *arg)
395 return *((int *)arg);
396 }
397
402 -static void test_reftable_stack_update_index_check(void)
398 +static void t_reftable_stack_update_index_check(void)
399 {
400 char *dir = get_tmp_dir(__LINE__);
401 struct reftable_write_options opts = { 0 };
@@ -419,18 +415,18 @@ static void test_reftable_stack_update_index_check(void)
415 };
416
417 err = reftable_new_stack(&st, dir, &opts);
422 - EXPECT_ERR(err);
418 + check(!err);
419
420 err = reftable_stack_add(st, &write_test_ref, &ref1);
425 - EXPECT_ERR(err);
421 + check(!err);
422
423 err = reftable_stack_add(st, &write_test_ref, &ref2);
428 - EXPECT(err == REFTABLE_API_ERROR);
424 + check_int(err, ==, REFTABLE_API_ERROR);
425 reftable_stack_destroy(st);
426 clear_dir(dir);
427 }
428
433 -static void test_reftable_stack_lock_failure(void)
429 +static void t_reftable_stack_lock_failure(void)
430 {
431 char *dir = get_tmp_dir(__LINE__);
432 struct reftable_write_options opts = { 0 };
@@ -438,17 +434,17 @@ static void test_reftable_stack_lock_failure(void)
434 int err, i;
435
436 err = reftable_new_stack(&st, dir, &opts);
441 - EXPECT_ERR(err);
437 + check(!err);
438 for (i = -1; i != REFTABLE_EMPTY_TABLE_ERROR; i--) {
439 err = reftable_stack_add(st, &write_error, &i);
444 - EXPECT(err == i);
440 + check_int(err, ==, i);
441 }
442
443 reftable_stack_destroy(st);
444 clear_dir(dir);
445 }
446
451 -static void test_reftable_stack_add(void)
447 +static void t_reftable_stack_add(void)
448 {
449 int i = 0;
450 int err = 0;
@@ -466,7 +462,7 @@ static void test_reftable_stack_add(void)
462 int N = ARRAY_SIZE(refs);
463
464 err = reftable_new_stack(&st, dir, &opts);
469 - EXPECT_ERR(err);
465 + check(!err);
466
467 for (i = 0; i < N; i++) {
468 char buf[256];
@@ -485,7 +481,7 @@ static void test_reftable_stack_add(void)
481
482 for (i = 0; i < N; i++) {
483 int err = reftable_stack_add(st, &write_test_ref, &refs[i]);
488 - EXPECT_ERR(err);
484 + check(!err);
485 }
486
487 for (i = 0; i < N; i++) {
@@ -494,18 +490,18 @@ static void test_reftable_stack_add(void)
490 .update_index = reftable_stack_next_update_index(st),
491 };
492 int err = reftable_stack_add(st, &write_test_log, &arg);
497 - EXPECT_ERR(err);
493 + check(!err);
494 }
495
496 err = reftable_stack_compact_all(st, NULL);
501 - EXPECT_ERR(err);
497 + check(!err);
498
499 for (i = 0; i < N; i++) {
500 struct reftable_ref_record dest = { NULL };
501
502 int err = reftable_stack_read_ref(st, refs[i].refname, &dest);
507 - EXPECT_ERR(err);
508 - EXPECT(reftable_ref_record_equal(&dest, refs + i,
503 + check(!err);
504 + check(reftable_ref_record_equal(&dest, refs + i,
505 GIT_SHA1_RAWSZ));
506 reftable_ref_record_release(&dest);
507 }
@@ -513,8 +509,8 @@ static void test_reftable_stack_add(void)
509 for (i = 0; i < N; i++) {
510 struct reftable_log_record dest = { NULL };
511 int err = reftable_stack_read_log(st, refs[i].refname, &dest);
516 - EXPECT_ERR(err);
517 - EXPECT(reftable_log_record_equal(&dest, logs + i,
512 + check(!err);
513 + check(reftable_log_record_equal(&dest, logs + i,
514 GIT_SHA1_RAWSZ));
515 reftable_log_record_release(&dest);
516 }
@@ -523,8 +519,8 @@ static void test_reftable_stack_add(void)
519 strbuf_addstr(&path, dir);
520 strbuf_addstr(&path, "/tables.list");
521 err = stat(path.buf, &stat_result);
526 - EXPECT(!err);
527 - EXPECT((stat_result.st_mode & 0777) == opts.default_permissions);
522 + check(!err);
523 + check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
524
525 strbuf_reset(&path);
526 strbuf_addstr(&path, dir);
@@ -532,8 +528,8 @@ static void test_reftable_stack_add(void)
528 /* do not try at home; not an external API for reftable. */
529 strbuf_addstr(&path, st->readers[0]->name);
530 err = stat(path.buf, &stat_result);
535 - EXPECT(!err);
536 - EXPECT((stat_result.st_mode & 0777) == opts.default_permissions);
531 + check(!err);
532 + check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
533 #else
534 (void) stat_result;
535 #endif
@@ -548,7 +544,7 @@ static void test_reftable_stack_add(void)
544 clear_dir(dir);
545 }
546
551 -static void test_reftable_stack_log_normalize(void)
547 +static void t_reftable_stack_log_normalize(void)
548 {
549 int err = 0;
550 struct reftable_write_options opts = {
@@ -576,27 +572,27 @@ static void test_reftable_stack_log_normalize(void)
572 };
573
574 err = reftable_new_stack(&st, dir, &opts);
579 - EXPECT_ERR(err);
575 + check(!err);
576
577 input.value.update.message = (char *) "one\ntwo";
578 err = reftable_stack_add(st, &write_test_log, &arg);
583 - EXPECT(err == REFTABLE_API_ERROR);
579 + check_int(err, ==, REFTABLE_API_ERROR);
580
581 input.value.update.message = (char *) "one";
582 err = reftable_stack_add(st, &write_test_log, &arg);
587 - EXPECT_ERR(err);
583 + check(!err);
584
585 err = reftable_stack_read_log(st, input.refname, &dest);
590 - EXPECT_ERR(err);
591 - EXPECT(0 == strcmp(dest.value.update.message, "one\n"));
586 + check(!err);
587 + check_str(dest.value.update.message, "one\n");
588
589 input.value.update.message = (char *) "two\n";
590 arg.update_index = 2;
591 err = reftable_stack_add(st, &write_test_log, &arg);
596 - EXPECT_ERR(err);
592 + check(!err);
593 err = reftable_stack_read_log(st, input.refname, &dest);
598 - EXPECT_ERR(err);
599 - EXPECT(0 == strcmp(dest.value.update.message, "two\n"));
594 + check(!err);
595 + check_str(dest.value.update.message, "two\n");
596
597 /* cleanup */
598 reftable_stack_destroy(st);
@@ -604,7 +600,7 @@ static void test_reftable_stack_log_normalize(void)
600 clear_dir(dir);
601 }
602
607 -static void test_reftable_stack_tombstone(void)
603 +static void t_reftable_stack_tombstone(void)
604 {
605 int i = 0;
606 char *dir = get_tmp_dir(__LINE__);
@@ -618,7 +614,7 @@ static void test_reftable_stack_tombstone(void)
614 struct reftable_log_record log_dest = { NULL };
615
616 err = reftable_new_stack(&st, dir, &opts);
621 - EXPECT_ERR(err);
617 + check(!err);
618
619 /* even entries add the refs, odd entries delete them. */
620 for (i = 0; i < N; i++) {
@@ -642,7 +638,7 @@ static void test_reftable_stack_tombstone(void)
638 }
639 for (i = 0; i < N; i++) {
640 int err = reftable_stack_add(st, &write_test_ref, &refs[i]);
645 - EXPECT_ERR(err);
641 + check(!err);
642 }
643
644 for (i = 0; i < N; i++) {
@@ -651,25 +647,25 @@ static void test_reftable_stack_tombstone(void)
647 .update_index = reftable_stack_next_update_index(st),
648 };
649 int err = reftable_stack_add(st, &write_test_log, &arg);
654 - EXPECT_ERR(err);
650 + check(!err);
651 }
652
653 err = reftable_stack_read_ref(st, "branch", &dest);
658 - EXPECT(err == 1);
654 + check_int(err, ==, 1);
655 reftable_ref_record_release(&dest);
656
657 err = reftable_stack_read_log(st, "branch", &log_dest);
662 - EXPECT(err == 1);
658 + check_int(err, ==, 1);
659 reftable_log_record_release(&log_dest);
660
661 err = reftable_stack_compact_all(st, NULL);
666 - EXPECT_ERR(err);
662 + check(!err);
663
664 err = reftable_stack_read_ref(st, "branch", &dest);
669 - EXPECT(err == 1);
665 + check_int(err, ==, 1);
666
667 err = reftable_stack_read_log(st, "branch", &log_dest);
672 - EXPECT(err == 1);
668 + check_int(err, ==, 1);
669 reftable_ref_record_release(&dest);
670 reftable_log_record_release(&log_dest);
671
@@ -682,7 +678,7 @@ static void test_reftable_stack_tombstone(void)
678 clear_dir(dir);
679 }
680
685 -static void test_reftable_stack_hash_id(void)
681 +static void t_reftable_stack_hash_id(void)
682 {
683 char *dir = get_tmp_dir(__LINE__);
684 struct reftable_write_options opts = { 0 };
@@ -702,47 +698,47 @@ static void test_reftable_stack_hash_id(void)
698 struct reftable_ref_record dest = { NULL };
699
700 err = reftable_new_stack(&st, dir, &opts);
705 - EXPECT_ERR(err);
701 + check(!err);
702
703 err = reftable_stack_add(st, &write_test_ref, &ref);
708 - EXPECT_ERR(err);
704 + check(!err);
705
706 /* can't read it with the wrong hash ID. */
707 err = reftable_new_stack(&st32, dir, &opts32);
712 - EXPECT(err == REFTABLE_FORMAT_ERROR);
708 + check_int(err, ==, REFTABLE_FORMAT_ERROR);
709
710 /* check that we can read it back with default opts too. */
711 err = reftable_new_stack(&st_default, dir, &opts_default);
716 - EXPECT_ERR(err);
712 + check(!err);
713
714 err = reftable_stack_read_ref(st_default, "master", &dest);
719 - EXPECT_ERR(err);
715 + check(!err);
716
721 - EXPECT(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ));
717 + check(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ));
718 reftable_ref_record_release(&dest);
719 reftable_stack_destroy(st);
720 reftable_stack_destroy(st_default);
721 clear_dir(dir);
722 }
723
728 -static void test_suggest_compaction_segment(void)
724 +static void t_suggest_compaction_segment(void)
725 {
726 uint64_t sizes[] = { 512, 64, 17, 16, 9, 9, 9, 16, 2, 16 };
727 struct segment min =
728 suggest_compaction_segment(sizes, ARRAY_SIZE(sizes), 2);
733 - EXPECT(min.start == 1);
734 - EXPECT(min.end == 10);
729 + check_int(min.start, ==, 1);
730 + check_int(min.end, ==, 10);
731 }
732
737 -static void test_suggest_compaction_segment_nothing(void)
733 +static void t_suggest_compaction_segment_nothing(void)
734 {
735 uint64_t sizes[] = { 64, 32, 16, 8, 4, 2 };
736 struct segment result =
737 suggest_compaction_segment(sizes, ARRAY_SIZE(sizes), 2);
742 - EXPECT(result.start == result.end);
738 + check_int(result.start, ==, result.end);
739 }
740
745 -static void test_reflog_expire(void)
741 +static void t_reflog_expire(void)
742 {
743 char *dir = get_tmp_dir(__LINE__);
744 struct reftable_write_options opts = { 0 };
@@ -757,7 +753,7 @@ static void test_reflog_expire(void)
753 struct reftable_log_record log = { NULL };
754
755 err = reftable_new_stack(&st, dir, &opts);
760 - EXPECT_ERR(err);
756 + check(!err);
757
758 for (i = 1; i <= N; i++) {
759 char buf[256];
@@ -777,30 +773,30 @@ static void test_reflog_expire(void)
773 .update_index = reftable_stack_next_update_index(st),
774 };
775 int err = reftable_stack_add(st, &write_test_log, &arg);
780 - EXPECT_ERR(err);
776 + check(!err);
777 }
778
779 err = reftable_stack_compact_all(st, NULL);
784 - EXPECT_ERR(err);
780 + check(!err);
781
782 err = reftable_stack_compact_all(st, &expiry);
787 - EXPECT_ERR(err);
783 + check(!err);
784
785 err = reftable_stack_read_log(st, logs[9].refname, &log);
790 - EXPECT(err == 1);
786 + check_int(err, ==, 1);
787
788 err = reftable_stack_read_log(st, logs[11].refname, &log);
793 - EXPECT_ERR(err);
789 + check(!err);
790
791 expiry.min_update_index = 15;
792 err = reftable_stack_compact_all(st, &expiry);
797 - EXPECT_ERR(err);
793 + check(!err);
794
795 err = reftable_stack_read_log(st, logs[14].refname, &log);
800 - EXPECT(err == 1);
796 + check_int(err, ==, 1);
797
798 err = reftable_stack_read_log(st, logs[16].refname, &log);
803 - EXPECT_ERR(err);
799 + check(!err);
800
801 /* cleanup */
802 reftable_stack_destroy(st);
@@ -817,7 +813,7 @@ static int write_nothing(struct reftable_writer *wr, void *arg UNUSED)
813 return 0;
814 }
815
820 -static void test_empty_add(void)
816 +static void t_empty_add(void)
817 {
818 struct reftable_write_options opts = { 0 };
819 struct reftable_stack *st = NULL;
@@ -826,13 +822,13 @@ static void test_empty_add(void)
822 struct reftable_stack *st2 = NULL;
823
824 err = reftable_new_stack(&st, dir, &opts);
829 - EXPECT_ERR(err);
825 + check(!err);
826
827 err = reftable_stack_add(st, &write_nothing, NULL);
832 - EXPECT_ERR(err);
828 + check(!err);
829
830 err = reftable_new_stack(&st2, dir, &opts);
835 - EXPECT_ERR(err);
831 + check(!err);
832 clear_dir(dir);
833 reftable_stack_destroy(st);
834 reftable_stack_destroy(st2);
@@ -848,7 +844,7 @@ static int fastlog2(uint64_t sz)
844 return l - 1;
845 }
846
851 -static void test_reftable_stack_auto_compaction(void)
847 +static void t_reftable_stack_auto_compaction(void)
848 {
849 struct reftable_write_options opts = {
850 .disable_auto_compact = 1,
@@ -859,7 +855,7 @@ static void test_reftable_stack_auto_compaction(void)
855 int N = 100;
856
857 err = reftable_new_stack(&st, dir, &opts);
862 - EXPECT_ERR(err);
858 + check(!err);
859
860 for (i = 0; i < N; i++) {
861 char name[100];
@@ -872,21 +868,21 @@ static void test_reftable_stack_auto_compaction(void)
868 snprintf(name, sizeof(name), "branch%04d", i);
869
870 err = reftable_stack_add(st, &write_test_ref, &ref);
875 - EXPECT_ERR(err);
871 + check(!err);
872
873 err = reftable_stack_auto_compact(st);
878 - EXPECT_ERR(err);
879 - EXPECT(i < 3 || st->merged->readers_len < 2 * fastlog2(i));
874 + check(!err);
875 + check(i < 3 || st->merged->readers_len < 2 * fastlog2(i));
876 }
877
882 - EXPECT(reftable_stack_compaction_stats(st)->entries_written <
878 + check_int(reftable_stack_compaction_stats(st)->entries_written, <,
879 (uint64_t)(N * fastlog2(N)));
880
881 reftable_stack_destroy(st);
882 clear_dir(dir);
883 }
884
889 -static void test_reftable_stack_auto_compaction_with_locked_tables(void)
885 +static void t_reftable_stack_auto_compaction_with_locked_tables(void)
886 {
887 struct reftable_write_options opts = {
888 .disable_auto_compact = 1,
@@ -897,10 +893,10 @@ static void test_reftable_stack_auto_compaction_with_locked_tables(void)
893 int err;
894
895 err = reftable_new_stack(&st, dir, &opts);
900 - EXPECT_ERR(err);
896 + check(!err);
897
898 write_n_ref_tables(st, 5);
903 - EXPECT(st->merged->readers_len == 5);
899 + check_int(st->merged->readers_len, ==, 5);
900
901 /*
902 * Given that all tables we have written should be roughly the same
@@ -918,16 +914,16 @@ static void test_reftable_stack_auto_compaction_with_locked_tables(void)
914 * only compact the newest two tables.
915 */
916 err = reftable_stack_auto_compact(st);
921 - EXPECT_ERR(err);
922 - EXPECT(st->stats.failures == 0);
923 - EXPECT(st->merged->readers_len == 4);
917 + check(!err);
918 + check_int(st->stats.failures, ==, 0);
919 + check_int(st->merged->readers_len, ==, 4);
920
921 reftable_stack_destroy(st);
922 strbuf_release(&buf);
923 clear_dir(dir);
924 }
925
930 -static void test_reftable_stack_add_performs_auto_compaction(void)
926 +static void t_reftable_stack_add_performs_auto_compaction(void)
927 {
928 struct reftable_write_options opts = { 0 };
929 struct reftable_stack *st = NULL;
@@ -936,7 +932,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void)
932 int err, i, n = 20;
933
934 err = reftable_new_stack(&st, dir, &opts);
939 - EXPECT_ERR(err);
935 + check(!err);
936
937 for (i = 0; i <= n; i++) {
938 struct reftable_ref_record ref = {
@@ -957,7 +953,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void)
953 ref.refname = refname.buf;
954
955 err = reftable_stack_add(st, &write_test_ref, &ref);
960 - EXPECT_ERR(err);
956 + check(!err);
957
958 /*
959 * The stack length should grow continuously for all runs where
@@ -965,9 +961,9 @@ static void test_reftable_stack_add_performs_auto_compaction(void)
961 * all tables in the stack.
962 */
963 if (i != n)
968 - EXPECT(st->merged->readers_len == i + 1);
964 + check_int(st->merged->readers_len, ==, i + 1);
965 else
970 - EXPECT(st->merged->readers_len == 1);
966 + check_int(st->merged->readers_len, ==, 1);
967 }
968
969 reftable_stack_destroy(st);
@@ -975,7 +971,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void)
971 clear_dir(dir);
972 }
973
978 -static void test_reftable_stack_compaction_with_locked_tables(void)
974 +static void t_reftable_stack_compaction_with_locked_tables(void)
975 {
976 struct reftable_write_options opts = {
977 .disable_auto_compact = 1,
@@ -986,10 +982,10 @@ static void test_reftable_stack_compaction_with_locked_tables(void)
982 int err;
983
984 err = reftable_new_stack(&st, dir, &opts);
989 - EXPECT_ERR(err);
985 + check(!err);
986
987 write_n_ref_tables(st, 3);
992 - EXPECT(st->merged->readers_len == 3);
988 + check_int(st->merged->readers_len, ==, 3);
989
990 /* Lock one of the tables that we're about to compact. */
991 strbuf_reset(&buf);
@@ -1001,16 +997,16 @@ static void test_reftable_stack_compaction_with_locked_tables(void)
997 * compact all tables.
998 */
999 err = reftable_stack_compact_all(st, NULL);
1004 - EXPECT(err == REFTABLE_LOCK_ERROR);
1005 - EXPECT(st->stats.failures == 1);
1006 - EXPECT(st->merged->readers_len == 3);
1000 + check_int(err, ==, REFTABLE_LOCK_ERROR);
1001 + check_int(st->stats.failures, ==, 1);
1002 + check_int(st->merged->readers_len, ==, 3);
1003
1004 reftable_stack_destroy(st);
1005 strbuf_release(&buf);
1006 clear_dir(dir);
1007 }
1008
1013 -static void test_reftable_stack_compaction_concurrent(void)
1009 +static void t_reftable_stack_compaction_concurrent(void)
1010 {
1011 struct reftable_write_options opts = { 0 };
1012 struct reftable_stack *st1 = NULL, *st2 = NULL;
@@ -1018,19 +1014,19 @@ static void test_reftable_stack_compaction_concurrent(void)
1014 int err;
1015
1016 err = reftable_new_stack(&st1, dir, &opts);
1021 - EXPECT_ERR(err);
1017 + check(!err);
1018 write_n_ref_tables(st1, 3);
1019
1020 err = reftable_new_stack(&st2, dir, &opts);
1025 - EXPECT_ERR(err);
1021 + check(!err);
1022
1023 err = reftable_stack_compact_all(st1, NULL);
1028 - EXPECT_ERR(err);
1024 + check(!err);
1025
1026 reftable_stack_destroy(st1);
1027 reftable_stack_destroy(st2);
1028
1033 - EXPECT(count_dir_entries(dir) == 2);
1029 + check_int(count_dir_entries(dir), ==, 2);
1030 clear_dir(dir);
1031 }
1032
@@ -1043,7 +1039,7 @@ static void unclean_stack_close(struct reftable_stack *st)
1039 FREE_AND_NULL(st->readers);
1040 }
1041
1046 -static void test_reftable_stack_compaction_concurrent_clean(void)
1042 +static void t_reftable_stack_compaction_concurrent_clean(void)
1043 {
1044 struct reftable_write_options opts = { 0 };
1045 struct reftable_stack *st1 = NULL, *st2 = NULL, *st3 = NULL;
@@ -1051,24 +1047,24 @@ static void test_reftable_stack_compaction_concurrent_clean(void)
1047 int err;
1048
1049 err = reftable_new_stack(&st1, dir, &opts);
1054 - EXPECT_ERR(err);
1050 + check(!err);
1051 write_n_ref_tables(st1, 3);
1052
1053 err = reftable_new_stack(&st2, dir, &opts);
1058 - EXPECT_ERR(err);
1054 + check(!err);
1055
1056 err = reftable_stack_compact_all(st1, NULL);
1061 - EXPECT_ERR(err);
1057 + check(!err);
1058
1059 unclean_stack_close(st1);
1060 unclean_stack_close(st2);
1061
1062 err = reftable_new_stack(&st3, dir, &opts);
1067 - EXPECT_ERR(err);
1063 + check(!err);
1064
1065 err = reftable_stack_clean(st3);
1070 - EXPECT_ERR(err);
1071 - EXPECT(count_dir_entries(dir) == 2);
1066 + check(!err);
1067 + check_int(count_dir_entries(dir), ==, 2);
1068
1069 reftable_stack_destroy(st1);
1070 reftable_stack_destroy(st2);
@@ -1077,7 +1073,7 @@ static void test_reftable_stack_compaction_concurrent_clean(void)
1073 clear_dir(dir);
1074 }
1075
1080 -static void test_reftable_stack_read_across_reload(void)
1076 +static void t_reftable_stack_read_across_reload(void)
1077 {
1078 struct reftable_write_options opts = { 0 };
1079 struct reftable_stack *st1 = NULL, *st2 = NULL;
@@ -1088,36 +1084,36 @@ static void test_reftable_stack_read_across_reload(void)
1084
1085 /* Create a first stack and set up an iterator for it. */
1086 err = reftable_new_stack(&st1, dir, &opts);
1091 - EXPECT_ERR(err);
1087 + check(!err);
1088 write_n_ref_tables(st1, 2);
1093 - EXPECT(st1->merged->readers_len == 2);
1089 + check_int(st1->merged->readers_len, ==, 2);
1090 reftable_stack_init_ref_iterator(st1, &it);
1091 err = reftable_iterator_seek_ref(&it, "");
1096 - EXPECT_ERR(err);
1092 + check(!err);
1093
1094 /* Set up a second stack for the same directory and compact it. */
1095 err = reftable_new_stack(&st2, dir, &opts);
1100 - EXPECT_ERR(err);
1101 - EXPECT(st2->merged->readers_len == 2);
1096 + check(!err);
1097 + check_int(st2->merged->readers_len, ==, 2);
1098 err = reftable_stack_compact_all(st2, NULL);
1103 - EXPECT_ERR(err);
1104 - EXPECT(st2->merged->readers_len == 1);
1099 + check(!err);
1100 + check_int(st2->merged->readers_len, ==, 1);
1101
1102 /*
1103 * Verify that we can continue to use the old iterator even after we
1104 * have reloaded its stack.
1105 */
1106 err = reftable_stack_reload(st1);
1111 - EXPECT_ERR(err);
1112 - EXPECT(st1->merged->readers_len == 1);
1107 + check(!err);
1108 + check_int(st1->merged->readers_len, ==, 1);
1109 err = reftable_iterator_next_ref(&it, &rec);
1114 - EXPECT_ERR(err);
1115 - EXPECT(!strcmp(rec.refname, "refs/heads/branch-0000"));
1110 + check(!err);
1111 + check_str(rec.refname, "refs/heads/branch-0000");
1112 err = reftable_iterator_next_ref(&it, &rec);
1117 - EXPECT_ERR(err);
1118 - EXPECT(!strcmp(rec.refname, "refs/heads/branch-0001"));
1113 + check(!err);
1114 + check_str(rec.refname, "refs/heads/branch-0001");
1115 err = reftable_iterator_next_ref(&it, &rec);
1120 - EXPECT(err > 0);
1116 + check_int(err, >, 0);
1117
1118 reftable_ref_record_release(&rec);
1119 reftable_iterator_destroy(&it);
@@ -1126,7 +1122,7 @@ static void test_reftable_stack_read_across_reload(void)
1122 clear_dir(dir);
1123 }
1124
1129 -static void test_reftable_stack_reload_with_missing_table(void)
1125 +static void t_reftable_stack_reload_with_missing_table(void)
1126 {
1127 struct reftable_write_options opts = { 0 };
1128 struct reftable_stack *st = NULL;
@@ -1138,12 +1134,12 @@ static void test_reftable_stack_reload_with_missing_table(void)
1134
1135 /* Create a first stack and set up an iterator for it. */
1136 err = reftable_new_stack(&st, dir, &opts);
1141 - EXPECT_ERR(err);
1137 + check(!err);
1138 write_n_ref_tables(st, 2);
1143 - EXPECT(st->merged->readers_len == 2);
1139 + check_int(st->merged->readers_len, ==, 2);
1140 reftable_stack_init_ref_iterator(st, &it);
1141 err = reftable_iterator_seek_ref(&it, "");
1146 - EXPECT_ERR(err);
1142 + check(!err);
1143
1144 /*
1145 * Update the tables.list file with some garbage data, while reusing
@@ -1156,24 +1152,24 @@ static void test_reftable_stack_reload_with_missing_table(void)
1152 strbuf_addf(&table_path, "%s.lock", st->list_file);
1153 write_file_buf(table_path.buf, content.buf, content.len);
1154 err = rename(table_path.buf, st->list_file);
1159 - EXPECT_ERR(err);
1155 + check(!err);
1156
1157 err = reftable_stack_reload(st);
1162 - EXPECT(err == -4);
1163 - EXPECT(st->merged->readers_len == 2);
1158 + check_int(err, ==, -4);
1159 + check_int(st->merged->readers_len, ==, 2);
1160
1161 /*
1162 * Even though the reload has failed, we should be able to continue
1163 * using the iterator.
1164 */
1165 err = reftable_iterator_next_ref(&it, &rec);
1170 - EXPECT_ERR(err);
1171 - EXPECT(!strcmp(rec.refname, "refs/heads/branch-0000"));
1166 + check(!err);
1167 + check_str(rec.refname, "refs/heads/branch-0000");
1168 err = reftable_iterator_next_ref(&it, &rec);
1173 - EXPECT_ERR(err);
1174 - EXPECT(!strcmp(rec.refname, "refs/heads/branch-0001"));
1169 + check(!err);
1170 + check_str(rec.refname, "refs/heads/branch-0001");
1171 err = reftable_iterator_next_ref(&it, &rec);
1176 - EXPECT(err > 0);
1172 + check_int(err, >, 0);
1173
1174 reftable_ref_record_release(&rec);
1175 reftable_iterator_destroy(&it);
@@ -1183,31 +1179,32 @@ static void test_reftable_stack_reload_with_missing_table(void)
1179 clear_dir(dir);
1180 }
1181
1186 -int stack_test_main(int argc UNUSED, const char *argv[] UNUSED)
1182 +int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
1183 {
1188 - RUN_TEST(test_empty_add);
1189 - RUN_TEST(test_read_file);
1190 - RUN_TEST(test_reflog_expire);
1191 - RUN_TEST(test_reftable_stack_add);
1192 - RUN_TEST(test_reftable_stack_add_one);
1193 - RUN_TEST(test_reftable_stack_auto_compaction);
1194 - RUN_TEST(test_reftable_stack_auto_compaction_with_locked_tables);
1195 - RUN_TEST(test_reftable_stack_add_performs_auto_compaction);
1196 - RUN_TEST(test_reftable_stack_compaction_concurrent);
1197 - RUN_TEST(test_reftable_stack_compaction_concurrent_clean);
1198 - RUN_TEST(test_reftable_stack_compaction_with_locked_tables);
1199 - RUN_TEST(test_reftable_stack_hash_id);
1200 - RUN_TEST(test_reftable_stack_lock_failure);
1201 - RUN_TEST(test_reftable_stack_log_normalize);
1202 - RUN_TEST(test_reftable_stack_tombstone);
1203 - RUN_TEST(test_reftable_stack_transaction_api);
1204 - RUN_TEST(test_reftable_stack_transaction_api_performs_auto_compaction);
1205 - RUN_TEST(test_reftable_stack_auto_compaction_fails_gracefully);
1206 - RUN_TEST(test_reftable_stack_update_index_check);
1207 - RUN_TEST(test_reftable_stack_uptodate);
1208 - RUN_TEST(test_reftable_stack_read_across_reload);
1209 - RUN_TEST(test_reftable_stack_reload_with_missing_table);
1210 - RUN_TEST(test_suggest_compaction_segment);
1211 - RUN_TEST(test_suggest_compaction_segment_nothing);
1212 - return 0;
1184 + TEST(t_empty_add(), "empty addition to stack");
1185 + TEST(t_read_file(), "read_lines works");
1186 + TEST(t_reflog_expire(), "expire reflog entries");
1187 + TEST(t_reftable_stack_add(), "add multiple refs and logs to stack");
1188 + TEST(t_reftable_stack_add_one(), "add a single ref record to stack");
1189 + TEST(t_reftable_stack_add_performs_auto_compaction(), "addition to stack triggers auto-compaction");
1190 + TEST(t_reftable_stack_auto_compaction(), "stack must form geometric sequence after compaction");
1191 + TEST(t_reftable_stack_auto_compaction_fails_gracefully(), "failure on auto-compaction");
1192 + TEST(t_reftable_stack_auto_compaction_with_locked_tables(), "auto compaction with locked tables");
1193 + TEST(t_reftable_stack_compaction_concurrent(), "compaction with concurrent stack");
1194 + TEST(t_reftable_stack_compaction_concurrent_clean(), "compaction with unclean stack shutdown");
1195 + TEST(t_reftable_stack_compaction_with_locked_tables(), "compaction with locked tables");
1196 + TEST(t_reftable_stack_hash_id(), "read stack with wrong hash ID");
1197 + TEST(t_reftable_stack_lock_failure(), "stack addition with lockfile failure");
1198 + TEST(t_reftable_stack_log_normalize(), "log messages should be normalized");
1199 + TEST(t_reftable_stack_read_across_reload(), "stack iterators work across reloads");
1200 + TEST(t_reftable_stack_reload_with_missing_table(), "stack iteration with garbage tables");
1201 + TEST(t_reftable_stack_tombstone(), "'tombstone' refs in stack");
1202 + TEST(t_reftable_stack_transaction_api(), "update transaction to stack");
1203 + TEST(t_reftable_stack_transaction_api_performs_auto_compaction(), "update transaction triggers auto-compaction");
1204 + TEST(t_reftable_stack_update_index_check(), "update transactions with equal update indices");
1205 + TEST(t_reftable_stack_uptodate(), "stack must be reloaded before ref update");
1206 + TEST(t_suggest_compaction_segment(), "suggest_compaction_segment with basic input");
1207 + TEST(t_suggest_compaction_segment_nothing(), "suggest_compaction_segment with pre-compacted input");
1208 +
1209 + return test_done();
1210 }