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 +"%F"`
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 +"%F"`
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 +"%F"`
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 +"%F"`
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 +"%F"`
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 +"%F"`
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 +"%F")
368 got checkout "$repo" "$wt" > /dev/null
370 if [ $ret -ne 0 ]; then
371 echo "got checkout failed unexpectedly"
372 test_done "$testroot" "$ret"
376 # move into the work tree (test is run in a subshell)
380 for i in $(seq 8); do
381 echo "alpha $i" >> alpha
383 got ci -m "commit $i" > /dev/null
385 if [ $ret -ne 0 ]; then
386 echo "commit failed unexpectedly" >&2
387 test_done "$testroot" "$ret"
391 id=$(git_show_head "$repo")
395 cat <<-EOF >$TOG_TEST_SCRIPT
396 WAIT_FOR_UI wait for log thread to finish
400 cat <<-EOF >$testroot/view.expected
401 commit $(pop_idx 5 $@) [1/5]
402 $ymd $(trim_obj_id 32 $(pop_idx 5 $@)) flan_hacker commit 4
403 $ymd $(trim_obj_id 32 $(pop_idx 4 $@)) flan_hacker commit 3
404 $ymd $(trim_obj_id 32 $(pop_idx 3 $@)) flan_hacker commit 2
405 $ymd $(trim_obj_id 32 $(pop_idx 2 $@)) flan_hacker commit 1
406 $ymd $(trim_obj_id 32 $(pop_idx 1 $@)) flan_hacker adding the test tree
414 cmp -s "$testroot/view.expected" "$testroot/view"
416 if [ $ret -ne 0 ]; then
417 diff -u "$testroot/view.expected" "$testroot/view"
418 test_done "$testroot" "$ret"
422 cat <<-EOF >$testroot/view.expected
423 commit $(pop_idx 7 $@) [1/7]
424 $ymd $(trim_obj_id 32 $(pop_idx 7 $@)) flan_hacker commit 6
425 $ymd $(trim_obj_id 32 $(pop_idx 6 $@)) flan_hacker commit 5
426 $ymd $(trim_obj_id 32 $(pop_idx 5 $@)) flan_hacker commit 4
427 $ymd $(trim_obj_id 32 $(pop_idx 4 $@)) flan_hacker commit 3
428 $ymd $(trim_obj_id 32 $(pop_idx 3 $@)) flan_hacker commit 2
429 $ymd $(trim_obj_id 32 $(pop_idx 2 $@)) flan_hacker commit 1
430 $ymd $(trim_obj_id 32 $(pop_idx 1 $@)) flan_hacker adding the test tree
435 tog log -r "$repo" -c:head:-2
436 cmp -s "$testroot/view.expected" "$testroot/view"
438 if [ $ret -ne 0 ]; then
439 diff -u "$testroot/view.expected" "$testroot/view"
440 test_done "$testroot" "$ret"
444 cat <<-EOF >$testroot/view.expected
445 commit $(pop_idx 5 $@) [1/5]
446 $ymd $(trim_obj_id 32 $(pop_idx 5 $@)) flan_hacker commit 4
447 $ymd $(trim_obj_id 32 $(pop_idx 4 $@)) flan_hacker commit 3
448 $ymd $(trim_obj_id 32 $(pop_idx 3 $@)) flan_hacker ~commit 2
449 $ymd $(trim_obj_id 32 $(pop_idx 2 $@)) flan_hacker commit 1
450 $ymd $(trim_obj_id 32 $(pop_idx 1 $@)) flan_hacker adding the test tree
457 got up -c:base:-6 > /dev/null
459 if [ $ret -ne 0 ]; then
460 echo "got update failed unexpectedly"
461 test_done "$testroot" "$ret"
466 cmp -s "$testroot/view.expected" "$testroot/view"
468 if [ $ret -ne 0 ]; then
469 diff -u "$testroot/view.expected" "$testroot/view"
470 test_done "$testroot" "$ret"
474 cat <<-EOF >$testroot/view.expected
475 commit $(pop_idx 1 $@) [1/1]
476 $ymd $(trim_obj_id 32 $(pop_idx 1 $@)) flan_hacker adding the test tree
488 cmp -s "$testroot/view.expected" "$testroot/view"
490 if [ $ret -ne 0 ]; then
491 diff -u "$testroot/view.expected" "$testroot/view"
492 test_done "$testroot" "$ret"
496 test_done "$testroot" "$ret"
499 test_log_show_base_commit()
501 # make view wide enough to show full headline
502 test_init log_show_base_commit 80 3
503 local repo="$testroot/repo"
504 local id=$(git_show_head "$repo")
506 echo "alpha" >> "$repo/alpha"
507 git_commit "$repo" -m "base commit"
509 got checkout "$repo" "$testroot/wt" > /dev/null
511 if [ $ret -ne 0 ]; then
512 echo "got checkout failed unexpectedly"
513 test_done "$testroot" "$ret"
517 # move into the work tree (test is run in a subshell)
520 local head_id=$(git_show_head "$repo")
521 local author_time=$(git_show_author_time "$repo")
522 local ymd=$(date -u -r "$author_time" +"%F")
524 # check up-to-date base commit marker prefixes base commit log message
525 cat <<-EOF >$TOG_TEST_SCRIPT
526 WAIT_FOR_UI wait for log thread to finish
530 cat <<-EOF >$testroot/view.expected
531 commit $head_id [1/2] master
532 $ymd flan_hacker *[master] base commit
533 $ymd flan_hacker adding the test tree
537 cmp -s "$testroot/view.expected" "$testroot/view"
539 if [ $ret -ne 0 ]; then
540 diff -u "$testroot/view.expected" "$testroot/view"
541 test_done "$testroot" "$ret"
545 # check marker is not drawn when not in a work tree
546 cat <<-EOF >$testroot/view.expected
547 commit $head_id [1/2] master
548 $ymd flan_hacker [master] base commit
549 $ymd flan_hacker adding the test tree
553 cmp -s "$testroot/view.expected" "$testroot/view"
555 if [ $ret -ne 0 ]; then
556 diff -u "$testroot/view.expected" "$testroot/view"
557 test_done "$testroot" "$ret"
561 # check out-of-date marker is shown with a mixed-commit tree
563 got commit -m "new base mixed-commit" > /dev/null
564 head_id=$(git_show_head "$repo")
566 cat <<-EOF >$TOG_TEST_SCRIPT
567 WAIT_FOR_UI wait for log thread to finish
571 cat <<-EOF >$testroot/view.expected
572 commit $head_id [1/3] master
573 $ymd flan_hacker ~[master] new base mixed-commit
574 $ymd flan_hacker base commit
578 cmp -s "$testroot/view.expected" "$testroot/view"
580 if [ $ret -ne 0 ]; then
581 diff -u "$testroot/view.expected" "$testroot/view"
582 test_done "$testroot" "$ret"
586 test_done "$testroot" "$ret"
589 test_log_limit_view()
591 test_init log_limit_view 80 4
592 local repo="$testroot/repo"
593 local wt="$testroot/wt"
595 got checkout "$repo" "$wt" > /dev/null
597 if [ $ret -ne 0 ]; then
598 echo "got checkout failed unexpectedly"
599 test_done "$testroot" "$ret"
605 echo "alpha0" > alpha
606 got commit -m alpha0 > /dev/null
608 if [ $ret -ne 0 ]; then
609 echo "got commit failed unexpectedly" >&2
610 test_done "$testroot" "$ret"
615 got commit -m beta0 > /dev/null
617 if [ $ret -ne 0 ]; then
618 echo "got commit failed unexpectedly" >&2
619 test_done "$testroot" "$ret"
623 echo "alpha1" > alpha
624 got commit -m alpha1 > /dev/null
626 if [ $ret -ne 0 ]; then
627 echo "got commit failed unexpectedly" >&2
628 test_done "$testroot" "$ret"
633 got commit -m beta1 > /dev/null
635 if [ $ret -ne 0 ]; then
636 echo "got commit failed unexpectedly" >&2
637 test_done "$testroot" "$ret"
640 local author_time=$(git_show_author_time "$repo")
641 local ymd=$(date -u -r $author_time +"%F")
642 local id=$(git_show_head "$repo")
644 # check base commit marker is not drawn
645 cat <<-EOF >$TOG_TEST_SCRIPT
650 cat <<-EOF >$testroot/view.expected
651 commit $id [1/2] master
652 $ymd flan_hacker [master] beta1
653 $ymd flan_hacker beta0
658 cmp -s "$testroot/view.expected" "$testroot/view"
660 if [ $ret -ne 0 ]; then
661 diff -u "$testroot/view.expected" "$testroot/view"
663 test_done "$testroot" "$ret"
668 test_init log_search 80 8
669 local repo="$testroot/repo"
670 local wt="$testroot/wt"
671 local id=$(git_show_head "$repo")
675 got checkout "$repo" "$wt" > /dev/null
677 if [ $ret -ne 0 ]; then
678 echo "got checkout failed unexpectedly"
679 test_done "$testroot" "$ret"
685 for i in $(seq 16); do
686 echo "alpha $i" > alpha
688 got ci -m "alpha commit $i" > /dev/null
690 if [ $ret -ne 0 ]; then
691 echo "got commit failed unexpectedly" >&2
692 test_done "$testroot" "$ret"
696 id=$(git_show_head "$repo")
700 local author_time=$(git_show_author_time "$repo")
701 local ymd=$(date -u -r $author_time +"%F")
703 cat <<-EOF >$TOG_TEST_SCRIPT
709 cat <<-EOF >$testroot/view.expected
710 commit $(pop_idx 9 $@) [9/17] no more matches
711 $ymd flan_hacker alpha commit 14
712 $ymd flan_hacker alpha commit 13
713 $ymd flan_hacker alpha commit 12
714 $ymd flan_hacker alpha commit 11
715 $ymd flan_hacker alpha commit 10
716 $ymd flan_hacker alpha commit 9
717 $ymd flan_hacker alpha commit 8
721 cmp -s "$testroot/view.expected" "$testroot/view"
723 if [ $ret -ne 0 ]; then
724 diff -u "$testroot/view.expected" "$testroot/view"
726 test_done "$testroot" "$ret"
730 run_test test_log_hsplit_diff
731 run_test test_log_vsplit_diff
732 run_test test_log_show_author
733 run_test test_log_scroll_right
734 run_test test_log_hsplit_ref
735 run_test test_log_hsplit_tree
736 run_test test_log_logmsg_widechar
737 run_test test_log_commit_keywords
738 run_test test_log_show_base_commit
739 run_test test_log_limit_view
740 run_test test_log_search