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 <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
May 29, 2024 at 22:29 UTC
b34116a30ce5ae19e303725d6e1fd0f558d36dce
3 files changed
+20
-24
Makefile
+1
-1
@@ -1349,6 +1349,7 @@ THIRD_PARTY_SOURCES += sha1dc/%
1349
1350
UNIT_TEST_PROGRAMS += t-basic
1351
UNIT_TEST_PROGRAMS += t-mem-pool
1352
+UNIT_TEST_PROGRAMS += t-reftable-basics
1353
UNIT_TEST_PROGRAMS += t-strbuf
1354
UNIT_TEST_PROGRAMS += t-ctype
1355
UNIT_TEST_PROGRAMS += t-prio-queue
@@ -2662,7 +2663,6 @@ REFTABLE_OBJS += reftable/stack.o
2663
REFTABLE_OBJS += reftable/tree.o
2664
REFTABLE_OBJS += reftable/writer.o
2665
2665
-REFTABLE_TEST_OBJS += reftable/basics_test.o
2666
REFTABLE_TEST_OBJS += reftable/block_test.o
2667
REFTABLE_TEST_OBJS += reftable/dump.o
2668
REFTABLE_TEST_OBJS += reftable/merged_test.o
t/helper/test-reftable.c
-1
@@ -5,7 +5,6 @@
5
int cmd__reftable(int argc, const char **argv)
6
{
7
/* test from simple to complex. */
8
- basics_test_main(argc, argv);
8
record_test_main(argc, argv);
9
block_test_main(argc, argv);
10
tree_test_main(argc, argv);
t/unit-tests/t-reftable-basics.c
renamed
+19
-22
@@ -6,11 +6,8 @@ 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
-
11
-#include "basics.h"
12
-#include "test_framework.h"
13
-#include "reftable-tests.h"
9
+#include "test-lib.h"
10
+#include "reftable/basics.h"
11
12
struct integer_needle_lesseq_args {
13
int needle;
@@ -42,9 +39,8 @@ static void test_binsearch(void)
39
{11, 5},
40
{9000, 5},
41
};
45
- size_t i = 0;
42
47
- for (i = 0; i < ARRAY_SIZE(testcases); i++) {
43
+ for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
44
struct integer_needle_lesseq_args args = {
45
.haystack = haystack,
46
.needle = testcases[i].needle,
@@ -52,14 +48,14 @@ static void test_binsearch(void)
48
size_t idx;
49
50
idx = binsearch(ARRAY_SIZE(haystack), &integer_needle_lesseq, &args);
55
- EXPECT(idx == testcases[i].expected_idx);
51
+ check_int(idx, ==, testcases[i].expected_idx);
52
}
53
}
54
55
static void test_names_length(void)
56
{
57
char *a[] = { "a", "b", NULL };
62
- EXPECT(names_length(a) == 2);
58
+ check_int(names_length(a), ==, 2);
59
}
60
61
static void test_parse_names_normal(void)
@@ -67,9 +63,9 @@ static void test_parse_names_normal(void)
63
char in[] = "a\nb\n";
64
char **out = NULL;
65
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]);
69
free_names(out);
70
}
71
@@ -78,8 +74,8 @@ static void test_parse_names_drop_empty(void)
74
char in[] = "a\n\n";
75
char **out = NULL;
76
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]);
79
free_names(out);
80
}
81
@@ -89,17 +85,18 @@ static void test_common_prefix(void)
85
struct strbuf s2 = STRBUF_INIT;
86
strbuf_addstr(&s1, "abcdef");
87
strbuf_addstr(&s2, "abc");
92
- EXPECT(common_prefix_size(&s1, &s2) == 3);
88
+ check_int(common_prefix_size(&s1, &s2), ==, 3);
89
strbuf_release(&s1);
90
strbuf_release(&s2);
91
}
92
97
-int basics_test_main(int argc, const char *argv[])
93
+int cmd_main(int argc, const char *argv[])
94
{
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();
102
}