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_blame_basic()
20 {
21 test_init blame_basic 80 8
23 local commit_id1=`git_show_head $testroot/repo`
25 got checkout $testroot/repo $testroot/wt > /dev/null
26 ret=$?
27 if [ $ret -ne 0 ]; then
28 test_done "$testroot" "$ret"
29 return 1
30 fi
32 echo aaaa >> $testroot/wt/alpha
33 (cd $testroot/wt && got commit -m "a change" > /dev/null)
34 local commit_id2=`git_show_head $testroot/repo`
36 echo bbbb >> $testroot/wt/alpha
37 (cd $testroot/wt && got commit -m "b change" > /dev/null)
38 local commit_id3=`git_show_head $testroot/repo`
40 echo cccc >> $testroot/wt/alpha
41 (cd $testroot/wt && got commit -m "c change" > /dev/null)
42 local commit_id4=`git_show_head $testroot/repo`
43 local author_time=`git_show_author_time $testroot/repo`
44 local ymd=`date -u -r $author_time +"%G-%m-%d"`
46 cat <<EOF >$TOG_TEST_SCRIPT
47 WAIT_FOR_UI wait for blame to finish
48 SCREENDUMP
49 EOF
51 local commit_id1_short=`trim_obj_id 32 $commit_id1`
52 local commit_id2_short=`trim_obj_id 32 $commit_id2`
53 local commit_id3_short=`trim_obj_id 32 $commit_id3`
54 local commit_id4_short=`trim_obj_id 32 $commit_id4`
56 cat <<EOF >$testroot/view.expected
57 commit $commit_id4
58 [1/4] /alpha
59 $commit_id1_short alpha
60 $commit_id2_short aaaa
61 $commit_id3_short bbbb
62 $commit_id4_short cccc
65 EOF
67 cd $testroot/wt && tog blame alpha
68 cmp -s $testroot/view.expected $testroot/view
69 ret=$?
70 if [ $ret -ne 0 ]; then
71 diff -u $testroot/view.expected $testroot/view
72 test_done "$testroot" "$ret"
73 return 1
74 fi
76 test_done "$testroot" "$ret"
77 }
79 test_blame_commit_keywords()
80 {
81 test_init blame_commit_keywords 80 10
82 local repo="$testroot/repo"
83 local wt="$testroot/wt"
84 local id=$(git_show_head "$repo")
85 local author_time=$(git_show_author_time "$repo")
86 local ymd=$(date -u -r $author_time +"%G-%m-%d")
88 set -A ids "$id"
89 set -A short_ids "$(trim_obj_id 32 $id)"
91 cat <<-EOF >$TOG_TEST_SCRIPT
92 WAIT_FOR_UI wait for blame to finish
93 SCREENDUMP
94 EOF
96 # :base requires work tree
97 echo "tog: '-c :base' requires work tree" > "$testroot/stderr.expected"
98 tog blame -r "$repo" -c:base alpha 2> "$testroot/stderr"
99 ret=$?
100 if [ $ret -eq 0 ]; then
101 echo "blame command succeeded unexpectedly" >&2
102 test_done "$testroot" "1"
103 return 1
104 fi
106 cmp -s "$testroot/stderr.expected" "$testroot/stderr"
107 ret=$?
108 if [ $ret -ne 0 ]; then
109 diff -u "$testroot/stderr.expected" "$testroot/stderr"
110 test_done "$testroot" "$ret"
111 return 1
112 fi
114 # :head keyword in repo
115 cat <<-EOF >$testroot/view.expected
116 commit $id
117 [1/1] /alpha
118 $(pop_id 1 $short_ids) alpha
126 EOF
128 tog blame -r "$repo" -c:head alpha
129 ret=$?
130 if [ $ret -ne 0 ]; then
131 echo "blame command failed unexpectedly" >&2
132 test_done "$testroot" "1"
133 return 1
134 fi
136 cmp -s $testroot/view.expected $testroot/view
137 ret=$?
138 if [ $ret -ne 0 ]; then
139 diff -u $testroot/view.expected $testroot/view
140 test_done "$testroot" "$ret"
141 return 1
142 fi
144 got checkout "$repo" "$wt" > /dev/null
145 ret=$?
146 if [ $ret -ne 0 ]; then
147 echo "got checkout failed unexpectedly"
148 test_done "$testroot" "$ret"
149 return 1
150 fi
152 # move into the work tree (test is run in a subshell)
153 cd "$wt"
154 echo -n > alpha
156 for i in $(seq 8); do
157 echo "alpha $i" >> alpha
159 got ci -m "commit $i" > /dev/null
160 ret=$?
161 if [ $ret -ne 0 ]; then
162 echo "commit failed unexpectedly" >&2
163 test_done "$testroot" "$ret"
164 return 1
165 fi
167 id=$(git_show_head "$repo")
168 set -- "$ids" "$id"
169 ids=$*
170 set -- "$short_ids" "$(trim_obj_id 32 $id)"
171 short_ids=$*
172 done
174 author_time=$(git_show_author_time "$repo")
175 ymd=$(date -u -r $author_time +"%G-%m-%d")
177 # :base:- keyword in work tree
178 cat <<-EOF >$testroot/view.expected
179 commit $(pop_id 8 $ids)
180 [1/7] /alpha
181 $(pop_id 2 $short_ids) alpha 1
182 $(pop_id 3 $short_ids) alpha 2
183 $(pop_id 4 $short_ids) alpha 3
184 $(pop_id 5 $short_ids) alpha 4
185 $(pop_id 6 $short_ids) alpha 5
186 $(pop_id 7 $short_ids) alpha 6
187 $(pop_id 8 $short_ids) alpha 7
189 EOF
191 tog blame -c:base:- alpha
192 ret=$?
193 if [ $ret -ne 0 ]; then
194 echo "blame command failed unexpectedly" >&2
195 test_done "$testroot" "1"
196 return 1
197 fi
199 cmp -s $testroot/view.expected $testroot/view
200 ret=$?
201 if [ $ret -ne 0 ]; then
202 diff -u $testroot/view.expected $testroot/view
203 test_done "$testroot" "$ret"
204 return 1
205 fi
207 # :head:-4 keyword in work tree
208 cat <<-EOF >$testroot/view.expected
209 commit $(pop_id 5 $ids)
210 [1/4] /alpha
211 $(pop_id 2 $short_ids) alpha 1
212 $(pop_id 3 $short_ids) alpha 2
213 $(pop_id 4 $short_ids) alpha 3
214 $(pop_id 5 $short_ids) alpha 4
219 EOF
221 tog blame -c:head:-4 alpha
222 ret=$?
223 if [ $ret -ne 0 ]; then
224 echo "blame command failed unexpectedly" >&2
225 test_done "$testroot" "1"
226 return 1
227 fi
229 cmp -s $testroot/view.expected $testroot/view
230 ret=$?
231 if [ $ret -ne 0 ]; then
232 diff -u $testroot/view.expected $testroot/view
233 test_done "$testroot" "$ret"
234 return 1
235 fi
237 # :base:+2 keyword in work tree
238 cat <<-EOF >$testroot/view.expected
239 commit $(pop_id 5 $ids)
240 [1/4] /alpha
241 $(pop_id 2 $short_ids) alpha 1
242 $(pop_id 3 $short_ids) alpha 2
243 $(pop_id 4 $short_ids) alpha 3
244 $(pop_id 5 $short_ids) alpha 4
249 EOF
251 got up -c:head:-6 > /dev/null
252 if [ $ret -ne 0 ]; then
253 echo "update command failed unexpectedly" >&2
254 test_done "$testroot" "1"
255 return 1
256 fi
258 tog blame -c:base:+2 alpha
259 ret=$?
260 if [ $ret -ne 0 ]; then
261 echo "blame command failed unexpectedly" >&2
262 test_done "$testroot" "1"
263 return 1
264 fi
266 cmp -s $testroot/view.expected $testroot/view
267 ret=$?
268 if [ $ret -ne 0 ]; then
269 diff -u $testroot/view.expected $testroot/view
270 test_done "$testroot" "$ret"
271 return 1
272 fi
274 # master:-99 keyword in work tree
275 cat <<-EOF >$testroot/view.expected
276 commit $(pop_id 1 $ids)
277 [1/1] /alpha
278 $(pop_id 1 $short_ids) alpha
286 EOF
288 tog blame -cmaster:-99 alpha
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 echo "blame command failed unexpectedly" >&2
292 test_done "$testroot" "1"
293 return 1
294 fi
296 cmp -s $testroot/view.expected $testroot/view
297 ret=$?
298 if [ $ret -ne 0 ]; then
299 diff -u $testroot/view.expected $testroot/view
300 test_done "$testroot" "$ret"
301 return 1
302 fi
304 test_done "$testroot" "$ret"
307 test_parseargs "$@"
308 run_test test_blame_basic
309 run_test test_blame_commit_keywords