Blame


1 d9bb8469 2023-04-20 mark #!/bin/sh
2 d9bb8469 2023-04-20 mark #
3 d9bb8469 2023-04-20 mark # Copyright (c) 2023 Mark Jamsek <mark@jamsek.dev>
4 d9bb8469 2023-04-20 mark #
5 d9bb8469 2023-04-20 mark # Permission to use, copy, modify, and distribute this software for any
6 d9bb8469 2023-04-20 mark # purpose with or without fee is hereby granted, provided that the above
7 d9bb8469 2023-04-20 mark # copyright notice and this permission notice appear in all copies.
8 d9bb8469 2023-04-20 mark #
9 d9bb8469 2023-04-20 mark # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 d9bb8469 2023-04-20 mark # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 d9bb8469 2023-04-20 mark # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 d9bb8469 2023-04-20 mark # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 d9bb8469 2023-04-20 mark # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 d9bb8469 2023-04-20 mark # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 d9bb8469 2023-04-20 mark # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 d9bb8469 2023-04-20 mark
17 d9bb8469 2023-04-20 mark . ./common.sh
18 d9bb8469 2023-04-20 mark
19 d9bb8469 2023-04-20 mark test_tree_basic()
20 d9bb8469 2023-04-20 mark {
21 d9bb8469 2023-04-20 mark test_init tree_basic 48 8
22 d9bb8469 2023-04-20 mark
23 d9bb8469 2023-04-20 mark local head_id=`git_show_head $testroot/repo`
24 d9bb8469 2023-04-20 mark
25 d9bb8469 2023-04-20 mark cat <<EOF >$TOG_TEST_SCRIPT
26 d9bb8469 2023-04-20 mark SCREENDUMP
27 d9bb8469 2023-04-20 mark EOF
28 d9bb8469 2023-04-20 mark
29 d9bb8469 2023-04-20 mark cat <<EOF >$testroot/view.expected
30 d9bb8469 2023-04-20 mark commit $head_id
31 d9bb8469 2023-04-20 mark [1/4] /
32 d9bb8469 2023-04-20 mark
33 d9bb8469 2023-04-20 mark alpha
34 d9bb8469 2023-04-20 mark beta
35 d9bb8469 2023-04-20 mark epsilon/
36 d9bb8469 2023-04-20 mark gamma/
37 d9bb8469 2023-04-20 mark
38 d9bb8469 2023-04-20 mark EOF
39 d9bb8469 2023-04-20 mark
40 d9bb8469 2023-04-20 mark cd $testroot/repo && tog tree
41 d9bb8469 2023-04-20 mark cmp -s $testroot/view.expected $testroot/view
42 d9bb8469 2023-04-20 mark ret=$?
43 d9bb8469 2023-04-20 mark if [ $ret -ne 0 ]; then
44 d9bb8469 2023-04-20 mark diff -u $testroot/view.expected $testroot/view
45 d9bb8469 2023-04-20 mark test_done "$testroot" "$ret"
46 d9bb8469 2023-04-20 mark return 1
47 d9bb8469 2023-04-20 mark fi
48 d9bb8469 2023-04-20 mark
49 d9bb8469 2023-04-20 mark test_done "$testroot" "$ret"
50 d9bb8469 2023-04-20 mark }
51 d9bb8469 2023-04-20 mark
52 d9bb8469 2023-04-20 mark test_tree_vsplit_blame()
53 d9bb8469 2023-04-20 mark {
54 d9bb8469 2023-04-20 mark test_init tree_vsplit_blame 120 8
55 d9bb8469 2023-04-20 mark
56 d9bb8469 2023-04-20 mark local head_id=`git_show_head $testroot/repo`
57 d9bb8469 2023-04-20 mark local head_id_truncated=`trim_obj_id 8 $head_id`
58 d9bb8469 2023-04-20 mark local head_id_short=`trim_obj_id 32 $head_id`
59 d9bb8469 2023-04-20 mark
60 d9bb8469 2023-04-20 mark cat <<EOF >$TOG_TEST_SCRIPT
61 d9bb8469 2023-04-20 mark KEY_ENTER
62 d9bb8469 2023-04-20 mark WAIT_FOR_UI wait for blame to finish
63 d9bb8469 2023-04-20 mark SCREENDUMP
64 d9bb8469 2023-04-20 mark EOF
65 d9bb8469 2023-04-20 mark
66 d9bb8469 2023-04-20 mark cat <<EOF >$testroot/view.expected
67 d9bb8469 2023-04-20 mark commit $head_id_truncated|commit $head_id
68 d9bb8469 2023-04-20 mark [1/4] / |[1/1] /alpha
69 d9bb8469 2023-04-20 mark |$head_id_short alpha
70 d9bb8469 2023-04-20 mark alpha |
71 d9bb8469 2023-04-20 mark beta |
72 d9bb8469 2023-04-20 mark epsilon/ |
73 d9bb8469 2023-04-20 mark gamma/ |
74 d9bb8469 2023-04-20 mark |
75 d9bb8469 2023-04-20 mark EOF
76 d9bb8469 2023-04-20 mark
77 d9bb8469 2023-04-20 mark cd $testroot/repo && tog tree
78 d9bb8469 2023-04-20 mark cmp -s $testroot/view.expected $testroot/view
79 d9bb8469 2023-04-20 mark ret=$?
80 d9bb8469 2023-04-20 mark if [ $ret -ne 0 ]; then
81 d9bb8469 2023-04-20 mark diff -u $testroot/view.expected $testroot/view
82 d9bb8469 2023-04-20 mark test_done "$testroot" "$ret"
83 d9bb8469 2023-04-20 mark return 1
84 d9bb8469 2023-04-20 mark fi
85 d9bb8469 2023-04-20 mark
86 d9bb8469 2023-04-20 mark test_done "$testroot" "$ret"
87 d9bb8469 2023-04-20 mark }
88 d9bb8469 2023-04-20 mark
89 d9bb8469 2023-04-20 mark test_tree_hsplit_blame()
90 d9bb8469 2023-04-20 mark {
91 d9bb8469 2023-04-20 mark test_init tree_hsplit_blame 48 24
92 d9bb8469 2023-04-20 mark
93 d9bb8469 2023-04-20 mark local head_id=`git_show_head $testroot/repo`
94 d9bb8469 2023-04-20 mark local head_id_truncated=`trim_obj_id 8 $head_id`
95 d9bb8469 2023-04-20 mark local head_id_short=`trim_obj_id 32 $head_id`
96 d9bb8469 2023-04-20 mark
97 d9bb8469 2023-04-20 mark cat <<EOF >$TOG_TEST_SCRIPT
98 d9bb8469 2023-04-20 mark j
99 d9bb8469 2023-04-20 mark KEY_ENTER
100 d9bb8469 2023-04-20 mark S toggle horizontal split
101 d9bb8469 2023-04-20 mark 4- 4x decrease blame split
102 d9bb8469 2023-04-20 mark WAIT_FOR_UI wait for blame to finish
103 d9bb8469 2023-04-20 mark SCREENDUMP
104 d9bb8469 2023-04-20 mark EOF
105 d9bb8469 2023-04-20 mark
106 d9bb8469 2023-04-20 mark cat <<EOF >$testroot/view.expected
107 d9bb8469 2023-04-20 mark commit $head_id
108 d9bb8469 2023-04-20 mark [2/4] /
109 d9bb8469 2023-04-20 mark
110 d9bb8469 2023-04-20 mark alpha
111 d9bb8469 2023-04-20 mark beta
112 d9bb8469 2023-04-20 mark epsilon/
113 d9bb8469 2023-04-20 mark gamma/
114 d9bb8469 2023-04-20 mark
115 d9bb8469 2023-04-20 mark
116 d9bb8469 2023-04-20 mark
117 d9bb8469 2023-04-20 mark ------------------------------------------------
118 d9bb8469 2023-04-20 mark commit $head_id
119 d9bb8469 2023-04-20 mark [1/1] /beta
120 d9bb8469 2023-04-20 mark $head_id_short beta
121 d9bb8469 2023-04-20 mark
122 d9bb8469 2023-04-20 mark
123 d9bb8469 2023-04-20 mark
124 d9bb8469 2023-04-20 mark
125 d9bb8469 2023-04-20 mark
126 d9bb8469 2023-04-20 mark
127 d9bb8469 2023-04-20 mark
128 d9bb8469 2023-04-20 mark
129 d9bb8469 2023-04-20 mark
130 d9bb8469 2023-04-20 mark
131 d9bb8469 2023-04-20 mark EOF
132 d9bb8469 2023-04-20 mark
133 d9bb8469 2023-04-20 mark cd $testroot/repo && tog tree
134 d9bb8469 2023-04-20 mark cmp -s $testroot/view.expected $testroot/view
135 d9bb8469 2023-04-20 mark ret=$?
136 d9bb8469 2023-04-20 mark if [ $ret -ne 0 ]; then
137 d9bb8469 2023-04-20 mark diff -u $testroot/view.expected $testroot/view
138 d9bb8469 2023-04-20 mark test_done "$testroot" "$ret"
139 d9bb8469 2023-04-20 mark return 1
140 d9bb8469 2023-04-20 mark fi
141 d9bb8469 2023-04-20 mark
142 d9bb8469 2023-04-20 mark test_done "$testroot" "$ret"
143 d9bb8469 2023-04-20 mark }
144 d9bb8469 2023-04-20 mark
145 98ec4245 2023-06-22 stsp test_tree_symlink()
146 98ec4245 2023-06-22 stsp {
147 98ec4245 2023-06-22 stsp test_init tree_symlink 48 8
148 98ec4245 2023-06-22 stsp
149 98ec4245 2023-06-22 stsp (cd $testroot/repo && ln -s alpha symlink)
150 98ec4245 2023-06-22 stsp (cd $testroot/repo && git add symlink)
151 98ec4245 2023-06-22 stsp git_commit $testroot/repo -m "symlink to alpha"
152 98ec4245 2023-06-22 stsp local head_id=`git_show_head $testroot/repo`
153 98ec4245 2023-06-22 stsp
154 98ec4245 2023-06-22 stsp cat <<EOF >$TOG_TEST_SCRIPT
155 98ec4245 2023-06-22 stsp SCREENDUMP
156 98ec4245 2023-06-22 stsp EOF
157 98ec4245 2023-06-22 stsp
158 98ec4245 2023-06-22 stsp cat <<EOF >$testroot/view.expected
159 98ec4245 2023-06-22 stsp commit $head_id
160 98ec4245 2023-06-22 stsp [1/5] /
161 98ec4245 2023-06-22 stsp
162 98ec4245 2023-06-22 stsp alpha
163 98ec4245 2023-06-22 stsp beta
164 98ec4245 2023-06-22 stsp epsilon/
165 98ec4245 2023-06-22 stsp gamma/
166 98ec4245 2023-06-22 stsp symlink@ -> alpha
167 98ec4245 2023-06-22 stsp EOF
168 98ec4245 2023-06-22 stsp
169 98ec4245 2023-06-22 stsp cd $testroot/repo && tog tree
170 98ec4245 2023-06-22 stsp cmp -s $testroot/view.expected $testroot/view
171 98ec4245 2023-06-22 stsp ret=$?
172 98ec4245 2023-06-22 stsp if [ $ret -ne 0 ]; then
173 98ec4245 2023-06-22 stsp diff -u $testroot/view.expected $testroot/view
174 98ec4245 2023-06-22 stsp test_done "$testroot" "$ret"
175 98ec4245 2023-06-22 stsp return 1
176 98ec4245 2023-06-22 stsp fi
177 98ec4245 2023-06-22 stsp
178 98ec4245 2023-06-22 stsp test_done "$testroot" "$ret"
179 98ec4245 2023-06-22 stsp }
180 98ec4245 2023-06-22 stsp
181 c4df265e 2023-07-19 mark test_tree_commit_keywords()
182 c4df265e 2023-07-19 mark {
183 c4df265e 2023-07-19 mark test_init tree_commit_keywords 48 11
184 c4df265e 2023-07-19 mark local repo="$testroot/repo"
185 c4df265e 2023-07-19 mark local wt="$testroot/wt"
186 c4df265e 2023-07-19 mark local id=$(git_show_head "$repo")
187 c4df265e 2023-07-19 mark
188 79c49d84 2023-07-24 mark set -- "$id"
189 c4df265e 2023-07-19 mark
190 c4df265e 2023-07-19 mark got checkout "$repo" "$wt" > /dev/null
191 c4df265e 2023-07-19 mark ret=$?
192 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
193 c4df265e 2023-07-19 mark echo "got checkout failed unexpectedly"
194 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
195 c4df265e 2023-07-19 mark return 1
196 c4df265e 2023-07-19 mark fi
197 c4df265e 2023-07-19 mark
198 c4df265e 2023-07-19 mark # move into the work tree (test is run in a subshell)
199 c4df265e 2023-07-19 mark cd "$wt"
200 c4df265e 2023-07-19 mark
201 c4df265e 2023-07-19 mark for i in $(seq 8); do
202 c4df265e 2023-07-19 mark if [ $(( i % 2 )) -eq 0 ]; then
203 c4df265e 2023-07-19 mark echo "file${i}" > "file${i}"
204 c4df265e 2023-07-19 mark got add "file${i}" > /dev/null
205 c4df265e 2023-07-19 mark else
206 c4df265e 2023-07-19 mark echo "alpha $i" > alpha
207 c4df265e 2023-07-19 mark fi
208 c4df265e 2023-07-19 mark
209 c4df265e 2023-07-19 mark got ci -m "commit $i" > /dev/null
210 c4df265e 2023-07-19 mark ret=$?
211 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
212 c4df265e 2023-07-19 mark echo "commit failed unexpectedly" >&2
213 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
214 c4df265e 2023-07-19 mark return 1
215 c4df265e 2023-07-19 mark fi
216 c4df265e 2023-07-19 mark
217 c4df265e 2023-07-19 mark id=$(git_show_head "$repo")
218 79c49d84 2023-07-24 mark set -- "$@" "$id"
219 c4df265e 2023-07-19 mark done
220 c4df265e 2023-07-19 mark
221 c4df265e 2023-07-19 mark
222 c4df265e 2023-07-19 mark cat <<-EOF >$TOG_TEST_SCRIPT
223 c4df265e 2023-07-19 mark SCREENDUMP
224 c4df265e 2023-07-19 mark EOF
225 c4df265e 2023-07-19 mark
226 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
227 79c49d84 2023-07-24 mark commit $(pop_idx 8 $@)
228 c4df265e 2023-07-19 mark [1/7] /
229 c4df265e 2023-07-19 mark
230 c4df265e 2023-07-19 mark alpha
231 c4df265e 2023-07-19 mark beta
232 c4df265e 2023-07-19 mark epsilon/
233 c4df265e 2023-07-19 mark file2
234 c4df265e 2023-07-19 mark file4
235 c4df265e 2023-07-19 mark file6
236 c4df265e 2023-07-19 mark gamma/
237 c4df265e 2023-07-19 mark
238 c4df265e 2023-07-19 mark EOF
239 c4df265e 2023-07-19 mark
240 c4df265e 2023-07-19 mark tog tree -c:base:-
241 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
242 c4df265e 2023-07-19 mark ret=$?
243 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
244 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
245 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
246 c4df265e 2023-07-19 mark return 1
247 c4df265e 2023-07-19 mark fi
248 c4df265e 2023-07-19 mark
249 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
250 79c49d84 2023-07-24 mark commit $(pop_idx 6 $@)
251 c4df265e 2023-07-19 mark [1/6] /
252 c4df265e 2023-07-19 mark
253 c4df265e 2023-07-19 mark alpha
254 c4df265e 2023-07-19 mark beta
255 c4df265e 2023-07-19 mark epsilon/
256 c4df265e 2023-07-19 mark file2
257 c4df265e 2023-07-19 mark file4
258 c4df265e 2023-07-19 mark gamma/
259 c4df265e 2023-07-19 mark
260 c4df265e 2023-07-19 mark
261 c4df265e 2023-07-19 mark EOF
262 c4df265e 2023-07-19 mark
263 c4df265e 2023-07-19 mark tog tree -cmaster:-3
264 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
265 c4df265e 2023-07-19 mark ret=$?
266 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
267 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
268 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
269 c4df265e 2023-07-19 mark return 1
270 c4df265e 2023-07-19 mark fi
271 c4df265e 2023-07-19 mark
272 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
273 79c49d84 2023-07-24 mark commit $(pop_idx 9 $@)
274 c4df265e 2023-07-19 mark [1/8] /
275 c4df265e 2023-07-19 mark
276 c4df265e 2023-07-19 mark alpha
277 c4df265e 2023-07-19 mark beta
278 c4df265e 2023-07-19 mark epsilon/
279 c4df265e 2023-07-19 mark file2
280 c4df265e 2023-07-19 mark file4
281 c4df265e 2023-07-19 mark file6
282 c4df265e 2023-07-19 mark file8
283 c4df265e 2023-07-19 mark gamma/
284 c4df265e 2023-07-19 mark EOF
285 c4df265e 2023-07-19 mark
286 c4df265e 2023-07-19 mark got up -c:head:-99 > /dev/null
287 c4df265e 2023-07-19 mark tog tree -c:base:+99
288 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
289 c4df265e 2023-07-19 mark ret=$?
290 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
291 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
292 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
293 c4df265e 2023-07-19 mark return 1
294 c4df265e 2023-07-19 mark fi
295 c4df265e 2023-07-19 mark
296 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
297 79c49d84 2023-07-24 mark commit $(pop_idx 4 $@)
298 c4df265e 2023-07-19 mark [1/5] /
299 c4df265e 2023-07-19 mark
300 c4df265e 2023-07-19 mark alpha
301 c4df265e 2023-07-19 mark beta
302 c4df265e 2023-07-19 mark epsilon/
303 c4df265e 2023-07-19 mark file2
304 c4df265e 2023-07-19 mark gamma/
305 c4df265e 2023-07-19 mark
306 c4df265e 2023-07-19 mark
307 c4df265e 2023-07-19 mark
308 c4df265e 2023-07-19 mark EOF
309 c4df265e 2023-07-19 mark
310 c4df265e 2023-07-19 mark tog tree -c:head:-5
311 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
312 c4df265e 2023-07-19 mark ret=$?
313 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
314 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
315 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
316 c4df265e 2023-07-19 mark return 1
317 c4df265e 2023-07-19 mark fi
318 c4df265e 2023-07-19 mark
319 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
320 79c49d84 2023-07-24 mark commit $(pop_idx 1 $@)
321 c4df265e 2023-07-19 mark [1/4] /
322 c4df265e 2023-07-19 mark
323 c4df265e 2023-07-19 mark alpha
324 c4df265e 2023-07-19 mark beta
325 c4df265e 2023-07-19 mark epsilon/
326 c4df265e 2023-07-19 mark gamma/
327 c4df265e 2023-07-19 mark
328 c4df265e 2023-07-19 mark
329 c4df265e 2023-07-19 mark
330 c4df265e 2023-07-19 mark
331 c4df265e 2023-07-19 mark EOF
332 c4df265e 2023-07-19 mark
333 c4df265e 2023-07-19 mark tog tree -r "$repo" -cmaster:-99
334 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
335 c4df265e 2023-07-19 mark ret=$?
336 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
337 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
338 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
339 c4df265e 2023-07-19 mark return 1
340 c4df265e 2023-07-19 mark fi
341 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
342 c4df265e 2023-07-19 mark }
343 c4df265e 2023-07-19 mark
344 d9bb8469 2023-04-20 mark test_parseargs "$@"
345 d9bb8469 2023-04-20 mark run_test test_tree_basic
346 d9bb8469 2023-04-20 mark run_test test_tree_vsplit_blame
347 d9bb8469 2023-04-20 mark run_test test_tree_hsplit_blame
348 98ec4245 2023-06-22 stsp run_test test_tree_symlink
349 c4df265e 2023-07-19 mark run_test test_tree_commit_keywords