Blob


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