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 -- "$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 -- "$@" "$id"
219 done
222 cat <<-EOF >$TOG_TEST_SCRIPT
223 SCREENDUMP
224 EOF
226 cat <<-EOF >$testroot/view.expected
227 commit $(pop_idx 8 $@)
228 [1/7] /
230 alpha
231 beta
232 epsilon/
233 file2
234 file4
235 file6
236 gamma/
238 EOF
240 tog tree -c:base:-
241 cmp -s $testroot/view.expected $testroot/view
242 ret=$?
243 if [ $ret -ne 0 ]; then
244 diff -u $testroot/view.expected $testroot/view
245 test_done "$testroot" "$ret"
246 return 1
247 fi
249 cat <<-EOF >$testroot/view.expected
250 commit $(pop_idx 6 $@)
251 [1/6] /
253 alpha
254 beta
255 epsilon/
256 file2
257 file4
258 gamma/
261 EOF
263 tog tree -cmaster:-3
264 cmp -s $testroot/view.expected $testroot/view
265 ret=$?
266 if [ $ret -ne 0 ]; then
267 diff -u $testroot/view.expected $testroot/view
268 test_done "$testroot" "$ret"
269 return 1
270 fi
272 cat <<-EOF >$testroot/view.expected
273 commit $(pop_idx 9 $@)
274 [1/8] /
276 alpha
277 beta
278 epsilon/
279 file2
280 file4
281 file6
282 file8
283 gamma/
284 EOF
286 got up -c:head:-99 > /dev/null
287 tog tree -c:base:+99
288 cmp -s $testroot/view.expected $testroot/view
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 diff -u $testroot/view.expected $testroot/view
292 test_done "$testroot" "$ret"
293 return 1
294 fi
296 cat <<-EOF >$testroot/view.expected
297 commit $(pop_idx 4 $@)
298 [1/5] /
300 alpha
301 beta
302 epsilon/
303 file2
304 gamma/
308 EOF
310 tog tree -c:head:-5
311 cmp -s $testroot/view.expected $testroot/view
312 ret=$?
313 if [ $ret -ne 0 ]; then
314 diff -u $testroot/view.expected $testroot/view
315 test_done "$testroot" "$ret"
316 return 1
317 fi
319 cat <<-EOF >$testroot/view.expected
320 commit $(pop_idx 1 $@)
321 [1/4] /
323 alpha
324 beta
325 epsilon/
326 gamma/
331 EOF
333 tog tree -r "$repo" -cmaster:-99
334 cmp -s $testroot/view.expected $testroot/view
335 ret=$?
336 if [ $ret -ne 0 ]; then
337 diff -u $testroot/view.expected $testroot/view
338 test_done "$testroot" "$ret"
339 return 1
340 fi
341 test_done "$testroot" "$ret"
344 test_parseargs "$@"
345 run_test test_tree_basic
346 run_test test_tree_vsplit_blame
347 run_test test_tree_hsplit_blame
348 run_test test_tree_symlink
349 run_test test_tree_commit_keywords