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