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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jul 20, 2018 at 16:33 UTC 6255232ec13b038a48326135f2e479797cd0d1f9
2 files changed +30
t/helper/test-reach.c
+8
@@ -10,6 +10,7 @@ int cmd__reach(int ac, const char **av)
10 {
11 struct object_id oid_A, oid_B;
12 struct commit *A, *B;
13 + struct commit_list *X;
14 struct strbuf buf = STRBUF_INIT;
15 struct repository *r = the_repository;
16
@@ -19,6 +20,7 @@ int cmd__reach(int ac, const char **av)
20 exit(1);
21
22 A = B = NULL;
23 + X = NULL;
24
25 while (strbuf_getline(&buf, stdin) != EOF) {
26 struct object_id oid;
@@ -54,6 +56,10 @@ int cmd__reach(int ac, const char **av)
56 B = c;
57 break;
58
59 + case 'X':
60 + commit_list_insert(c, &X);
61 + break;
62 +
63 default:
64 die("unexpected start of line: %c", buf.buf[0]);
65 }
@@ -64,6 +70,8 @@ int cmd__reach(int ac, const char **av)
70 printf("%s(A,B):%d\n", av[1], ref_newer(&oid_A, &oid_B));
71 else if (!strcmp(av[1], "in_merge_bases"))
72 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));
75
76 exit(0);
77 }
t/t6600-test-reach.sh
+22
@@ -101,4 +101,26 @@ test_expect_success 'in_merge_bases:miss' '
101 test_three_modes in_merge_bases
102 '
103
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 +
126 test_done