3 8d212112 2023-04-16 mark # Copyright (c) 2023 Mark Jamsek <mark@jamsek.dev>
5 8d212112 2023-04-16 mark # Permission to use, copy, modify, and distribute this software for any
6 8d212112 2023-04-16 mark # purpose with or without fee is hereby granted, provided that the above
7 8d212112 2023-04-16 mark # copyright notice and this permission notice appear in all copies.
9 8d212112 2023-04-16 mark # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 8d212112 2023-04-16 mark # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 8d212112 2023-04-16 mark # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 8d212112 2023-04-16 mark # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 8d212112 2023-04-16 mark # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 8d212112 2023-04-16 mark # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 8d212112 2023-04-16 mark # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 8d212112 2023-04-16 mark . ./common.sh
19 8d212112 2023-04-16 mark test_blame_basic()
21 8d212112 2023-04-16 mark test_init blame_basic 80 8
23 8d212112 2023-04-16 mark local commit_id1=`git_show_head $testroot/repo`
25 8d212112 2023-04-16 mark got checkout $testroot/repo $testroot/wt > /dev/null
27 8d212112 2023-04-16 mark if [ $ret -ne 0 ]; then
28 8d212112 2023-04-16 mark test_done "$testroot" "$ret"
32 8d212112 2023-04-16 mark echo aaaa >> $testroot/wt/alpha
33 8d212112 2023-04-16 mark (cd $testroot/wt && got commit -m "a change" > /dev/null)
34 8d212112 2023-04-16 mark local commit_id2=`git_show_head $testroot/repo`
36 8d212112 2023-04-16 mark echo bbbb >> $testroot/wt/alpha
37 8d212112 2023-04-16 mark (cd $testroot/wt && got commit -m "b change" > /dev/null)
38 8d212112 2023-04-16 mark local commit_id3=`git_show_head $testroot/repo`
40 8d212112 2023-04-16 mark echo cccc >> $testroot/wt/alpha
41 8d212112 2023-04-16 mark (cd $testroot/wt && got commit -m "c change" > /dev/null)
42 8d212112 2023-04-16 mark local commit_id4=`git_show_head $testroot/repo`
43 8d212112 2023-04-16 mark local author_time=`git_show_author_time $testroot/repo`
44 8d212112 2023-04-16 mark local ymd=`date -u -r $author_time +"%G-%m-%d"`
46 8d212112 2023-04-16 mark cat <<EOF >$TOG_TEST_SCRIPT
47 8d212112 2023-04-16 mark WAIT_FOR_UI wait for blame to finish
51 8d212112 2023-04-16 mark local commit_id1_short=`trim_obj_id 32 $commit_id1`
52 8d212112 2023-04-16 mark local commit_id2_short=`trim_obj_id 32 $commit_id2`
53 8d212112 2023-04-16 mark local commit_id3_short=`trim_obj_id 32 $commit_id3`
54 8d212112 2023-04-16 mark local commit_id4_short=`trim_obj_id 32 $commit_id4`
56 8d212112 2023-04-16 mark cat <<EOF >$testroot/view.expected
57 8d212112 2023-04-16 mark commit $commit_id4
58 8d212112 2023-04-16 mark [1/4] /alpha
59 8d212112 2023-04-16 mark $commit_id1_short alpha
60 8d212112 2023-04-16 mark $commit_id2_short aaaa
61 8d212112 2023-04-16 mark $commit_id3_short bbbb
62 8d212112 2023-04-16 mark $commit_id4_short cccc
67 8d212112 2023-04-16 mark cd $testroot/wt && tog blame alpha
68 8d212112 2023-04-16 mark cmp -s $testroot/view.expected $testroot/view
70 8d212112 2023-04-16 mark if [ $ret -ne 0 ]; then
71 8d212112 2023-04-16 mark diff -u $testroot/view.expected $testroot/view
72 8d212112 2023-04-16 mark test_done "$testroot" "$ret"
76 8d212112 2023-04-16 mark test_done "$testroot" "$ret"
79 c4df265e 2023-07-19 mark test_blame_commit_keywords()
81 c4df265e 2023-07-19 mark test_init blame_commit_keywords 80 10
82 c4df265e 2023-07-19 mark local repo="$testroot/repo"
83 c4df265e 2023-07-19 mark local wt="$testroot/wt"
84 c4df265e 2023-07-19 mark local id=$(git_show_head "$repo")
85 c4df265e 2023-07-19 mark local author_time=$(git_show_author_time "$repo")
86 c4df265e 2023-07-19 mark local ymd=$(date -u -r $author_time +"%G-%m-%d")
88 c4df265e 2023-07-19 mark set -A ids "$id"
89 c4df265e 2023-07-19 mark set -A short_ids "$(trim_obj_id 32 $id)"
91 c4df265e 2023-07-19 mark cat <<-EOF >$TOG_TEST_SCRIPT
92 c4df265e 2023-07-19 mark WAIT_FOR_UI wait for blame to finish
96 c4df265e 2023-07-19 mark # :base requires work tree
97 c4df265e 2023-07-19 mark echo "tog: '-c :base' requires work tree" > "$testroot/stderr.expected"
98 c4df265e 2023-07-19 mark tog blame -r "$repo" -c:base alpha 2> "$testroot/stderr"
100 c4df265e 2023-07-19 mark if [ $ret -eq 0 ]; then
101 c4df265e 2023-07-19 mark echo "blame command succeeded unexpectedly" >&2
102 c4df265e 2023-07-19 mark test_done "$testroot" "1"
106 c4df265e 2023-07-19 mark cmp -s "$testroot/stderr.expected" "$testroot/stderr"
108 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
109 c4df265e 2023-07-19 mark diff -u "$testroot/stderr.expected" "$testroot/stderr"
110 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
114 c4df265e 2023-07-19 mark # :head keyword in repo
115 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
117 c4df265e 2023-07-19 mark [1/1] /alpha
118 c4df265e 2023-07-19 mark $(pop_id 1 $short_ids) alpha
128 c4df265e 2023-07-19 mark tog blame -r "$repo" -c:head alpha
130 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
131 c4df265e 2023-07-19 mark echo "blame command failed unexpectedly" >&2
132 c4df265e 2023-07-19 mark test_done "$testroot" "1"
136 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
138 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
139 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
140 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
144 c4df265e 2023-07-19 mark got checkout "$repo" "$wt" > /dev/null
146 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
147 c4df265e 2023-07-19 mark echo "got checkout failed unexpectedly"
148 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
152 c4df265e 2023-07-19 mark # move into the work tree (test is run in a subshell)
154 c4df265e 2023-07-19 mark echo -n > alpha
156 c4df265e 2023-07-19 mark for i in $(seq 8); do
157 c4df265e 2023-07-19 mark echo "alpha $i" >> alpha
159 c4df265e 2023-07-19 mark got ci -m "commit $i" > /dev/null
161 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
162 c4df265e 2023-07-19 mark echo "commit failed unexpectedly" >&2
163 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
167 c4df265e 2023-07-19 mark id=$(git_show_head "$repo")
168 c4df265e 2023-07-19 mark set -- "$ids" "$id"
170 c4df265e 2023-07-19 mark set -- "$short_ids" "$(trim_obj_id 32 $id)"
171 c4df265e 2023-07-19 mark short_ids=$*
174 c4df265e 2023-07-19 mark author_time=$(git_show_author_time "$repo")
175 c4df265e 2023-07-19 mark ymd=$(date -u -r $author_time +"%G-%m-%d")
177 c4df265e 2023-07-19 mark # :base:- keyword in work tree
178 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
179 c4df265e 2023-07-19 mark commit $(pop_id 8 $ids)
180 c4df265e 2023-07-19 mark [1/7] /alpha
181 c4df265e 2023-07-19 mark $(pop_id 2 $short_ids) alpha 1
182 c4df265e 2023-07-19 mark $(pop_id 3 $short_ids) alpha 2
183 c4df265e 2023-07-19 mark $(pop_id 4 $short_ids) alpha 3
184 c4df265e 2023-07-19 mark $(pop_id 5 $short_ids) alpha 4
185 c4df265e 2023-07-19 mark $(pop_id 6 $short_ids) alpha 5
186 c4df265e 2023-07-19 mark $(pop_id 7 $short_ids) alpha 6
187 c4df265e 2023-07-19 mark $(pop_id 8 $short_ids) alpha 7
191 c4df265e 2023-07-19 mark tog blame -c:base:- alpha
193 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
194 c4df265e 2023-07-19 mark echo "blame command failed unexpectedly" >&2
195 c4df265e 2023-07-19 mark test_done "$testroot" "1"
199 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
201 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
202 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
203 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
207 c4df265e 2023-07-19 mark # :head:-4 keyword in work tree
208 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
209 c4df265e 2023-07-19 mark commit $(pop_id 5 $ids)
210 c4df265e 2023-07-19 mark [1/4] /alpha
211 c4df265e 2023-07-19 mark $(pop_id 2 $short_ids) alpha 1
212 c4df265e 2023-07-19 mark $(pop_id 3 $short_ids) alpha 2
213 c4df265e 2023-07-19 mark $(pop_id 4 $short_ids) alpha 3
214 c4df265e 2023-07-19 mark $(pop_id 5 $short_ids) alpha 4
221 c4df265e 2023-07-19 mark tog blame -c:head:-4 alpha
223 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
224 c4df265e 2023-07-19 mark echo "blame command failed unexpectedly" >&2
225 c4df265e 2023-07-19 mark test_done "$testroot" "1"
229 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
231 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
232 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
233 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
237 c4df265e 2023-07-19 mark # :base:+2 keyword in work tree
238 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
239 c4df265e 2023-07-19 mark commit $(pop_id 5 $ids)
240 c4df265e 2023-07-19 mark [1/4] /alpha
241 c4df265e 2023-07-19 mark $(pop_id 2 $short_ids) alpha 1
242 c4df265e 2023-07-19 mark $(pop_id 3 $short_ids) alpha 2
243 c4df265e 2023-07-19 mark $(pop_id 4 $short_ids) alpha 3
244 c4df265e 2023-07-19 mark $(pop_id 5 $short_ids) alpha 4
251 c4df265e 2023-07-19 mark got up -c:head:-6 > /dev/null
252 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
253 c4df265e 2023-07-19 mark echo "update command failed unexpectedly" >&2
254 c4df265e 2023-07-19 mark test_done "$testroot" "1"
258 c4df265e 2023-07-19 mark tog blame -c:base:+2 alpha
260 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
261 c4df265e 2023-07-19 mark echo "blame command failed unexpectedly" >&2
262 c4df265e 2023-07-19 mark test_done "$testroot" "1"
266 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
268 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
269 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
270 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
274 c4df265e 2023-07-19 mark # master:-99 keyword in work tree
275 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
276 c4df265e 2023-07-19 mark commit $(pop_id 1 $ids)
277 c4df265e 2023-07-19 mark [1/1] /alpha
278 c4df265e 2023-07-19 mark $(pop_id 1 $short_ids) alpha
288 c4df265e 2023-07-19 mark tog blame -cmaster:-99 alpha
290 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
291 c4df265e 2023-07-19 mark echo "blame command failed unexpectedly" >&2
292 c4df265e 2023-07-19 mark test_done "$testroot" "1"
296 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
298 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
299 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
300 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
304 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
307 8d212112 2023-04-16 mark test_parseargs "$@"
308 8d212112 2023-04-16 mark run_test test_blame_basic
309 c4df265e 2023-07-19 mark run_test test_blame_commit_keywords