Blame


1 c970ea82 2019-07-27 stsp #!/bin/sh
2 c970ea82 2019-07-27 stsp #
3 c970ea82 2019-07-27 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 c970ea82 2019-07-27 stsp #
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.
8 c970ea82 2019-07-27 stsp #
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.
16 c970ea82 2019-07-27 stsp
17 c970ea82 2019-07-27 stsp . ./common.sh
18 c970ea82 2019-07-27 stsp
19 c970ea82 2019-07-27 stsp function test_blame_basic {
20 c970ea82 2019-07-27 stsp local testroot=`test_init blame_basic`
21 c970ea82 2019-07-27 stsp
22 c970ea82 2019-07-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 c970ea82 2019-07-27 stsp ret="$?"
24 c970ea82 2019-07-27 stsp if [ "$ret" != "0" ]; then
25 c970ea82 2019-07-27 stsp test_done "$testroot" "$ret"
26 c970ea82 2019-07-27 stsp return 1
27 c970ea82 2019-07-27 stsp fi
28 c970ea82 2019-07-27 stsp
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`
32 c970ea82 2019-07-27 stsp
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`
36 c970ea82 2019-07-27 stsp
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`
41 c970ea82 2019-07-27 stsp
42 c970ea82 2019-07-27 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
43 c970ea82 2019-07-27 stsp
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`
47 c970ea82 2019-07-27 stsp
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
52 c970ea82 2019-07-27 stsp
53 c970ea82 2019-07-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
54 c970ea82 2019-07-27 stsp ret="$?"
55 c970ea82 2019-07-27 stsp if [ "$ret" != "0" ]; then
56 c970ea82 2019-07-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
57 c970ea82 2019-07-27 stsp fi
58 c970ea82 2019-07-27 stsp
59 c970ea82 2019-07-27 stsp test_done "$testroot" "$ret"
60 c970ea82 2019-07-27 stsp }
61 c970ea82 2019-07-27 stsp
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
65 303e2782 2019-08-09 stsp
66 303e2782 2019-08-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
67 303e2782 2019-08-09 stsp ret="$?"
68 303e2782 2019-08-09 stsp if [ "$ret" != "0" ]; then
69 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
70 303e2782 2019-08-09 stsp return 1
71 303e2782 2019-08-09 stsp fi
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`
75 303e2782 2019-08-09 stsp
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`
79 303e2782 2019-08-09 stsp
80 303e2782 2019-08-09 stsp (cd $testroot/repo && git tag -a -m "test" $tag)
81 303e2782 2019-08-09 stsp
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`
86 303e2782 2019-08-09 stsp
87 303e2782 2019-08-09 stsp (cd $testroot/wt && got blame -c $tag alpha > $testroot/stdout)
88 303e2782 2019-08-09 stsp
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`
91 303e2782 2019-08-09 stsp
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
95 303e2782 2019-08-09 stsp
96 303e2782 2019-08-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
97 303e2782 2019-08-09 stsp ret="$?"
98 303e2782 2019-08-09 stsp if [ "$ret" != "0" ]; then
99 303e2782 2019-08-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
100 303e2782 2019-08-09 stsp fi
101 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
102 303e2782 2019-08-09 stsp }
103 303e2782 2019-08-09 stsp
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`
106 78695fb7 2019-08-12 stsp
107 78695fb7 2019-08-12 stsp got checkout $testroot/repo $testroot/wt > /dev/null
108 78695fb7 2019-08-12 stsp ret="$?"
109 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
110 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
111 78695fb7 2019-08-12 stsp return 1
112 78695fb7 2019-08-12 stsp fi
113 78695fb7 2019-08-12 stsp
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`
118 78695fb7 2019-08-12 stsp
119 78695fb7 2019-08-12 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
120 78695fb7 2019-08-12 stsp
121 78695fb7 2019-08-12 stsp local short_commit1=`trim_obj_id 32 $commit1`
122 78695fb7 2019-08-12 stsp
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
125 78695fb7 2019-08-12 stsp
126 78695fb7 2019-08-12 stsp cmp -s $testroot/stdout.expected $testroot/stdout
127 78695fb7 2019-08-12 stsp ret="$?"
128 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
129 78695fb7 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
130 78695fb7 2019-08-12 stsp fi
131 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
132 78695fb7 2019-08-12 stsp }
133 78695fb7 2019-08-12 stsp
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`
136 78695fb7 2019-08-12 stsp
137 78695fb7 2019-08-12 stsp got checkout $testroot/repo $testroot/wt > /dev/null
138 78695fb7 2019-08-12 stsp ret="$?"
139 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
140 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
141 78695fb7 2019-08-12 stsp return 1
142 78695fb7 2019-08-12 stsp fi
143 78695fb7 2019-08-12 stsp
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`
148 78695fb7 2019-08-12 stsp
149 78695fb7 2019-08-12 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
150 78695fb7 2019-08-12 stsp
151 78695fb7 2019-08-12 stsp local short_commit1=`trim_obj_id 32 $commit1`
152 78695fb7 2019-08-12 stsp
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
155 78695fb7 2019-08-12 stsp
156 78695fb7 2019-08-12 stsp cmp -s $testroot/stdout.expected $testroot/stdout
157 78695fb7 2019-08-12 stsp ret="$?"
158 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
159 78695fb7 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
160 78695fb7 2019-08-12 stsp fi
161 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
162 78695fb7 2019-08-12 stsp }
163 78695fb7 2019-08-12 stsp
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