Skip to content

Commit f74e186

Browse files
Chandra Pratapgitster
authored andcommitted
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 <[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 b34116a commit f74e186

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

reftable/stack_test.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,6 @@ static void test_read_file(void)
102102
(void) remove(fn);
103103
}
104104

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-
128105
static int write_test_ref(struct reftable_writer *wr, void *arg)
129106
{
130107
struct reftable_ref_record *ref = arg;
@@ -1086,8 +1063,6 @@ static void test_reftable_stack_compaction_concurrent_clean(void)
10861063
int stack_test_main(int argc, const char *argv[])
10871064
{
10881065
RUN_TEST(test_empty_add);
1089-
RUN_TEST(test_names_equal);
1090-
RUN_TEST(test_parse_names);
10911066
RUN_TEST(test_read_file);
10921067
RUN_TEST(test_reflog_expire);
10931068
RUN_TEST(test_reftable_stack_add);

t/unit-tests/t-reftable-basics.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,32 @@ static void test_names_length(void)
5858
check_int(names_length(a), ==, 2);
5959
}
6060

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+
6172
static void test_parse_names_normal(void)
6273
{
63-
char in[] = "a\nb\n";
74+
char in1[] = "line\n";
75+
char in2[] = "a\nb\nc";
6476
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);
6683
check_str(out[0], "a");
6784
check_str(out[1], "b");
68-
check(!out[2]);
85+
check_str(out[2], "c");
86+
check(!out[3]);
6987
free_names(out);
7088
}
7189

@@ -97,6 +115,7 @@ int cmd_main(int argc, const char *argv[])
97115
TEST(test_parse_names_drop_empty(), "parse_names drops empty string");
98116
TEST(test_binsearch(), "binary search with binsearch works");
99117
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");
100119

101120
return test_done();
102121
}

0 commit comments

Comments
 (0)