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>
This commit is contained in:

committed by
Junio C Hamano

parent
b34116a30c
commit
f74e1865fe
@ -102,29 +102,6 @@ static void test_read_file(void)
|
|||||||
(void) remove(fn);
|
(void) remove(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_parse_names(void)
|
|
||||||
{
|
|
||||||
char buf[] = "line\n";
|
|
||||||
char **names = NULL;
|
|
||||||
parse_names(buf, strlen(buf), &names);
|
|
||||||
|
|
||||||
EXPECT(NULL != names[0]);
|
|
||||||
EXPECT(0 == strcmp(names[0], "line"));
|
|
||||||
EXPECT(NULL == names[1]);
|
|
||||||
free_names(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_names_equal(void)
|
|
||||||
{
|
|
||||||
char *a[] = { "a", "b", "c", NULL };
|
|
||||||
char *b[] = { "a", "b", "d", NULL };
|
|
||||||
char *c[] = { "a", "b", NULL };
|
|
||||||
|
|
||||||
EXPECT(names_equal(a, a));
|
|
||||||
EXPECT(!names_equal(a, b));
|
|
||||||
EXPECT(!names_equal(a, c));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int write_test_ref(struct reftable_writer *wr, void *arg)
|
static int write_test_ref(struct reftable_writer *wr, void *arg)
|
||||||
{
|
{
|
||||||
struct reftable_ref_record *ref = arg;
|
struct reftable_ref_record *ref = arg;
|
||||||
@ -1086,8 +1063,6 @@ static void test_reftable_stack_compaction_concurrent_clean(void)
|
|||||||
int stack_test_main(int argc, const char *argv[])
|
int stack_test_main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
RUN_TEST(test_empty_add);
|
RUN_TEST(test_empty_add);
|
||||||
RUN_TEST(test_names_equal);
|
|
||||||
RUN_TEST(test_parse_names);
|
|
||||||
RUN_TEST(test_read_file);
|
RUN_TEST(test_read_file);
|
||||||
RUN_TEST(test_reflog_expire);
|
RUN_TEST(test_reflog_expire);
|
||||||
RUN_TEST(test_reftable_stack_add);
|
RUN_TEST(test_reftable_stack_add);
|
||||||
|
@ -58,14 +58,32 @@ static void test_names_length(void)
|
|||||||
check_int(names_length(a), ==, 2);
|
check_int(names_length(a), ==, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_names_equal(void)
|
||||||
|
{
|
||||||
|
char *a[] = { "a", "b", "c", NULL };
|
||||||
|
char *b[] = { "a", "b", "d", NULL };
|
||||||
|
char *c[] = { "a", "b", NULL };
|
||||||
|
|
||||||
|
check(names_equal(a, a));
|
||||||
|
check(!names_equal(a, b));
|
||||||
|
check(!names_equal(a, c));
|
||||||
|
}
|
||||||
|
|
||||||
static void test_parse_names_normal(void)
|
static void test_parse_names_normal(void)
|
||||||
{
|
{
|
||||||
char in[] = "a\nb\n";
|
char in1[] = "line\n";
|
||||||
|
char in2[] = "a\nb\nc";
|
||||||
char **out = NULL;
|
char **out = NULL;
|
||||||
parse_names(in, strlen(in), &out);
|
parse_names(in1, strlen(in1), &out);
|
||||||
|
check_str(out[0], "line");
|
||||||
|
check(!out[1]);
|
||||||
|
free_names(out);
|
||||||
|
|
||||||
|
parse_names(in2, strlen(in2), &out);
|
||||||
check_str(out[0], "a");
|
check_str(out[0], "a");
|
||||||
check_str(out[1], "b");
|
check_str(out[1], "b");
|
||||||
check(!out[2]);
|
check_str(out[2], "c");
|
||||||
|
check(!out[3]);
|
||||||
free_names(out);
|
free_names(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +115,7 @@ int cmd_main(int argc, const char *argv[])
|
|||||||
TEST(test_parse_names_drop_empty(), "parse_names drops empty string");
|
TEST(test_parse_names_drop_empty(), "parse_names drops empty string");
|
||||||
TEST(test_binsearch(), "binary search with binsearch works");
|
TEST(test_binsearch(), "binary search with binsearch works");
|
||||||
TEST(test_names_length(), "names_length retuns size of a NULL-terminated string array");
|
TEST(test_names_length(), "names_length retuns size of a NULL-terminated string array");
|
||||||
|
TEST(test_names_equal(), "names_equal compares NULL-terminated string arrays");
|
||||||
|
|
||||||
return test_done();
|
return test_done();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user