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_log_hsplit_diff()
20 {
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
31 SCREENDUMP
32 EOF
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>
45 date: $date
47 adding the test tree
49 A alpha | 1+ 0-
50 A beta | 1+ 0-
51 A epsilon/zeta | 1+ 0-
52 A gamma/delta | 1+ 0-
54 4 files changed, 4 insertions(+), 0 deletions(-)
56 commit - /dev/null
57 commit + $head_id
58 blob - /dev/null
59 EOF
61 cd $testroot/repo && tog log
62 cmp -s $testroot/view.expected $testroot/view
63 ret=$?
64 if [ $ret -ne 0 ]; then
65 diff -u $testroot/view.expected $testroot/view
66 test_done "$testroot" "$ret"
67 return 1
68 fi
70 test_done "$testroot" "$ret"
71 }
73 test_log_vsplit_diff()
74 {
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
87 SCREENDUMP
88 EOF
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>
94 |date: $date
95 |
96 |adding the test tree
97 |
98 |A alpha | 1+ 0-
99 |A beta | 1+ 0-
100 |A epsilon/zeta | 1+ 0-
101 |A gamma/delta | 1+ 0-
103 |4 files changed, 4 insertions(+), 0 deletions(-)
105 |commit - /dev/null
106 |commit + $head_id
107 |blob - /dev/null
108 |blob + $blobid_alpha (mode 644)
109 |--- /dev/null
110 |+++ alpha
111 |@@ -0,0 +1 @@
112 |+alpha
113 |blob - /dev/null
114 |blob + $blobid_beta (mode 644)
115 EOF
117 cd $testroot/repo && tog log
118 cmp -s $testroot/view.expected $testroot/view
119 ret=$?
120 if [ $ret -ne 0 ]; then
121 diff -u $testroot/view.expected $testroot/view
122 test_done "$testroot" "$ret"
123 return 1
124 fi
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 > \
144 /dev/null
146 local commit1=`git_show_head $testroot/repo`
147 local id1_len8=`trim_obj_id 32 $commit1`
149 cat <<EOF >$TOG_TEST_SCRIPT
150 @ toggle show author
151 SCREENDUMP
152 EOF
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
158 :show commit author
159 EOF
161 cd $testroot/repo && tog log
162 cmp -s $testroot/view.expected $testroot/view
163 ret=$?
164 if [ $ret -ne 0 ]; then
165 diff -u $testroot/view.expected $testroot/view
166 test_done "$testroot" "$ret"
167 return 1
168 fi
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
190 l scroll right
191 l scroll right
192 SCREENDUMP
193 EOF
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
199 EOF
201 cd $testroot/repo && tog log
202 cmp -s $testroot/view.expected $testroot/view
203 ret=$?
204 if [ $ret -ne 0 ]; then
205 diff -u $testroot/view.expected $testroot/view
206 test_done "$testroot" "$ret"
207 return 1
208 fi
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
223 R open ref view
224 S toggle horizontal split
225 - reduce size of ref view split
226 SCREENDUMP
227 EOF
229 cat <<EOF >$testroot/view.expected
230 commit $head_id [1/1] master
231 $ymd flan_hacker [master] adding the test tree
233 --------------------------------------------------------------------------------
234 references [1/2]
235 HEAD -> refs/heads/master
236 refs/heads/master
240 EOF
242 cd $testroot/repo && tog log
243 cmp -s $testroot/view.expected $testroot/view
244 ret=$?
245 if [ $ret -ne 0 ]; then
246 diff -u $testroot/view.expected $testroot/view
247 test_done "$testroot" "$ret"
248 return 1
249 fi
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
264 T open tree view
265 S toggle horizontal split
266 j move selection cursor down one entry to "beta"
267 - reduce size of tree view split
268 SCREENDUMP
269 EOF
271 cat <<EOF >$testroot/view.expected
272 commit $head_id [1/1] master
273 $ymd flan_hacker [master] adding the test tree
275 --------------------------------------------------------------------------------
276 commit $head_id
277 [2/4] /
279 alpha
280 beta
281 epsilon/
282 EOF
284 cd $testroot/repo && tog log
285 cmp -s $testroot/view.expected $testroot/view
286 ret=$?
287 if [ $ret -ne 0 ]; then
288 diff -u $testroot/view.expected $testroot/view
289 test_done "$testroot" "$ret"
290 return 1
291 fi
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
311 F toggle fullscreen
312 SCREENDUMP
313 EOF
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>
319 date: $date
321 $(widechar_logmsg)
323 A $(widechar_filename) | 5+ 0-
325 1 file changed, 5 insertions(+), 0 deletions(-)
327 commit - $commit1
328 commit + $head_id
329 blob - /dev/null
330 blob + $blobid (mode 644)
331 --- /dev/null
332 +++ $(widechar_filename)
333 @@ -0,0 +1,5 @@
334 +ウィリアム・ユワート・グラッドストン(英語: William Ewart Gladstone PC FRS FSS、1809年12月29日 - 1898年5月19日)は、イギリスの政治家。
336 +ヴィクトリア朝中期から後期にかけて、自由党を指導して、4度にわたり首相を務めた。
338 +生涯を通じて敬虔なイングランド国教会の信徒であり、キリスト教の精神を政治に反映させることを目指した。多くの自由主義改革を行い、帝国主義にも批判的であった。好敵手である保守党党首ベン
342 (END)
343 EOF
345 cd $testroot/repo && tog log
346 cmp -s $testroot/view.expected $testroot/view
347 ret=$?
348 if [ $ret -ne 0 ]; then
349 diff -u $testroot/view.expected $testroot/view
350 test_done "$testroot" "$ret"
351 return 1
352 fi
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")
366 set -- "$id"
368 got checkout "$repo" "$wt" > /dev/null
369 ret=$?
370 if [ $ret -ne 0 ]; then
371 echo "got checkout failed unexpectedly"
372 test_done "$testroot" "$ret"
373 return 1
374 fi
376 # move into the work tree (test is run in a subshell)
377 cd "$wt"
378 echo -n > alpha
380 for i in $(seq 8); do
381 echo "alpha $i" >> alpha
383 got ci -m "commit $i" > /dev/null
384 ret=$?
385 if [ $ret -ne 0 ]; then
386 echo "commit failed unexpectedly" >&2
387 test_done "$testroot" "$ret"
388 return 1
389 fi
391 id=$(git_show_head "$repo")
392 set -- "$@" "$id"
393 done
395 cat <<-EOF >$TOG_TEST_SCRIPT
396 WAIT_FOR_UI wait for log thread to finish
397 SCREENDUMP
398 EOF
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
411 EOF
413 tog log -c:base:-4
414 cmp -s "$testroot/view.expected" "$testroot/view"
415 ret=$?
416 if [ $ret -ne 0 ]; then
417 diff -u "$testroot/view.expected" "$testroot/view"
418 test_done "$testroot" "$ret"
419 return 1
420 fi
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
433 EOF
435 tog log -r "$repo" -c:head:-2
436 cmp -s "$testroot/view.expected" "$testroot/view"
437 ret=$?
438 if [ $ret -ne 0 ]; then
439 diff -u "$testroot/view.expected" "$testroot/view"
440 test_done "$testroot" "$ret"
441 return 1
442 fi
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
455 EOF
457 got up -c:base:-6 > /dev/null
458 ret=$?
459 if [ $ret -ne 0 ]; then
460 echo "got update failed unexpectedly"
461 test_done "$testroot" "$ret"
462 return 1
463 fi
465 tog log -c:base:+2
466 cmp -s "$testroot/view.expected" "$testroot/view"
467 ret=$?
468 if [ $ret -ne 0 ]; then
469 diff -u "$testroot/view.expected" "$testroot/view"
470 test_done "$testroot" "$ret"
471 return 1
472 fi
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
485 EOF
487 tog log -c:base:-99
488 cmp -s "$testroot/view.expected" "$testroot/view"
489 ret=$?
490 if [ $ret -ne 0 ]; then
491 diff -u "$testroot/view.expected" "$testroot/view"
492 test_done "$testroot" "$ret"
493 return 1
494 fi
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
510 ret=$?
511 if [ $ret -ne 0 ]; then
512 echo "got checkout failed unexpectedly"
513 test_done "$testroot" "$ret"
514 return 1
515 fi
517 # move into the work tree (test is run in a subshell)
518 cd "$testroot/wt"
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" +"%G-%m-%d")
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
527 SCREENDUMP
528 EOF
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
534 EOF
536 tog log
537 cmp -s "$testroot/view.expected" "$testroot/view"
538 ret=$?
539 if [ $ret -ne 0 ]; then
540 diff -u "$testroot/view.expected" "$testroot/view"
541 test_done "$testroot" "$ret"
542 return 1
543 fi
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
550 EOF
552 tog log -r "$repo"
553 cmp -s "$testroot/view.expected" "$testroot/view"
554 ret=$?
555 if [ $ret -ne 0 ]; then
556 diff -u "$testroot/view.expected" "$testroot/view"
557 test_done "$testroot" "$ret"
558 return 1
559 fi
561 # check out-of-date marker is shown with a mixed-commit tree
562 echo "mixed" > alpha
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
568 SCREENDUMP
569 EOF
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
575 EOF
577 tog log
578 cmp -s "$testroot/view.expected" "$testroot/view"
579 ret=$?
580 if [ $ret -ne 0 ]; then
581 diff -u "$testroot/view.expected" "$testroot/view"
582 test_done "$testroot" "$ret"
583 return 1
584 fi
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
596 ret=$?
597 if [ $ret -ne 0 ]; then
598 echo "got checkout failed unexpectedly"
599 test_done "$testroot" "$ret"
600 return 1
601 fi
603 cd "$wt"
605 echo "alpha0" > alpha
606 got commit -m alpha0 > /dev/null
607 ret=$?
608 if [ $ret -ne 0 ]; then
609 echo "got commit failed unexpectedly" >&2
610 test_done "$testroot" "$ret"
611 return 1
612 fi
614 echo "beta0" > beta
615 got commit -m beta0 > /dev/null
616 ret=$?
617 if [ $ret -ne 0 ]; then
618 echo "got commit failed unexpectedly" >&2
619 test_done "$testroot" "$ret"
620 return 1
621 fi
623 echo "alpha1" > alpha
624 got commit -m alpha1 > /dev/null
625 ret=$?
626 if [ $ret -ne 0 ]; then
627 echo "got commit failed unexpectedly" >&2
628 test_done "$testroot" "$ret"
629 return 1
630 fi
632 echo "beta1" > beta
633 got commit -m beta1 > /dev/null
634 ret=$?
635 if [ $ret -ne 0 ]; then
636 echo "got commit failed unexpectedly" >&2
637 test_done "$testroot" "$ret"
638 return 1
639 fi
640 local author_time=$(git_show_author_time "$repo")
641 local ymd=$(date -u -r $author_time +"%G-%m-%d")
642 local id=$(git_show_head "$repo")
644 # check base commit marker is not drawn
645 cat <<-EOF >$TOG_TEST_SCRIPT
646 &beta
647 SCREENDUMP
648 EOF
650 cat <<-EOF >$testroot/view.expected
651 commit $id [1/2] master
652 $ymd flan_hacker [master] beta1
653 $ymd flan_hacker beta0
655 EOF
657 tog log
658 cmp -s "$testroot/view.expected" "$testroot/view"
659 ret=$?
660 if [ $ret -ne 0 ]; then
661 diff -u "$testroot/view.expected" "$testroot/view"
662 fi
663 test_done "$testroot" "$ret"
666 test_log_search()
668 test_init log_search 80 8
669 local repo="$testroot/repo"
670 local wt="$testroot/wt"
671 local id=$(git_show_head "$repo")
673 set -- "$id"
675 got checkout "$repo" "$wt" > /dev/null
676 ret=$?
677 if [ $ret -ne 0 ]; then
678 echo "got checkout failed unexpectedly"
679 test_done "$testroot" "$ret"
680 return 1
681 fi
683 cd "$wt"
685 for i in $(seq 16); do
686 echo "alpha $i" > alpha
688 got ci -m "alpha commit $i" > /dev/null
689 ret=$?
690 if [ $ret -ne 0 ]; then
691 echo "got commit failed unexpectedly" >&2
692 test_done "$testroot" "$ret"
693 return 1
694 fi
696 id=$(git_show_head "$repo")
697 set -- "$@" "$id"
698 done
700 local author_time=$(git_show_author_time "$repo")
701 local ymd=$(date -u -r $author_time +"%G-%m-%d")
703 cat <<-EOF >$TOG_TEST_SCRIPT
704 /alpha commit 8
706 SCREENDUMP
707 EOF
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
718 EOF
720 tog log
721 cmp -s "$testroot/view.expected" "$testroot/view"
722 ret=$?
723 if [ $ret -ne 0 ]; then
724 diff -u "$testroot/view.expected" "$testroot/view"
725 fi
726 test_done "$testroot" "$ret"
729 test_parseargs "$@"
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