3 c5f4d357 2023-04-22 thomas # Copyright (c) 2023 Mark Jamsek <mark@jamsek.dev>
5 c5f4d357 2023-04-22 thomas # Permission to use, copy, modify, and distribute this software for any
6 c5f4d357 2023-04-22 thomas # purpose with or without fee is hereby granted, provided that the above
7 c5f4d357 2023-04-22 thomas # copyright notice and this permission notice appear in all copies.
9 c5f4d357 2023-04-22 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 c5f4d357 2023-04-22 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 c5f4d357 2023-04-22 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 c5f4d357 2023-04-22 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 c5f4d357 2023-04-22 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 c5f4d357 2023-04-22 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 c5f4d357 2023-04-22 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 c5f4d357 2023-04-22 thomas . ./common.sh
19 c5f4d357 2023-04-22 thomas test_diff_contiguous_commits()
21 c5f4d357 2023-04-22 thomas test_init diff_contiguous_commits
23 c5f4d357 2023-04-22 thomas local commit_id1=`git_show_head $testroot/repo`
24 c5f4d357 2023-04-22 thomas local alpha_id_old=`get_blob_id $testroot/repo "" alpha`
26 c5f4d357 2023-04-22 thomas echo "modified alpha" > $testroot/repo/alpha
27 c5f4d357 2023-04-22 thomas git_commit $testroot/repo -m "changed alpha"
28 c5f4d357 2023-04-22 thomas local author_time=`git_show_author_time $testroot/repo`
29 c5f4d357 2023-04-22 thomas local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
30 c5f4d357 2023-04-22 thomas local head_id=`git_show_head $testroot/repo`
31 c5f4d357 2023-04-22 thomas local head_id_truncated=`trim_obj_id 13 $head_id`
32 c5f4d357 2023-04-22 thomas local alpha_id=`get_blob_id $testroot/repo "" alpha`
34 fa9bb690 2023-04-22 thomas cat <<EOF >$TOG_TEST_SCRIPT
35 c5f4d357 2023-04-22 thomas SCREENDUMP
38 c5f4d357 2023-04-22 thomas cat <<EOF >$testroot/view.expected
39 c5f4d357 2023-04-22 thomas [1/20] diff $commit_id1 $head_id_truncated
40 c5f4d357 2023-04-22 thomas commit $head_id (master)
41 c5f4d357 2023-04-22 thomas from: Flan Hacker <flan_hacker@openbsd.org>
42 c5f4d357 2023-04-22 thomas date: $date
44 c5f4d357 2023-04-22 thomas changed alpha
46 c5f4d357 2023-04-22 thomas M alpha | 1+ 1-
48 c5f4d357 2023-04-22 thomas 1 file changed, 1 insertion(+), 1 deletion(-)
50 c5f4d357 2023-04-22 thomas commit - $commit_id1
51 c5f4d357 2023-04-22 thomas commit + $head_id
52 c5f4d357 2023-04-22 thomas blob - $alpha_id_old
53 c5f4d357 2023-04-22 thomas blob + $alpha_id
56 c5f4d357 2023-04-22 thomas @@ -1 +1 @@
58 c5f4d357 2023-04-22 thomas +modified alpha
65 c5f4d357 2023-04-22 thomas cd $testroot/repo && tog diff $commit_id1 $head_id
66 c5f4d357 2023-04-22 thomas cmp -s $testroot/view.expected $testroot/view
68 c5f4d357 2023-04-22 thomas if [ $ret -ne 0 ]; then
69 c5f4d357 2023-04-22 thomas diff -u $testroot/view.expected $testroot/view
70 c5f4d357 2023-04-22 thomas test_done "$testroot" "$ret"
74 c5f4d357 2023-04-22 thomas test_done "$testroot" "$ret"
77 c5f4d357 2023-04-22 thomas test_diff_arbitrary_commits()
79 c5f4d357 2023-04-22 thomas test_init diff_arbitrary_commits 80 18
81 c5f4d357 2023-04-22 thomas local commit_id1=`git_show_head $testroot/repo`
82 c5f4d357 2023-04-22 thomas local alpha_id_old=`get_blob_id $testroot/repo "" alpha`
84 c5f4d357 2023-04-22 thomas echo "modified alpha" > $testroot/repo/alpha
85 c5f4d357 2023-04-22 thomas git_commit $testroot/repo -m "changed alpha"
86 c5f4d357 2023-04-22 thomas local commit_id2=`git_show_head $testroot/repo`
88 c5f4d357 2023-04-22 thomas echo "modified alpha again" > $testroot/repo/alpha
89 c5f4d357 2023-04-22 thomas echo "new file" > $testroot/repo/new
90 c5f4d357 2023-04-22 thomas (cd $testroot/repo && git add new)
91 c5f4d357 2023-04-22 thomas git_commit $testroot/repo -m "new file"
92 c5f4d357 2023-04-22 thomas local head_id=`git_show_head $testroot/repo`
93 c5f4d357 2023-04-22 thomas local head_id_truncated=`trim_obj_id 13 $head_id`
94 c5f4d357 2023-04-22 thomas local alpha_id=`get_blob_id $testroot/repo "" alpha`
95 c5f4d357 2023-04-22 thomas local new_id=`get_blob_id $testroot/repo "" new`
97 fa9bb690 2023-04-22 thomas cat <<EOF >$TOG_TEST_SCRIPT
98 c5f4d357 2023-04-22 thomas SCREENDUMP
101 c5f4d357 2023-04-22 thomas cat <<EOF >$testroot/view.expected
102 c5f4d357 2023-04-22 thomas [1/16] diff $commit_id1 $head_id_truncated
103 c5f4d357 2023-04-22 thomas commit - $commit_id1
104 c5f4d357 2023-04-22 thomas commit + $head_id
105 c5f4d357 2023-04-22 thomas blob - $alpha_id_old
106 c5f4d357 2023-04-22 thomas blob + $alpha_id
107 c5f4d357 2023-04-22 thomas --- alpha
108 c5f4d357 2023-04-22 thomas +++ alpha
109 c5f4d357 2023-04-22 thomas @@ -1 +1 @@
111 c5f4d357 2023-04-22 thomas +modified alpha again
112 c5f4d357 2023-04-22 thomas blob - /dev/null
113 c5f4d357 2023-04-22 thomas blob + $new_id (mode 644)
114 c5f4d357 2023-04-22 thomas --- /dev/null
116 c5f4d357 2023-04-22 thomas @@ -0,0 +1 @@
117 c5f4d357 2023-04-22 thomas +new file
122 c5f4d357 2023-04-22 thomas cd $testroot/repo && tog diff $commit_id1 $head_id
123 c5f4d357 2023-04-22 thomas cmp -s $testroot/view.expected $testroot/view
125 c5f4d357 2023-04-22 thomas if [ $ret -ne 0 ]; then
126 c5f4d357 2023-04-22 thomas diff -u $testroot/view.expected $testroot/view
127 c5f4d357 2023-04-22 thomas test_done "$testroot" "$ret"
131 c5f4d357 2023-04-22 thomas test_done "$testroot" "$ret"
134 52c5094b 2023-04-28 thomas test_diff_J_keymap_on_last_loaded_commit()
136 52c5094b 2023-04-28 thomas test_init diff_J_keymap_on_last_loaded_commit 94 24
138 52c5094b 2023-04-28 thomas local i=0
140 52c5094b 2023-04-28 thomas cd $testroot/repo
142 52c5094b 2023-04-28 thomas while [ "$i" -lt 32 ]; do
143 52c5094b 2023-04-28 thomas echo $i > alpha
144 52c5094b 2023-04-28 thomas git commit -aqm $i
145 52c5094b 2023-04-28 thomas if [ $i -eq 6 ]; then
146 52c5094b 2023-04-28 thomas local id6=$(git_show_head .)
147 52c5094b 2023-04-28 thomas local blobid6=$(get_blob_id . "" alpha)
148 52c5094b 2023-04-28 thomas elif [ $i -eq 7 ]; then
149 52c5094b 2023-04-28 thomas local id7=$(git_show_head .)
150 52c5094b 2023-04-28 thomas local blobid7=$(get_blob_id . "" alpha)
151 52c5094b 2023-04-28 thomas local author_time=$(git_show_author_time .)
153 52c5094b 2023-04-28 thomas i=$(( i + 1 ))
156 52c5094b 2023-04-28 thomas local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
158 52c5094b 2023-04-28 thomas cat <<EOF >$TOG_TEST_SCRIPT
159 52c5094b 2023-04-28 thomas KEY_ENTER open diff view of selected commit
160 52c5094b 2023-04-28 thomas S toggle horizontal split
161 52c5094b 2023-04-28 thomas TAB tab back to log view
162 52c5094b 2023-04-28 thomas 23j move to last loaded commit
163 52c5094b 2023-04-28 thomas KEY_ENTER select last loaded commit
164 52c5094b 2023-04-28 thomas F toggle fullscreen
165 52c5094b 2023-04-28 thomas J move down to next commit in the log
166 52c5094b 2023-04-28 thomas SCREENDUMP
169 52c5094b 2023-04-28 thomas cat <<EOF >$testroot/view.expected
170 52c5094b 2023-04-28 thomas [1/20] diff $id6 $id7
171 52c5094b 2023-04-28 thomas commit $id7
172 52c5094b 2023-04-28 thomas from: Flan Hacker <flan_hacker@openbsd.org>
173 52c5094b 2023-04-28 thomas date: $date
177 52c5094b 2023-04-28 thomas M alpha | 1+ 1-
179 52c5094b 2023-04-28 thomas 1 file changed, 1 insertion(+), 1 deletion(-)
181 52c5094b 2023-04-28 thomas commit - $id6
182 52c5094b 2023-04-28 thomas commit + $id7
183 52c5094b 2023-04-28 thomas blob - $blobid6
184 52c5094b 2023-04-28 thomas blob + $blobid7
185 52c5094b 2023-04-28 thomas --- alpha
186 52c5094b 2023-04-28 thomas +++ alpha
187 52c5094b 2023-04-28 thomas @@ -1 +1 @@
197 52c5094b 2023-04-28 thomas cmp -s $testroot/view.expected $testroot/view
199 52c5094b 2023-04-28 thomas if [ $ret -ne 0 ]; then
200 52c5094b 2023-04-28 thomas diff -u $testroot/view.expected $testroot/view
201 52c5094b 2023-04-28 thomas test_done "$testroot" "$ret"
205 52c5094b 2023-04-28 thomas test_done "$testroot" "$ret"
208 c5f4d357 2023-04-22 thomas test_parseargs "$@"
209 c5f4d357 2023-04-22 thomas run_test test_diff_contiguous_commits
210 c5f4d357 2023-04-22 thomas run_test test_diff_arbitrary_commits
211 52c5094b 2023-04-28 thomas run_test test_diff_J_keymap_on_last_loaded_commit