test-reach: add run_three_modes method
[git/raj.git] / t / t6600-test-reach.sh
blob9d65b8b946cc3c5afd21f3b7f0f0030810171bee
1 #!/bin/sh
3 test_description='basic commit reachability tests'
5 . ./test-lib.sh
7 # Construct a grid-like commit graph with points (x,y)
8 # with 1 <= x <= 10, 1 <= y <= 10, where (x,y) has
9 # parents (x-1, y) and (x, y-1), keeping in mind that
10 # we drop a parent if a coordinate is nonpositive.
12 # (10,10)
13 # / \
14 # (10,9) (9,10)
15 # / \ / \
16 # (10,8) (9,9) (8,10)
17 # / \ / \ / \
18 # ( continued...)
19 # \ / \ / \ /
20 # (3,1) (2,2) (1,3)
21 # \ / \ /
22 # (2,1) (2,1)
23 # \ /
24 # (1,1)
26 # We use branch 'commit-x-y' to refer to (x,y).
27 # This grid allows interesting reachability and
28 # non-reachability queries: (x,y) can reach (x',y')
29 # if and only if x' <= x and y' <= y.
30 test_expect_success 'setup' '
31 for i in $(test_seq 1 10)
33 test_commit "1-$i" &&
34 git branch -f commit-1-$i
35 done &&
36 for j in $(test_seq 1 9)
38 git reset --hard commit-$j-1 &&
39 x=$(($j + 1)) &&
40 test_commit "$x-1" &&
41 git branch -f commit-$x-1 &&
43 for i in $(test_seq 2 10)
45 git merge commit-$j-$i -m "$x-$i" &&
46 git branch -f commit-$x-$i
47 done
48 done &&
49 git commit-graph write --reachable &&
50 mv .git/objects/info/commit-graph commit-graph-full &&
51 git show-ref -s commit-5-5 | git commit-graph write --stdin-commits &&
52 mv .git/objects/info/commit-graph commit-graph-half &&
53 git config core.commitGraph true
56 run_three_modes () {
57 test_when_finished rm -rf .git/objects/info/commit-graph &&
58 "$@" <input >actual &&
59 test_cmp expect actual &&
60 cp commit-graph-full .git/objects/info/commit-graph &&
61 "$@" <input >actual &&
62 test_cmp expect actual &&
63 cp commit-graph-half .git/objects/info/commit-graph &&
64 "$@" <input >actual &&
65 test_cmp expect actual
68 test_three_modes () {
69 run_three_modes test-tool reach "$@"
72 test_expect_success 'ref_newer:miss' '
73 cat >input <<-\EOF &&
74 A:commit-5-7
75 B:commit-4-9
76 EOF
77 echo "ref_newer(A,B):0" >expect &&
78 test_three_modes ref_newer
81 test_expect_success 'ref_newer:hit' '
82 cat >input <<-\EOF &&
83 A:commit-5-7
84 B:commit-2-3
85 EOF
86 echo "ref_newer(A,B):1" >expect &&
87 test_three_modes ref_newer
90 test_expect_success 'in_merge_bases:hit' '
91 cat >input <<-\EOF &&
92 A:commit-5-7
93 B:commit-8-8
94 EOF
95 echo "in_merge_bases(A,B):1" >expect &&
96 test_three_modes in_merge_bases
99 test_expect_success 'in_merge_bases:miss' '
100 cat >input <<-\EOF &&
101 A:commit-6-8
102 B:commit-5-9
104 echo "in_merge_bases(A,B):0" >expect &&
105 test_three_modes in_merge_bases
108 test_expect_success 'is_descendant_of:hit' '
109 cat >input <<-\EOF &&
110 A:commit-5-7
111 X:commit-4-8
112 X:commit-6-6
113 X:commit-1-1
115 echo "is_descendant_of(A,X):1" >expect &&
116 test_three_modes is_descendant_of
119 test_expect_success 'is_descendant_of:miss' '
120 cat >input <<-\EOF &&
121 A:commit-6-8
122 X:commit-5-9
123 X:commit-4-10
124 X:commit-7-6
126 echo "is_descendant_of(A,X):0" >expect &&
127 test_three_modes is_descendant_of
130 test_expect_success 'get_merge_bases_many' '
131 cat >input <<-\EOF &&
132 A:commit-5-7
133 X:commit-4-8
134 X:commit-6-6
135 X:commit-8-3
138 echo "get_merge_bases_many(A,X):" &&
139 git rev-parse commit-5-6 \
140 commit-4-7 | sort
141 } >expect &&
142 test_three_modes get_merge_bases_many
145 test_expect_success 'reduce_heads' '
146 cat >input <<-\EOF &&
147 X:commit-1-10
148 X:commit-2-8
149 X:commit-3-6
150 X:commit-4-4
151 X:commit-1-7
152 X:commit-2-5
153 X:commit-3-3
154 X:commit-5-1
157 echo "reduce_heads(X):" &&
158 git rev-parse commit-5-1 \
159 commit-4-4 \
160 commit-3-6 \
161 commit-2-8 \
162 commit-1-10 | sort
163 } >expect &&
164 test_three_modes reduce_heads
167 test_expect_success 'can_all_from_reach:hit' '
168 cat >input <<-\EOF &&
169 X:commit-2-10
170 X:commit-3-9
171 X:commit-4-8
172 X:commit-5-7
173 X:commit-6-6
174 X:commit-7-5
175 X:commit-8-4
176 X:commit-9-3
177 Y:commit-1-9
178 Y:commit-2-8
179 Y:commit-3-7
180 Y:commit-4-6
181 Y:commit-5-5
182 Y:commit-6-4
183 Y:commit-7-3
184 Y:commit-8-1
186 echo "can_all_from_reach(X,Y):1" >expect &&
187 test_three_modes can_all_from_reach
190 test_expect_success 'can_all_from_reach:miss' '
191 cat >input <<-\EOF &&
192 X:commit-2-10
193 X:commit-3-9
194 X:commit-4-8
195 X:commit-5-7
196 X:commit-6-6
197 X:commit-7-5
198 X:commit-8-4
199 X:commit-9-3
200 Y:commit-1-9
201 Y:commit-2-8
202 Y:commit-3-7
203 Y:commit-4-6
204 Y:commit-5-5
205 Y:commit-6-4
206 Y:commit-8-5
208 echo "can_all_from_reach(X,Y):0" >expect &&
209 test_three_modes can_all_from_reach
212 test_expect_success 'commit_contains:hit' '
213 cat >input <<-\EOF &&
214 A:commit-7-7
215 X:commit-2-10
216 X:commit-3-9
217 X:commit-4-8
218 X:commit-5-7
219 X:commit-6-6
220 X:commit-7-5
221 X:commit-8-4
222 X:commit-9-3
224 echo "commit_contains(_,A,X,_):1" >expect &&
225 test_three_modes commit_contains &&
226 test_three_modes commit_contains --tag
229 test_expect_success 'commit_contains:miss' '
230 cat >input <<-\EOF &&
231 A:commit-6-5
232 X:commit-2-10
233 X:commit-3-9
234 X:commit-4-8
235 X:commit-5-7
236 X:commit-6-6
237 X:commit-7-5
238 X:commit-8-4
239 X:commit-9-3
241 echo "commit_contains(_,A,X,_):0" >expect &&
242 test_three_modes commit_contains &&
243 test_three_modes commit_contains --tag
246 test_done