Skip to content

Commit 546cc0d

Browse files
Chandra Pratapgitster
authored andcommitted
t: move reftable/block_test.c to the unit testing framework
reftable/block_test.c exercises the functions defined in reftable/block.{c, h}. Migrate reftable/block_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 follow the unit-tests' naming conventions. Mentored-by: Patrick Steinhardt <[email protected]> Mentored-by: Christian Couder <[email protected]> Signed-off-by: Chandra Pratap <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80ccd8a commit 546cc0d

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,7 @@ UNIT_TEST_PROGRAMS += t-oidmap
13411341
UNIT_TEST_PROGRAMS += t-oidtree
13421342
UNIT_TEST_PROGRAMS += t-prio-queue
13431343
UNIT_TEST_PROGRAMS += t-reftable-basics
1344+
UNIT_TEST_PROGRAMS += t-reftable-block
13441345
UNIT_TEST_PROGRAMS += t-reftable-merged
13451346
UNIT_TEST_PROGRAMS += t-reftable-pq
13461347
UNIT_TEST_PROGRAMS += t-reftable-record
@@ -2682,7 +2683,6 @@ REFTABLE_OBJS += reftable/stack.o
26822683
REFTABLE_OBJS += reftable/tree.o
26832684
REFTABLE_OBJS += reftable/writer.o
26842685

2685-
REFTABLE_TEST_OBJS += reftable/block_test.o
26862686
REFTABLE_TEST_OBJS += reftable/dump.o
26872687
REFTABLE_TEST_OBJS += reftable/readwrite_test.o
26882688
REFTABLE_TEST_OBJS += reftable/stack_test.o

reftable/reftable-tests.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ license that can be found in the LICENSE file or at
1010
#define REFTABLE_TESTS_H
1111

1212
int basics_test_main(int argc, const char **argv);
13-
int block_test_main(int argc, const char **argv);
1413
int record_test_main(int argc, const char **argv);
1514
int readwrite_test_main(int argc, const char **argv);
1615
int stack_test_main(int argc, const char **argv);

t/helper/test-reftable.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
int cmd__reftable(int argc, const char **argv)
66
{
77
/* test from simple to complex. */
8-
block_test_main(argc, argv);
98
readwrite_test_main(argc, argv);
109
stack_test_main(argc, argv);
1110
return 0;

reftable/block_test.c renamed to t/unit-tests/t-reftable-block.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ license that can be found in the LICENSE file or at
66
https://developers.google.com/open-source/licenses/bsd
77
*/
88

9-
#include "block.h"
9+
#include "test-lib.h"
10+
#include "reftable/block.h"
11+
#include "reftable/blocksource.h"
12+
#include "reftable/constants.h"
13+
#include "reftable/reftable-error.h"
1014

11-
#include "system.h"
12-
#include "blocksource.h"
13-
#include "basics.h"
14-
#include "constants.h"
15-
#include "record.h"
16-
#include "test_framework.h"
17-
#include "reftable-tests.h"
18-
19-
static void test_block_read_write(void)
15+
static void t_block_read_write(void)
2016
{
2117
const int header_off = 21; /* random */
2218
char *names[30];
@@ -45,7 +41,7 @@ static void test_block_read_write(void)
4541
rec.u.ref.refname = (char *) "";
4642
rec.u.ref.value_type = REFTABLE_REF_DELETION;
4743
n = block_writer_add(&bw, &rec);
48-
EXPECT(n == REFTABLE_API_ERROR);
44+
check_int(n, ==, REFTABLE_API_ERROR);
4945

5046
for (i = 0; i < N; i++) {
5147
char name[100];
@@ -59,11 +55,11 @@ static void test_block_read_write(void)
5955
n = block_writer_add(&bw, &rec);
6056
rec.u.ref.refname = NULL;
6157
rec.u.ref.value_type = REFTABLE_REF_DELETION;
62-
EXPECT(n == 0);
58+
check_int(n, ==, 0);
6359
}
6460

6561
n = block_writer_finish(&bw);
66-
EXPECT(n > 0);
62+
check_int(n, >, 0);
6763

6864
block_writer_release(&bw);
6965

@@ -73,11 +69,11 @@ static void test_block_read_write(void)
7369

7470
while (1) {
7571
int r = block_iter_next(&it, &rec);
76-
EXPECT(r >= 0);
72+
check_int(r, >=, 0);
7773
if (r > 0) {
7874
break;
7975
}
80-
EXPECT_STREQ(names[j], rec.u.ref.refname);
76+
check_str(names[j], rec.u.ref.refname);
8177
j++;
8278
}
8379

@@ -90,20 +86,20 @@ static void test_block_read_write(void)
9086
strbuf_addstr(&want, names[i]);
9187

9288
n = block_iter_seek_key(&it, &br, &want);
93-
EXPECT(n == 0);
89+
check_int(n, ==, 0);
9490

9591
n = block_iter_next(&it, &rec);
96-
EXPECT(n == 0);
92+
check_int(n, ==, 0);
9793

98-
EXPECT_STREQ(names[i], rec.u.ref.refname);
94+
check_str(names[i], rec.u.ref.refname);
9995

10096
want.len--;
10197
n = block_iter_seek_key(&it, &br, &want);
102-
EXPECT(n == 0);
98+
check_int(n, ==, 0);
10399

104100
n = block_iter_next(&it, &rec);
105-
EXPECT(n == 0);
106-
EXPECT_STREQ(names[10 * (i / 10)], rec.u.ref.refname);
101+
check_int(n, ==, 0);
102+
check_str(names[10 * (i / 10)], rec.u.ref.refname);
107103

108104
block_iter_close(&it);
109105
}
@@ -116,8 +112,9 @@ static void test_block_read_write(void)
116112
}
117113
}
118114

119-
int block_test_main(int argc, const char *argv[])
115+
int cmd_main(int argc, const char *argv[])
120116
{
121-
RUN_TEST(test_block_read_write);
122-
return 0;
117+
TEST(t_block_read_write(), "read-write operations on blocks work");
118+
119+
return test_done();
123120
}

0 commit comments

Comments
 (0)