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_parseargs "$@"
358 run_test test_log_hsplit_diff
359 run_test test_log_vsplit_diff
360 run_test test_log_show_author
361 run_test test_log_scroll_right
362 run_test test_log_hsplit_ref
363 run_test test_log_hsplit_tree
364 run_test test_log_logmsg_widechar