From: Derrick Stolee <dsto...@microsoft.com>

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 <dsto...@microsoft.com>
---
 t/helper/test-reach.c |  8 ++++++++
 t/t6600-test-reach.sh | 22 ++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 29104d41a..149e8f32c 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -9,6 +9,7 @@ int cmd__reach(int ac, const char **av)
 {
        struct object_id oid_A, oid_B;
        struct commit *A, *B;
+       struct commit_list *X;
        struct strbuf buf = STRBUF_INIT;
        struct repository *r = the_repository;
 
@@ -18,6 +19,7 @@ int cmd__reach(int ac, const char **av)
                exit(1);
 
        A = B = NULL;
+       X = NULL;
 
        while (strbuf_getline(&buf, stdin) != EOF) {
                struct object_id oid;
@@ -53,6 +55,10 @@ int cmd__reach(int ac, const char **av)
                                B = c;
                                break;
 
+                       case 'X':
+                               commit_list_insert(c, &X);
+                               break;
+
                        default:
                                die("unexpected start of line: %c", buf.buf[0]);
                }
@@ -63,6 +69,8 @@ int cmd__reach(int ac, const char **av)
                printf("%s:%d\n", av[1], ref_newer(&oid_A, &oid_B));
        else if (!strcmp(av[1], "in_merge_bases"))
                printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B));
+       else if (!strcmp(av[1], "is_descendant_of"))
+               printf("%s(A,X):%d\n", av[1], is_descendant_of(A, X));
 
        exit(0);
 }
diff --git a/t/t6600-test-reach.sh b/t/t6600-test-reach.sh
index d065f2602..99444e0f7 100755
--- a/t/t6600-test-reach.sh
+++ b/t/t6600-test-reach.sh
@@ -101,4 +101,26 @@ test_expect_success 'in_merge_bases:miss' '
        test_three_modes in_merge_bases
 '
 
+test_expect_success 'is_descendant_of:hit' '
+       cat >input <<-\EOF &&
+               A:commit-5-7
+               X:commit-4-8
+               X:commit-6-6
+               X:commit-1-1
+       EOF
+       printf "is_descendant_of(A,X):1\n" >expect &&
+       test_three_modes is_descendant_of
+'
+
+test_expect_success 'is_descendant_of:miss' '
+       cat >input <<-\EOF &&
+               A:commit-6-8
+               X:commit-5-9
+               X:commit-4-10
+               X:commit-7-6
+       EOF
+       printf "is_descendant_of(A,X):0\n" >expect &&
+       test_three_modes is_descendant_of
+'
+
 test_done
-- 
gitgitgadget

Reply via email to