Skip to content

Commit 9008b8a

Browse files
Chandra Pratapgitster
authored andcommitted
t-reftable-record: add reftable_record_cmp() tests for log records
In the current testing setup for log records, only reftable_log_record_equal() among log record's comparison functions is tested. Modify the existing tests to exercise reftable_log_record_cmp_void() (using the wrapper function reftable_record_cmp()) alongside reftable_log_record_equal(). Note that to achieve this, we'll need to replace instances of reftable_log_record_equal() with the wrapper function reftable_record_equal(). Rename the now modified test to reflect its nature of exercising all comparison operations, not just equality. 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 ba9661b commit 9008b8a

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,36 @@ static void t_reftable_ref_record_roundtrip(void)
120120
strbuf_release(&scratch);
121121
}
122122

123-
static void t_reftable_log_record_equal(void)
123+
static void t_reftable_log_record_comparison(void)
124124
{
125-
struct reftable_log_record in[2] = {
125+
struct reftable_record in[3] = {
126126
{
127-
.refname = xstrdup("refs/heads/master"),
128-
.update_index = 42,
127+
.type = BLOCK_TYPE_LOG,
128+
.u.log.refname = (char *) "refs/heads/master",
129+
.u.log.update_index = 42,
129130
},
130131
{
131-
.refname = xstrdup("refs/heads/master"),
132-
.update_index = 22,
133-
}
132+
.type = BLOCK_TYPE_LOG,
133+
.u.log.refname = (char *) "refs/heads/master",
134+
.u.log.update_index = 22,
135+
},
136+
{
137+
.type = BLOCK_TYPE_LOG,
138+
.u.log.refname = (char *) "refs/heads/main",
139+
.u.log.update_index = 22,
140+
},
134141
};
135142

136-
check(!reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
137-
in[1].update_index = in[0].update_index;
138-
check(reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
139-
reftable_log_record_release(&in[0]);
140-
reftable_log_record_release(&in[1]);
143+
check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
144+
check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
145+
check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
146+
/* comparison should be reversed for equal keys, because
147+
* comparison is now performed on the basis of update indices */
148+
check_int(reftable_record_cmp(&in[0], &in[1]), <, 0);
149+
150+
in[1].u.log.update_index = in[0].u.log.update_index;
151+
check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
152+
check(!reftable_record_cmp(&in[0], &in[1]));
141153
}
142154

143155
static void t_reftable_log_record_roundtrip(void)
@@ -359,7 +371,7 @@ static void t_reftable_index_record_roundtrip(void)
359371

360372
int cmd_main(int argc, const char *argv[])
361373
{
362-
TEST(t_reftable_log_record_equal(), "reftable_log_record_equal works");
374+
TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
363375
TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
364376
TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
365377
TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");

0 commit comments

Comments
 (0)