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 c970ea82 2019-07-27 stsp
41 c970ea82 2019-07-27 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
42 c970ea82 2019-07-27 stsp
43 c970ea82 2019-07-27 stsp local short_commit1=`trim_obj_id 32 $commit1`
44 c970ea82 2019-07-27 stsp local short_commit2=`trim_obj_id 32 $commit2`
45 c970ea82 2019-07-27 stsp local short_commit3=`trim_obj_id 32 $commit3`
46 c970ea82 2019-07-27 stsp
47 c970ea82 2019-07-27 stsp echo "$short_commit1 1" > $testroot/stdout.expected
48 c970ea82 2019-07-27 stsp echo "$short_commit2 2" >> $testroot/stdout.expected
49 c970ea82 2019-07-27 stsp echo "$short_commit3 3" >> $testroot/stdout.expected
50 c970ea82 2019-07-27 stsp
51 c970ea82 2019-07-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
52 c970ea82 2019-07-27 stsp ret="$?"
53 c970ea82 2019-07-27 stsp if [ "$ret" != "0" ]; then
54 c970ea82 2019-07-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
55 c970ea82 2019-07-27 stsp fi
56 c970ea82 2019-07-27 stsp
57 c970ea82 2019-07-27 stsp test_done "$testroot" "$ret"
58 c970ea82 2019-07-27 stsp }
59 c970ea82 2019-07-27 stsp
60 303e2782 2019-08-09 stsp function test_blame_tag {
61 303e2782 2019-08-09 stsp local testroot=`test_init blame_tag`
62 303e2782 2019-08-09 stsp local tag=1.0.0
63 303e2782 2019-08-09 stsp
64 303e2782 2019-08-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
65 303e2782 2019-08-09 stsp ret="$?"
66 303e2782 2019-08-09 stsp if [ "$ret" != "0" ]; then
67 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
68 303e2782 2019-08-09 stsp return 1
69 303e2782 2019-08-09 stsp fi
70 303e2782 2019-08-09 stsp echo 1 > $testroot/wt/alpha
71 303e2782 2019-08-09 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
72 303e2782 2019-08-09 stsp local commit1=`git_show_head $testroot/repo`
73 303e2782 2019-08-09 stsp
74 303e2782 2019-08-09 stsp echo 2 >> $testroot/wt/alpha
75 303e2782 2019-08-09 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
76 303e2782 2019-08-09 stsp local commit2=`git_show_head $testroot/repo`
77 303e2782 2019-08-09 stsp
78 303e2782 2019-08-09 stsp (cd $testroot/repo && git tag -a -m "test" $tag)
79 303e2782 2019-08-09 stsp
80 303e2782 2019-08-09 stsp echo 3 >> $testroot/wt/alpha
81 303e2782 2019-08-09 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
82 303e2782 2019-08-09 stsp local commit3=`git_show_head $testroot/repo`
83 303e2782 2019-08-09 stsp
84 303e2782 2019-08-09 stsp (cd $testroot/wt && got blame -c $tag alpha > $testroot/stdout)
85 303e2782 2019-08-09 stsp
86 303e2782 2019-08-09 stsp local short_commit1=`trim_obj_id 32 $commit1`
87 303e2782 2019-08-09 stsp local short_commit2=`trim_obj_id 32 $commit2`
88 303e2782 2019-08-09 stsp
89 303e2782 2019-08-09 stsp echo "$short_commit1 1" > $testroot/stdout.expected
90 303e2782 2019-08-09 stsp echo "$short_commit2 2" >> $testroot/stdout.expected
91 303e2782 2019-08-09 stsp
92 303e2782 2019-08-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
93 303e2782 2019-08-09 stsp ret="$?"
94 303e2782 2019-08-09 stsp if [ "$ret" != "0" ]; then
95 303e2782 2019-08-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
96 303e2782 2019-08-09 stsp fi
97 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
98 303e2782 2019-08-09 stsp }
99 303e2782 2019-08-09 stsp
100 78695fb7 2019-08-12 stsp function test_blame_file_single_line {
101 78695fb7 2019-08-12 stsp local testroot=`test_init blame_file_single_line`
102 78695fb7 2019-08-12 stsp
103 78695fb7 2019-08-12 stsp got checkout $testroot/repo $testroot/wt > /dev/null
104 78695fb7 2019-08-12 stsp ret="$?"
105 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
106 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
107 78695fb7 2019-08-12 stsp return 1
108 78695fb7 2019-08-12 stsp fi
109 78695fb7 2019-08-12 stsp
110 78695fb7 2019-08-12 stsp echo 1 > $testroot/wt/alpha
111 78695fb7 2019-08-12 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
112 78695fb7 2019-08-12 stsp local commit1=`git_show_head $testroot/repo`
113 78695fb7 2019-08-12 stsp
114 78695fb7 2019-08-12 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
115 78695fb7 2019-08-12 stsp
116 78695fb7 2019-08-12 stsp local short_commit1=`trim_obj_id 32 $commit1`
117 78695fb7 2019-08-12 stsp
118 78695fb7 2019-08-12 stsp echo "$short_commit1 1" > $testroot/stdout.expected
119 78695fb7 2019-08-12 stsp
120 78695fb7 2019-08-12 stsp cmp -s $testroot/stdout.expected $testroot/stdout
121 78695fb7 2019-08-12 stsp ret="$?"
122 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
123 78695fb7 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
124 78695fb7 2019-08-12 stsp fi
125 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
126 78695fb7 2019-08-12 stsp }
127 78695fb7 2019-08-12 stsp
128 78695fb7 2019-08-12 stsp function test_blame_file_single_line_no_newline {
129 78695fb7 2019-08-12 stsp local testroot=`test_init blame_file_single_line_no_newline`
130 78695fb7 2019-08-12 stsp
131 78695fb7 2019-08-12 stsp got checkout $testroot/repo $testroot/wt > /dev/null
132 78695fb7 2019-08-12 stsp ret="$?"
133 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
134 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
135 78695fb7 2019-08-12 stsp return 1
136 78695fb7 2019-08-12 stsp fi
137 78695fb7 2019-08-12 stsp
138 78695fb7 2019-08-12 stsp echo -n 1 > $testroot/wt/alpha
139 78695fb7 2019-08-12 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
140 78695fb7 2019-08-12 stsp local commit1=`git_show_head $testroot/repo`
141 78695fb7 2019-08-12 stsp
142 78695fb7 2019-08-12 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
143 78695fb7 2019-08-12 stsp
144 78695fb7 2019-08-12 stsp local short_commit1=`trim_obj_id 32 $commit1`
145 78695fb7 2019-08-12 stsp
146 78695fb7 2019-08-12 stsp echo "$short_commit1 1" > $testroot/stdout.expected
147 78695fb7 2019-08-12 stsp
148 78695fb7 2019-08-12 stsp cmp -s $testroot/stdout.expected $testroot/stdout
149 78695fb7 2019-08-12 stsp ret="$?"
150 78695fb7 2019-08-12 stsp if [ "$ret" != "0" ]; then
151 78695fb7 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
152 78695fb7 2019-08-12 stsp fi
153 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
154 78695fb7 2019-08-12 stsp }
155 78695fb7 2019-08-12 stsp
156 c970ea82 2019-07-27 stsp run_test test_blame_basic
157 303e2782 2019-08-09 stsp run_test test_blame_tag
158 78695fb7 2019-08-12 stsp run_test test_blame_file_single_line
159 78695fb7 2019-08-12 stsp run_test test_blame_file_single_line_no_newline