Skip to content

Commit 6255232

Browse files
derrickstoleegitster
authored andcommitted
test-reach: test is_descendant_of
The is_descendant_of method takes a single commit as its first parameter and a list of commits as its second parameter. Extend the input of the 'test-tool reach' command to take multiple lines of the form "X:<committish>" to construct a list of commits. Pass these to is_descendant_of and create tests that check each result. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5cd52de commit 6255232

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

t/helper/test-reach.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ int cmd__reach(int ac, const char **av)
1010
{
1111
struct object_id oid_A, oid_B;
1212
struct commit *A, *B;
13+
struct commit_list *X;
1314
struct strbuf buf = STRBUF_INIT;
1415
struct repository *r = the_repository;
1516

@@ -19,6 +20,7 @@ int cmd__reach(int ac, const char **av)
1920
exit(1);
2021

2122
A = B = NULL;
23+
X = NULL;
2224

2325
while (strbuf_getline(&buf, stdin) != EOF) {
2426
struct object_id oid;
@@ -54,6 +56,10 @@ int cmd__reach(int ac, const char **av)
5456
B = c;
5557
break;
5658

59+
case 'X':
60+
commit_list_insert(c, &X);
61+
break;
62+
5763
default:
5864
die("unexpected start of line: %c", buf.buf[0]);
5965
}
@@ -64,6 +70,8 @@ int cmd__reach(int ac, const char **av)
6470
printf("%s(A,B):%d\n", av[1], ref_newer(&oid_A, &oid_B));
6571
else if (!strcmp(av[1], "in_merge_bases"))
6672
printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B));
73+
else if (!strcmp(av[1], "is_descendant_of"))
74+
printf("%s(A,X):%d\n", av[1], is_descendant_of(A, X));
6775

6876
exit(0);
6977
}

t/t6600-test-reach.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,26 @@ test_expect_success 'in_merge_bases:miss' '
101101
test_three_modes in_merge_bases
102102
'
103103

104+
test_expect_success 'is_descendant_of:hit' '
105+
cat >input <<-\EOF &&
106+
A:commit-5-7
107+
X:commit-4-8
108+
X:commit-6-6
109+
X:commit-1-1
110+
EOF
111+
echo "is_descendant_of(A,X):1" >expect &&
112+
test_three_modes is_descendant_of
113+
'
114+
115+
test_expect_success 'is_descendant_of:miss' '
116+
cat >input <<-\EOF &&
117+
A:commit-6-8
118+
X:commit-5-9
119+
X:commit-4-10
120+
X:commit-7-6
121+
EOF
122+
echo "is_descendant_of(A,X):0" >expect &&
123+
test_three_modes is_descendant_of
124+
'
125+
104126
test_done

0 commit comments

Comments
 (0)