Skip to content

Commit b34116a

Browse files
Chandra Pratapgitster
authored andcommitted
t: move reftable/basics_test.c to the unit testing framework
reftable/basics_test.c exercise the functions defined in reftable/basics.{c, h}. Migrate reftable/basics_test.c to the unit testing framework. Migration involves refactoring the tests to use the unit testing framework instead of reftable's test framework. 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 786a3e4 commit b34116a

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,7 @@ THIRD_PARTY_SOURCES += sha1dc/%
13491349

13501350
UNIT_TEST_PROGRAMS += t-basic
13511351
UNIT_TEST_PROGRAMS += t-mem-pool
1352+
UNIT_TEST_PROGRAMS += t-reftable-basics
13521353
UNIT_TEST_PROGRAMS += t-strbuf
13531354
UNIT_TEST_PROGRAMS += t-ctype
13541355
UNIT_TEST_PROGRAMS += t-prio-queue
@@ -2662,7 +2663,6 @@ REFTABLE_OBJS += reftable/stack.o
26622663
REFTABLE_OBJS += reftable/tree.o
26632664
REFTABLE_OBJS += reftable/writer.o
26642665

2665-
REFTABLE_TEST_OBJS += reftable/basics_test.o
26662666
REFTABLE_TEST_OBJS += reftable/block_test.o
26672667
REFTABLE_TEST_OBJS += reftable/dump.o
26682668
REFTABLE_TEST_OBJS += reftable/merged_test.o

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-
basics_test_main(argc, argv);
98
record_test_main(argc, argv);
109
block_test_main(argc, argv);
1110
tree_test_main(argc, argv);

reftable/basics_test.c renamed to t/unit-tests/t-reftable-basics.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ 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 "test_framework.h"
13-
#include "reftable-tests.h"
9+
#include "test-lib.h"
10+
#include "reftable/basics.h"
1411

1512
struct integer_needle_lesseq_args {
1613
int needle;
@@ -42,34 +39,33 @@ static void test_binsearch(void)
4239
{11, 5},
4340
{9000, 5},
4441
};
45-
size_t i = 0;
4642

47-
for (i = 0; i < ARRAY_SIZE(testcases); i++) {
43+
for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
4844
struct integer_needle_lesseq_args args = {
4945
.haystack = haystack,
5046
.needle = testcases[i].needle,
5147
};
5248
size_t idx;
5349

5450
idx = binsearch(ARRAY_SIZE(haystack), &integer_needle_lesseq, &args);
55-
EXPECT(idx == testcases[i].expected_idx);
51+
check_int(idx, ==, testcases[i].expected_idx);
5652
}
5753
}
5854

5955
static void test_names_length(void)
6056
{
6157
char *a[] = { "a", "b", NULL };
62-
EXPECT(names_length(a) == 2);
58+
check_int(names_length(a), ==, 2);
6359
}
6460

6561
static void test_parse_names_normal(void)
6662
{
6763
char in[] = "a\nb\n";
6864
char **out = NULL;
6965
parse_names(in, strlen(in), &out);
70-
EXPECT(!strcmp(out[0], "a"));
71-
EXPECT(!strcmp(out[1], "b"));
72-
EXPECT(!out[2]);
66+
check_str(out[0], "a");
67+
check_str(out[1], "b");
68+
check(!out[2]);
7369
free_names(out);
7470
}
7571

@@ -78,8 +74,8 @@ static void test_parse_names_drop_empty(void)
7874
char in[] = "a\n\n";
7975
char **out = NULL;
8076
parse_names(in, strlen(in), &out);
81-
EXPECT(!strcmp(out[0], "a"));
82-
EXPECT(!out[1]);
77+
check_str(out[0], "a");
78+
check(!out[1]);
8379
free_names(out);
8480
}
8581

@@ -89,17 +85,18 @@ static void test_common_prefix(void)
8985
struct strbuf s2 = STRBUF_INIT;
9086
strbuf_addstr(&s1, "abcdef");
9187
strbuf_addstr(&s2, "abc");
92-
EXPECT(common_prefix_size(&s1, &s2) == 3);
88+
check_int(common_prefix_size(&s1, &s2), ==, 3);
9389
strbuf_release(&s1);
9490
strbuf_release(&s2);
9591
}
9692

97-
int basics_test_main(int argc, const char *argv[])
93+
int cmd_main(int argc, const char *argv[])
9894
{
99-
RUN_TEST(test_common_prefix);
100-
RUN_TEST(test_parse_names_normal);
101-
RUN_TEST(test_parse_names_drop_empty);
102-
RUN_TEST(test_binsearch);
103-
RUN_TEST(test_names_length);
104-
return 0;
95+
TEST(test_common_prefix(), "common_prefix_size works");
96+
TEST(test_parse_names_normal(), "parse_names works for basic input");
97+
TEST(test_parse_names_drop_empty(), "parse_names drops empty string");
98+
TEST(test_binsearch(), "binary search with binsearch works");
99+
TEST(test_names_length(), "names_length retuns size of a NULL-terminated string array");
100+
101+
return test_done();
105102
}

0 commit comments

Comments
 (0)