3 # Copyright (c) 2023 Mark Jamsek <mark@jamsek.dev>
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.
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.
19 test_log_hsplit_diff()
21 test_init log_hsplit_diff
23 local head_id=`git_show_head $testroot/repo`
24 local author_time=`git_show_author_time $testroot/repo`
25 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
26 local ymd=`date -u -r $author_time +"%G-%m-%d"`
28 cat <<EOF >$TOG_TEST_SCRIPT
29 KEY_ENTER open diff view of selected commit
30 S toggle horizontal split
34 cat <<EOF >$testroot/view.expected
35 commit $head_id [1/1] master
36 $ymd flan_hacker [master] adding the test tree
41 --------------------------------------------------------------------------------
42 [1/40] diff /dev/null $head_id
43 commit $head_id (master)
44 from: Flan Hacker <flan_hacker@openbsd.org>
51 A epsilon/zeta | 1+ 0-
54 4 files changed, 4 insertions(+), 0 deletions(-)
61 cd $testroot/repo && tog log
62 cmp -s $testroot/view.expected $testroot/view
64 if [ $ret -ne 0 ]; then
65 diff -u $testroot/view.expected $testroot/view
66 test_done "$testroot" "$ret"
70 test_done "$testroot" "$ret"
73 test_log_vsplit_diff()
75 # make screen wide enough for vsplit
76 test_init log_vsplit_diff 142
78 local head_id=`git_show_head $testroot/repo`
79 local author_time=`git_show_author_time $testroot/repo`
80 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
81 local ymd=`date -u -r $author_time +"%G-%m-%d"`
82 local blobid_alpha=`get_blob_id $testroot/repo "" alpha`
83 local blobid_beta=`get_blob_id $testroot/repo "" beta`
85 cat <<EOF >$TOG_TEST_SCRIPT
86 KEY_ENTER open diff view of selected commit in vertical split
90 cat <<EOF >$testroot/view.expected
91 commit $head_id [1/1] master |[1/40] diff /dev/null $head_id
92 $ymd flan_hacker [master] adding the test tree |commit $head_id (master)
93 |from: Flan Hacker <flan_hacker@openbsd.org>
100 |A epsilon/zeta | 1+ 0-
101 |A gamma/delta | 1+ 0-
103 |4 files changed, 4 insertions(+), 0 deletions(-)
108 |blob + $blobid_alpha (mode 644)
114 |blob + $blobid_beta (mode 644)
117 cd $testroot/repo && tog log
118 cmp -s $testroot/view.expected $testroot/view
120 if [ $ret -ne 0 ]; then
121 diff -u $testroot/view.expected $testroot/view
122 test_done "$testroot" "$ret"
126 test_done "$testroot" "$ret"
129 test_log_show_author()
131 # make view wide enough to show id
132 test_init log_show_author 120 4
134 local head_id=`git_show_head $testroot/repo`
135 local author_time=`git_show_author_time $testroot/repo`
136 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
137 local ymd=`date -u -r $author_time +"%G-%m-%d"`
138 local head_id_len8=`trim_obj_id 32 $head_id`
140 echo "mod alpha" > $testroot/repo/alpha
141 cd $testroot/repo && git add .
142 cd $testroot/repo && \
143 git commit --author "Johnny Cash <john@cash.net>" -m author > \
146 local commit1=`git_show_head $testroot/repo`
147 local id1_len8=`trim_obj_id 32 $commit1`
149 cat <<EOF >$TOG_TEST_SCRIPT
154 cat <<EOF >$testroot/view.expected
155 commit $commit1 [1/2] master
156 $ymd $id1_len8 john [master] author
157 $ymd $head_id_len8 flan_hacker adding the test tree
161 cd $testroot/repo && tog log
162 cmp -s $testroot/view.expected $testroot/view
164 if [ $ret -ne 0 ]; then
165 diff -u $testroot/view.expected $testroot/view
166 test_done "$testroot" "$ret"
170 test_done "$testroot" "$ret"
173 test_log_scroll_right()
175 test_init log_scroll_right 80 3
177 local head_id=`git_show_head $testroot/repo`
178 local author_time=`git_show_author_time $testroot/repo`
179 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
180 local ymd=`date -u -r $author_time +"%G-%m-%d"`
181 local msg="scroll this log message to the right four characters"
182 local scrolled_msg="ter] scroll this log message to the right four character"
184 echo "mod alpha" > $testroot/repo/alpha
185 cd $testroot/repo && git add . && git commit -m "$msg" > /dev/null
187 local commit1=`git_show_head $testroot/repo`
189 cat <<EOF >$TOG_TEST_SCRIPT
195 cat <<EOF >$testroot/view.expected
196 commit $commit1 [1/2] master
197 $ymd flan_hacker $scrolled_msg
198 $ymd flan_hacker ng the test tree
201 cd $testroot/repo && tog log
202 cmp -s $testroot/view.expected $testroot/view
204 if [ $ret -ne 0 ]; then
205 diff -u $testroot/view.expected $testroot/view
206 test_done "$testroot" "$ret"
210 test_done "$testroot" "$ret"
213 test_log_hsplit_ref()
215 test_init log_hsplit_ref 80 10
217 local head_id=`git_show_head $testroot/repo`
218 local author_time=`git_show_author_time $testroot/repo`
219 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
220 local ymd=`date -u -r $author_time +"%G-%m-%d"`
222 cat <<EOF >$TOG_TEST_SCRIPT
224 S toggle horizontal split
225 - reduce size of ref view split
229 cat <<EOF >$testroot/view.expected
230 commit $head_id [1/1] master
231 $ymd flan_hacker [master] adding the test tree
233 --------------------------------------------------------------------------------
235 HEAD -> refs/heads/master
242 cd $testroot/repo && tog log
243 cmp -s $testroot/view.expected $testroot/view
245 if [ $ret -ne 0 ]; then
246 diff -u $testroot/view.expected $testroot/view
247 test_done "$testroot" "$ret"
251 test_done "$testroot" "$ret"
254 test_log_hsplit_tree()
256 test_init log_hsplit_tree 80 10
258 local head_id=`git_show_head $testroot/repo`
259 local author_time=`git_show_author_time $testroot/repo`
260 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
261 local ymd=`date -u -r $author_time +"%G-%m-%d"`
263 cat <<EOF >$TOG_TEST_SCRIPT
265 S toggle horizontal split
266 j move selection cursor down one entry to "beta"
267 - reduce size of tree view split
271 cat <<EOF >$testroot/view.expected
272 commit $head_id [1/1] master
273 $ymd flan_hacker [master] adding the test tree
275 --------------------------------------------------------------------------------
284 cd $testroot/repo && tog log
285 cmp -s $testroot/view.expected $testroot/view
287 if [ $ret -ne 0 ]; then
288 diff -u $testroot/view.expected $testroot/view
289 test_done "$testroot" "$ret"
293 test_done "$testroot" "$ret"
296 test_log_logmsg_widechar()
298 # make view wide enough to fit logmsg line length
299 # but short enough so long diff lines are truncated
300 test_init log_logmsg_widechar 182 30
301 widechar_commit $testroot/repo
303 local head_id=`git_show_head $testroot/repo`
304 local author_time=`git_show_author_time $testroot/repo`
305 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
306 local commit1=`git_show_parent_commit $testroot/repo`
307 local blobid=`get_blob_id $testroot/repo "" $(widechar_filename)`
309 cat <<EOF >$TOG_TEST_SCRIPT
310 KEY_ENTER open selected commit in diff view
315 cat <<EOF >$testroot/view.expected
316 [1/26] diff $commit1 $head_id
317 commit $head_id (master)
318 from: Flan Hacker <flan_hacker@openbsd.org>
323 A $(widechar_filename) | 5+ 0-
325 1 file changed, 5 insertions(+), 0 deletions(-)
330 blob + $blobid (mode 644)
332 +++ $(widechar_filename)
334 +ウィリアム・ユワート・グラッドストン(英語: William Ewart Gladstone PC FRS FSS、1809年12月29日 - 1898年5月19日)は、イギリスの政治家。
336 +ヴィクトリア朝中期から後期にかけて、自由党を指導して、4度にわたり首相を務めた。
338 +生涯を通じて敬虔なイングランド国教会の信徒であり、キリスト教の精神を政治に反映させることを目指した。多くの自由主義改革を行い、帝国主義にも批判的であった。好敵手である保守党党首ベン
345 cd $testroot/repo && tog log
346 cmp -s $testroot/view.expected $testroot/view
348 if [ $ret -ne 0 ]; then
349 diff -u $testroot/view.expected $testroot/view
350 test_done "$testroot" "$ret"
354 test_done "$testroot" "$ret"
357 test_log_commit_keywords()
359 test_init log_commit_keywords 120 10
360 local repo="$testroot/repo"
361 local wt="$testroot/wt"
362 local id=$(git_show_head "$repo")
363 local author_time=$(git_show_author_time "$repo")
364 local ymd=$(date -u -r $author_time +"%G-%m-%d")
367 set -A short_ids "$(trim_obj_id 32 $id)"
369 got checkout "$repo" "$wt" > /dev/null
371 if [ $ret -ne 0 ]; then
372 echo "got checkout failed unexpectedly"
373 test_done "$testroot" "$ret"
377 # move into the work tree (test is run in a subshell)
381 for i in $(seq 8); do
382 echo "alpha $i" >> alpha
384 got ci -m "commit $i" > /dev/null
386 if [ $ret -ne 0 ]; then
387 echo "commit failed unexpectedly" >&2
388 test_done "$testroot" "$ret"
392 id=$(git_show_head "$repo")
395 set -- "$short_ids" "$(trim_obj_id 32 $id)"
399 cat <<-EOF >$TOG_TEST_SCRIPT
403 cat <<-EOF >$testroot/view.expected
404 commit $(pop_id 5 $ids) [1/5]
405 $ymd $(pop_id 5 $short_ids) flan_hacker commit 4
406 $ymd $(pop_id 4 $short_ids) flan_hacker commit 3
407 $ymd $(pop_id 3 $short_ids) flan_hacker commit 2
408 $ymd $(pop_id 2 $short_ids) flan_hacker commit 1
409 $ymd $(pop_id 1 $short_ids) flan_hacker adding the test tree
417 cmp -s "$testroot/view.expected" "$testroot/view"
419 if [ $ret -ne 0 ]; then
420 diff -u "$testroot/view.expected" "$testroot/view"
421 test_done "$testroot" "$ret"
425 cat <<-EOF >$testroot/view.expected
426 commit $(pop_id 7 $ids) [1/7]
427 $ymd $(pop_id 7 $short_ids) flan_hacker commit 6
428 $ymd $(pop_id 6 $short_ids) flan_hacker commit 5
429 $ymd $(pop_id 5 $short_ids) flan_hacker commit 4
430 $ymd $(pop_id 4 $short_ids) flan_hacker commit 3
431 $ymd $(pop_id 3 $short_ids) flan_hacker commit 2
432 $ymd $(pop_id 2 $short_ids) flan_hacker commit 1
433 $ymd $(pop_id 1 $short_ids) flan_hacker adding the test tree
438 tog log -r "$repo" -c:head:-2
439 cmp -s "$testroot/view.expected" "$testroot/view"
441 if [ $ret -ne 0 ]; then
442 diff -u "$testroot/view.expected" "$testroot/view"
443 test_done "$testroot" "$ret"
447 cat <<-EOF >$testroot/view.expected
448 commit $(pop_id 5 $ids) [1/5]
449 $ymd $(pop_id 5 $short_ids) flan_hacker commit 4
450 $ymd $(pop_id 4 $short_ids) flan_hacker commit 3
451 $ymd $(pop_id 3 $short_ids) flan_hacker commit 2
452 $ymd $(pop_id 2 $short_ids) flan_hacker commit 1
453 $ymd $(pop_id 1 $short_ids) flan_hacker adding the test tree
460 got up -c:base:-6 > /dev/null
462 if [ $ret -ne 0 ]; then
463 echo "got update failed unexpectedly"
464 test_done "$testroot" "$ret"
469 cmp -s "$testroot/view.expected" "$testroot/view"
471 if [ $ret -ne 0 ]; then
472 diff -u "$testroot/view.expected" "$testroot/view"
473 test_done "$testroot" "$ret"
477 cat <<-EOF >$testroot/view.expected
478 commit $(pop_id 1 $ids) [1/1]
479 $ymd $(pop_id 1 $short_ids) flan_hacker adding the test tree
491 cmp -s "$testroot/view.expected" "$testroot/view"
493 if [ $ret -ne 0 ]; then
494 diff -u "$testroot/view.expected" "$testroot/view"
495 test_done "$testroot" "$ret"
499 test_done "$testroot" "$ret"
503 run_test test_log_hsplit_diff
504 run_test test_log_vsplit_diff
505 run_test test_log_show_author
506 run_test test_log_scroll_right
507 run_test test_log_hsplit_ref
508 run_test test_log_hsplit_tree
509 run_test test_log_logmsg_widechar
510 run_test test_log_commit_keywords