t: move tests from reftable/stack_test.c to the new unit test

parse_names() and names_equal() are functions defined in reftable/basics.{c, h}. Move the tests for these functions from reftable/stack_test.c to the newly ported test. 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 f74e1865fe3fd0de573da03ecd0b9efdcb95c672
2 files changed +22 -28
reftable/stack_test.c
-25
@@ -102,29 +102,6 @@ static void test_read_file(void)
102 (void) remove(fn);
103 }
104
105 -static void test_parse_names(void)
106 -{
107 - char buf[] = "line\n";
108 - char **names = NULL;
109 - parse_names(buf, strlen(buf), &names);
110 -
111 - EXPECT(NULL != names[0]);
112 - EXPECT(0 == strcmp(names[0], "line"));
113 - EXPECT(NULL == names[1]);
114 - free_names(names);
115 -}
116 -
117 -static void test_names_equal(void)
118 -{
119 - char *a[] = { "a", "b", "c", NULL };
120 - char *b[] = { "a", "b", "d", NULL };
121 - char *c[] = { "a", "b", NULL };
122 -
123 - EXPECT(names_equal(a, a));
124 - EXPECT(!names_equal(a, b));
125 - EXPECT(!names_equal(a, c));
126 -}
127 -
105 static int write_test_ref(struct reftable_writer *wr, void *arg)
106 {
107 struct reftable_ref_record *ref = arg;
@@ -1086,8 +1063,6 @@ static void test_reftable_stack_compaction_concurrent_clean(void)
1063 int stack_test_main(int argc, const char *argv[])
1064 {
1065 RUN_TEST(test_empty_add);
1089 - RUN_TEST(test_names_equal);
1090 - RUN_TEST(test_parse_names);
1066 RUN_TEST(test_read_file);
1067 RUN_TEST(test_reflog_expire);
1068 RUN_TEST(test_reftable_stack_add);
t/unit-tests/t-reftable-basics.c
+22 -3
@@ -58,14 +58,32 @@ static void test_names_length(void)
58 check_int(names_length(a), ==, 2);
59 }
60
61 +static void test_names_equal(void)
62 +{
63 + char *a[] = { "a", "b", "c", NULL };
64 + char *b[] = { "a", "b", "d", NULL };
65 + char *c[] = { "a", "b", NULL };
66 +
67 + check(names_equal(a, a));
68 + check(!names_equal(a, b));
69 + check(!names_equal(a, c));
70 +}
71 +
72 static void test_parse_names_normal(void)
73 {
63 - char in[] = "a\nb\n";
74 + char in1[] = "line\n";
75 + char in2[] = "a\nb\nc";
76 char **out = NULL;
65 - parse_names(in, strlen(in), &out);
77 + parse_names(in1, strlen(in1), &out);
78 + check_str(out[0], "line");
79 + check(!out[1]);
80 + free_names(out);
81 +
82 + parse_names(in2, strlen(in2), &out);
83 check_str(out[0], "a");
84 check_str(out[1], "b");
68 - check(!out[2]);
85 + check_str(out[2], "c");
86 + check(!out[3]);
87 free_names(out);
88 }
89
@@ -97,6 +115,7 @@ int cmd_main(int argc, const char *argv[])
115 TEST(test_parse_names_drop_empty(), "parse_names drops empty string");
116 TEST(test_binsearch(), "binary search with binsearch works");
117 TEST(test_names_length(), "names_length retuns size of a NULL-terminated string array");
118 + TEST(test_names_equal(), "names_equal compares NULL-terminated string arrays");
119
120 return test_done();
121 }