Skip to content

Commit f7ec13b

Browse files
Chandra Pratapgitster
Chandra Pratap
authored andcommitted
t-reftable-record: add tests for reftable_ref_record_compare_name()
reftable_ref_record_compare_name() is a function defined by reftable/record.{c, h} and is used to compare the refname of two ref records when sorting multiple ref records using 'qsort'. In the current testing setup, this function is left unexercised. Add a testing function for the same. Mentored-by: Patrick Steinhardt <[email protected]> Mentored-by: Christian Couder <[email protected]> Signed-off-by: Chandra Pratap <[email protected]> Acked-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8a1f1f8 commit f7ec13b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ static void t_reftable_ref_record_comparison(void)
9595
check(!reftable_record_cmp(&in[0], &in[1]));
9696
}
9797

98+
static void t_reftable_ref_record_compare_name(void)
99+
{
100+
struct reftable_ref_record recs[3] = {
101+
{
102+
.refname = (char *) "refs/heads/a"
103+
},
104+
{
105+
.refname = (char *) "refs/heads/b"
106+
},
107+
{
108+
.refname = (char *) "refs/heads/a"
109+
},
110+
};
111+
112+
check_int(reftable_ref_record_compare_name(&recs[0], &recs[1]), <, 0);
113+
check_int(reftable_ref_record_compare_name(&recs[1], &recs[0]), >, 0);
114+
check_int(reftable_ref_record_compare_name(&recs[0], &recs[2]), ==, 0);
115+
}
116+
98117
static void t_reftable_ref_record_roundtrip(void)
99118
{
100119
struct strbuf scratch = STRBUF_INIT;
@@ -490,6 +509,7 @@ int cmd_main(int argc, const char *argv[])
490509
TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
491510
TEST(t_reftable_index_record_comparison(), "comparison operations work on index record");
492511
TEST(t_reftable_obj_record_comparison(), "comparison operations work on obj record");
512+
TEST(t_reftable_ref_record_compare_name(), "reftable_ref_record_compare_name works");
493513
TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
494514
TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
495515
TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");

0 commit comments

Comments
 (0)