Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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 function test_blame_basic {
20 local testroot=`test_init blame_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo 1 > $testroot/wt/alpha
30 (cd $testroot/wt && got commit -m "change 1" > /dev/null)
31 local commit1=`git_show_head $testroot/repo`
33 echo 2 >> $testroot/wt/alpha
34 (cd $testroot/wt && got commit -m "change 2" > /dev/null)
35 local commit2=`git_show_head $testroot/repo`
37 echo 3 >> $testroot/wt/alpha
38 (cd $testroot/wt && got commit -m "change 3" > /dev/null)
39 local commit3=`git_show_head $testroot/repo`
40 local author_time=`git_show_author_time $testroot/repo`
42 (cd $testroot/wt && got blame alpha > $testroot/stdout)
44 local short_commit1=`trim_obj_id 32 $commit1`
45 local short_commit2=`trim_obj_id 32 $commit2`
46 local short_commit3=`trim_obj_id 32 $commit3`
48 d=`date -r $author_time +"%g/%m/%d"`
49 echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
50 echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
51 echo "3) $short_commit3 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected
53 cmp -s $testroot/stdout.expected $testroot/stdout
54 ret="$?"
55 if [ "$ret" != "0" ]; then
56 diff -u $testroot/stdout.expected $testroot/stdout
57 fi
59 test_done "$testroot" "$ret"
60 }
62 function test_blame_tag {
63 local testroot=`test_init blame_tag`
64 local tag=1.0.0
66 got checkout $testroot/repo $testroot/wt > /dev/null
67 ret="$?"
68 if [ "$ret" != "0" ]; then
69 test_done "$testroot" "$ret"
70 return 1
71 fi
72 echo 1 > $testroot/wt/alpha
73 (cd $testroot/wt && got commit -m "change 1" > /dev/null)
74 local commit1=`git_show_head $testroot/repo`
76 echo 2 >> $testroot/wt/alpha
77 (cd $testroot/wt && got commit -m "change 2" > /dev/null)
78 local commit2=`git_show_head $testroot/repo`
80 (cd $testroot/repo && git tag -a -m "test" $tag)
82 echo 3 >> $testroot/wt/alpha
83 (cd $testroot/wt && got commit -m "change 3" > /dev/null)
84 local commit3=`git_show_head $testroot/repo`
85 local author_time=`git_show_author_time $testroot/repo`
87 (cd $testroot/wt && got blame -c $tag alpha > $testroot/stdout)
89 local short_commit1=`trim_obj_id 32 $commit1`
90 local short_commit2=`trim_obj_id 32 $commit2`
92 d=`date -r $author_time +"%g/%m/%d"`
93 echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
94 echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
96 cmp -s $testroot/stdout.expected $testroot/stdout
97 ret="$?"
98 if [ "$ret" != "0" ]; then
99 diff -u $testroot/stdout.expected $testroot/stdout
100 fi
101 test_done "$testroot" "$ret"
104 function test_blame_file_single_line {
105 local testroot=`test_init blame_file_single_line`
107 got checkout $testroot/repo $testroot/wt > /dev/null
108 ret="$?"
109 if [ "$ret" != "0" ]; then
110 test_done "$testroot" "$ret"
111 return 1
112 fi
114 echo 1 > $testroot/wt/alpha
115 (cd $testroot/wt && got commit -m "change 1" > /dev/null)
116 local commit1=`git_show_head $testroot/repo`
117 local author_time=`git_show_author_time $testroot/repo`
119 (cd $testroot/wt && got blame alpha > $testroot/stdout)
121 local short_commit1=`trim_obj_id 32 $commit1`
123 d=`date -r $author_time +"%g/%m/%d"`
124 echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
126 cmp -s $testroot/stdout.expected $testroot/stdout
127 ret="$?"
128 if [ "$ret" != "0" ]; then
129 diff -u $testroot/stdout.expected $testroot/stdout
130 fi
131 test_done "$testroot" "$ret"
134 function test_blame_file_single_line_no_newline {
135 local testroot=`test_init blame_file_single_line_no_newline`
137 got checkout $testroot/repo $testroot/wt > /dev/null
138 ret="$?"
139 if [ "$ret" != "0" ]; then
140 test_done "$testroot" "$ret"
141 return 1
142 fi
144 echo -n 1 > $testroot/wt/alpha
145 (cd $testroot/wt && got commit -m "change 1" > /dev/null)
146 local commit1=`git_show_head $testroot/repo`
147 local author_time=`git_show_author_time $testroot/repo`
149 (cd $testroot/wt && got blame alpha > $testroot/stdout)
151 local short_commit1=`trim_obj_id 32 $commit1`
153 d=`date -r $author_time +"%g/%m/%d"`
154 echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
156 cmp -s $testroot/stdout.expected $testroot/stdout
157 ret="$?"
158 if [ "$ret" != "0" ]; then
159 diff -u $testroot/stdout.expected $testroot/stdout
160 fi
161 test_done "$testroot" "$ret"
164 run_test test_blame_basic
165 run_test test_blame_tag
166 run_test test_blame_file_single_line
167 run_test test_blame_file_single_line_no_newline