3 c970ea82 2019-07-27 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 c970ea82 2019-07-27 stsp # Permission to use, copy, modify, and distribute this software for any
6 c970ea82 2019-07-27 stsp # purpose with or without fee is hereby granted, provided that the above
7 c970ea82 2019-07-27 stsp # copyright notice and this permission notice appear in all copies.
9 c970ea82 2019-07-27 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 c970ea82 2019-07-27 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 c970ea82 2019-07-27 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 c970ea82 2019-07-27 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 c970ea82 2019-07-27 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 c970ea82 2019-07-27 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 c970ea82 2019-07-27 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 c970ea82 2019-07-27 stsp . ./common.sh
19 c970ea82 2019-07-27 stsp function test_blame_basic {
20 c970ea82 2019-07-27 stsp local testroot=`test_init blame_basic`
22 c970ea82 2019-07-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
24 c970ea82 2019-07-27 stsp if [ "$ret" != "0" ]; then
25 c970ea82 2019-07-27 stsp test_done "$testroot" "$ret"
29 c970ea82 2019-07-27 stsp echo 1 > $testroot/wt/alpha
30 c970ea82 2019-07-27 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
31 c970ea82 2019-07-27 stsp local commit1=`git_show_head $testroot/repo`
33 c970ea82 2019-07-27 stsp echo 2 >> $testroot/wt/alpha
34 c970ea82 2019-07-27 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
35 c970ea82 2019-07-27 stsp local commit2=`git_show_head $testroot/repo`
37 c970ea82 2019-07-27 stsp echo 3 >> $testroot/wt/alpha
38 c970ea82 2019-07-27 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
39 c970ea82 2019-07-27 stsp local commit3=`git_show_head $testroot/repo`
40 bcb49d15 2019-08-14 stsp local author_time=`git_show_author_time $testroot/repo`
42 c970ea82 2019-07-27 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
44 c970ea82 2019-07-27 stsp local short_commit1=`trim_obj_id 32 $commit1`
45 c970ea82 2019-07-27 stsp local short_commit2=`trim_obj_id 32 $commit2`
46 c970ea82 2019-07-27 stsp local short_commit3=`trim_obj_id 32 $commit3`
48 bcb49d15 2019-08-14 stsp d=`date -r $author_time +"%g/%m/%d"`
49 bcb49d15 2019-08-14 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
50 bcb49d15 2019-08-14 stsp echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
51 bcb49d15 2019-08-14 stsp echo "3) $short_commit3 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected
53 c970ea82 2019-07-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
55 c970ea82 2019-07-27 stsp if [ "$ret" != "0" ]; then
56 c970ea82 2019-07-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
59 c970ea82 2019-07-27 stsp test_done "$testroot" "$ret"
62 303e2782 2019-08-09 stsp function test_blame_tag {
63 303e2782 2019-08-09 stsp local testroot=`test_init blame_tag`
64 303e2782 2019-08-09 stsp local tag=1.0.0
66 303e2782 2019-08-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
68 303e2782 2019-08-09 stsp if [ "$ret" != "0" ]; then
69 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
72 303e2782 2019-08-09 stsp echo 1 > $testroot/wt/alpha
73 303e2782 2019-08-09 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
74 303e2782 2019-08-09 stsp local commit1=`git_show_head $testroot/repo`
76 303e2782 2019-08-09 stsp echo 2 >> $testroot/wt/alpha
77 303e2782 2019-08-09 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
78 303e2782 2019-08-09 stsp local commit2=`git_show_head $testroot/repo`
80 303e2782 2019-08-09 stsp (cd $testroot/repo && git tag -a -m "test" $tag)
82 303e2782 2019-08-09 stsp echo 3 >> $testroot/wt/alpha
83 303e2782 2019-08-09 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
84 303e2782 2019-08-09 stsp local commit3=`git_show_head $testroot/repo`
85 bcb49d15 2019-08-14 stsp local author_time=`git_show_author_time $testroot/repo`
87 303e2782 2019-08-09 stsp (cd $testroot/wt && got blame -c $tag alpha > $testroot/stdout)
89 303e2782 2019-08-09 stsp local short_commit1=`trim_obj_id 32 $commit1`
90 303e2782 2019-08-09 stsp local short_commit2=`trim_obj_id 32 $commit2`
92 bcb49d15 2019-08-14 stsp d=`date -r $author_time +"%g/%m/%d"`
93 bcb49d15 2019-08-14 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
94 bcb49d15 2019-08-14 stsp echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
96 303e2782 2019-08-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
98 303e2782 2019-08-09 stsp if [ "$ret" != "0" ]; then
99 303e2782 2019-08-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
101 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
104 78695fb7 2019-08-12 stsp function test_blame_file_single_line {
105 78695fb7 2019-08-12 stsp local testroot=`test_init blame_file_single_line`
107 78695fb7 2019-08-12 stsp got checkout $testroot/repo $testroot/wt > /dev/null
109 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
110 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
114 78695fb7 2019-08-12 stsp echo 1 > $testroot/wt/alpha
115 78695fb7 2019-08-12 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
116 78695fb7 2019-08-12 stsp local commit1=`git_show_head $testroot/repo`
117 bcb49d15 2019-08-14 stsp local author_time=`git_show_author_time $testroot/repo`
119 78695fb7 2019-08-12 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
121 78695fb7 2019-08-12 stsp local short_commit1=`trim_obj_id 32 $commit1`
123 bcb49d15 2019-08-14 stsp d=`date -r $author_time +"%g/%m/%d"`
124 bcb49d15 2019-08-14 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
126 78695fb7 2019-08-12 stsp cmp -s $testroot/stdout.expected $testroot/stdout
128 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
129 78695fb7 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
131 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
134 78695fb7 2019-08-12 stsp function test_blame_file_single_line_no_newline {
135 78695fb7 2019-08-12 stsp local testroot=`test_init blame_file_single_line_no_newline`
137 78695fb7 2019-08-12 stsp got checkout $testroot/repo $testroot/wt > /dev/null
139 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
140 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
144 78695fb7 2019-08-12 stsp echo -n 1 > $testroot/wt/alpha
145 78695fb7 2019-08-12 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
146 78695fb7 2019-08-12 stsp local commit1=`git_show_head $testroot/repo`
147 bcb49d15 2019-08-14 stsp local author_time=`git_show_author_time $testroot/repo`
149 78695fb7 2019-08-12 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
151 78695fb7 2019-08-12 stsp local short_commit1=`trim_obj_id 32 $commit1`
153 bcb49d15 2019-08-14 stsp d=`date -r $author_time +"%g/%m/%d"`
154 bcb49d15 2019-08-14 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
156 78695fb7 2019-08-12 stsp cmp -s $testroot/stdout.expected $testroot/stdout
158 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
159 78695fb7 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
161 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
164 c970ea82 2019-07-27 stsp run_test test_blame_basic
165 303e2782 2019-08-09 stsp run_test test_blame_tag
166 78695fb7 2019-08-12 stsp run_test test_blame_file_single_line
167 78695fb7 2019-08-12 stsp run_test test_blame_file_single_line_no_newline