Skip to content

Commit a08ea27

Browse files
Chandra Pratapgitster
authored andcommitted
t: move reftable/pq_test.c to the unit testing framework
reftable/pq_test.c exercises a priority queue defined by reftable/pq.{c, h}. Migrate reftable/pq_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 align with unit-tests' standards. 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 2a85906 commit a08ea27

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ UNIT_TEST_PROGRAMS += t-oidmap
13401340
UNIT_TEST_PROGRAMS += t-oidtree
13411341
UNIT_TEST_PROGRAMS += t-prio-queue
13421342
UNIT_TEST_PROGRAMS += t-reftable-basics
1343+
UNIT_TEST_PROGRAMS += t-reftable-pq
13431344
UNIT_TEST_PROGRAMS += t-reftable-record
13441345
UNIT_TEST_PROGRAMS += t-strbuf
13451346
UNIT_TEST_PROGRAMS += t-strcmp-offset
@@ -2681,7 +2682,6 @@ REFTABLE_OBJS += reftable/writer.o
26812682
REFTABLE_TEST_OBJS += reftable/block_test.o
26822683
REFTABLE_TEST_OBJS += reftable/dump.o
26832684
REFTABLE_TEST_OBJS += reftable/merged_test.o
2684-
REFTABLE_TEST_OBJS += reftable/pq_test.o
26852685
REFTABLE_TEST_OBJS += reftable/readwrite_test.o
26862686
REFTABLE_TEST_OBJS += reftable/stack_test.o
26872687
REFTABLE_TEST_OBJS += reftable/test_framework.o

reftable/reftable-tests.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ license that can be found in the LICENSE file or at
1212
int basics_test_main(int argc, const char **argv);
1313
int block_test_main(int argc, const char **argv);
1414
int merged_test_main(int argc, const char **argv);
15-
int pq_test_main(int argc, const char **argv);
1615
int record_test_main(int argc, const char **argv);
1716
int readwrite_test_main(int argc, const char **argv);
1817
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
@@ -7,7 +7,6 @@ int cmd__reftable(int argc, const char **argv)
77
/* test from simple to complex. */
88
block_test_main(argc, argv);
99
tree_test_main(argc, argv);
10-
pq_test_main(argc, argv);
1110
readwrite_test_main(argc, argv);
1211
merged_test_main(argc, argv);
1312
stack_test_main(argc, argv);

reftable/pq_test.c renamed to t/unit-tests/t-reftable-pq.c

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

9-
#include "system.h"
10-
11-
#include "basics.h"
12-
#include "constants.h"
13-
#include "pq.h"
14-
#include "record.h"
15-
#include "reftable-tests.h"
16-
#include "test_framework.h"
9+
#include "test-lib.h"
10+
#include "reftable/constants.h"
11+
#include "reftable/pq.h"
1712

1813
void merged_iter_pqueue_check(struct merged_iter_pqueue pq)
1914
{
20-
int i;
21-
for (i = 1; i < pq.len; i++) {
22-
int parent = (i - 1) / 2;
23-
24-
EXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));
15+
for (size_t i = 1; i < pq.len; i++) {
16+
size_t parent = (i - 1) / 2;
17+
check(pq_less(&pq.heap[parent], &pq.heap[i]));
2518
}
2619
}
2720

28-
static void test_pq(void)
21+
static void t_pq(void)
2922
{
30-
struct merged_iter_pqueue pq = { NULL };
23+
struct merged_iter_pqueue pq = { 0 };
3124
struct reftable_record recs[54];
32-
int N = ARRAY_SIZE(recs) - 1, i;
25+
size_t N = ARRAY_SIZE(recs) - 1, i;
3326
char *last = NULL;
3427

3528
for (i = 0; i < N; i++) {
3629
struct strbuf refname = STRBUF_INIT;
37-
strbuf_addf(&refname, "%02d", i);
30+
strbuf_addf(&refname, "%02"PRIuMAX, (uintmax_t)i);
3831

3932
reftable_record_init(&recs[i], BLOCK_TYPE_REF);
4033
recs[i].u.ref.refname = strbuf_detach(&refname, NULL);
@@ -48,17 +41,16 @@ static void test_pq(void)
4841

4942
merged_iter_pqueue_add(&pq, &e);
5043
merged_iter_pqueue_check(pq);
51-
5244
i = (i * 7) % N;
5345
} while (i != 1);
5446

5547
while (!merged_iter_pqueue_is_empty(pq)) {
5648
struct pq_entry e = merged_iter_pqueue_remove(&pq);
5749
merged_iter_pqueue_check(pq);
5850

59-
EXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
51+
check(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
6052
if (last)
61-
EXPECT(strcmp(last, e.rec->u.ref.refname) < 0);
53+
check_int(strcmp(last, e.rec->u.ref.refname), <, 0);
6254
last = e.rec->u.ref.refname;
6355
}
6456

@@ -67,8 +59,9 @@ static void test_pq(void)
6759
merged_iter_pqueue_release(&pq);
6860
}
6961

70-
int pq_test_main(int argc, const char *argv[])
62+
int cmd_main(int argc, const char *argv[])
7163
{
72-
RUN_TEST(test_pq);
73-
return 0;
64+
TEST(t_pq(), "pq works");
65+
66+
return test_done();
7467
}

0 commit comments

Comments
 (0)