1 # This file isn't used as a test script directly, instead it is
2 # sourced from t8001-annotate.sh and t8002-blame.sh.
11 -h) head="$2"; shift; shift ;;
12 -f) file="$2"; shift; shift ;;
13 -*) options
="$options $1"; shift ;;
17 echo "$PROG $options $file $head" >&4 &&
18 $PROG $options $file $head >actual
&&
21 my %count = map { $_ => 0 } keys %expect;
23 if (/^[0-9a-f]+\t\(([^\t]+)\t/) {
25 for ($author) { s/^\s*//; s/\s*$//; }
30 while (my ($author, $count) = each %count) {
33 $value = $expect{$author} if defined $expect{$author};
34 if ($value != $count) {
41 print STDERR "Author $author (expected $value, attributed $count) $ok\n";
47 test_expect_success
'setup A lines' '
48 echo "1A quick brown fox jumps over the" >file &&
49 echo "lazy dog" >>file &&
51 GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \
52 git commit -a -m "Initial."
55 test_expect_success
'blame 1 author' '
59 test_expect_success
'setup B lines' '
60 echo "2A quick brown fox jumps over the" >>file &&
61 echo "lazy dog" >>file &&
62 GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \
63 git commit -a -m "Second."
66 test_expect_success
'blame 2 authors' '
70 test_expect_success
'setup B1 lines (branch1)' '
71 git checkout -b branch1 master &&
72 echo "3A slow green fox jumps into the" >>file &&
73 echo "well." >>file &&
74 GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" \
75 git commit -a -m "Branch1-1"
78 test_expect_success
'blame 2 authors + 1 branch1 author' '
79 check_count A 2 B 2 B1 2
82 test_expect_success
'setup B2 lines (branch2)' '
83 git checkout -b branch2 master &&
84 sed -e "s/2A quick brown/4A quick brown lazy dog/" <file >file.new &&
86 GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" \
87 git commit -a -m "Branch2-1"
90 test_expect_success
'blame 2 authors + 1 branch2 author' '
91 check_count A 2 B 1 B2 1
94 test_expect_success
'merge branch1 & branch2' '
98 test_expect_success
'blame 2 authors + 2 merged-in authors' '
99 check_count A 2 B 1 B1 2 B2 1
102 test_expect_success
'blame ancestor' '
103 check_count -h master A 2 B 2
106 test_expect_success
'blame great-ancestor' '
107 check_count -h master^ A 2
110 test_expect_success
'setup evil merge' '
111 echo "evil merge." >>file &&
112 git commit -a --amend
115 test_expect_success
'blame evil merge' '
116 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
119 test_expect_success
'setup incomplete line' '
120 echo "incomplete" | tr -d "\\012" >>file &&
121 GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \
122 git commit -a -m "Incomplete"
125 test_expect_success
'blame incomplete line' '
126 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1
129 test_expect_success
'setup edits' '
134 } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" >file &&
135 echo "incomplete" | tr -d "\\012" >>file &&
136 GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" \
137 git commit -a -m "edit"
140 test_expect_success
'blame edits' '
141 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1
144 test_expect_success
'setup obfuscated email' '
145 echo "No robots allowed" >file.new &&
146 cat file >>file.new &&
148 GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \
149 git commit -a -m "norobots"
152 test_expect_success
'blame obfuscated email' '
153 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
156 test_expect_success
'blame -L 1 (all)' '
157 check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
160 test_expect_success
'blame -L , (all)' '
161 check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
164 test_expect_success
'blame -L X (X to end)' '
165 check_count -L5 B1 1 C 1 D 1 "A U Thor" 1
168 test_expect_success
'blame -L X, (X to end)' '
169 check_count -L5, B1 1 C 1 D 1 "A U Thor" 1
172 test_expect_success
'blame -L ,Y (up to Y)' '
173 check_count -L,3 A 1 B2 1 E 1
176 test_expect_success
'blame -L X,X' '
177 check_count -L3,3 B2 1
180 test_expect_success
'blame -L X,Y' '
181 check_count -L3,6 B 1 B1 1 B2 1 D 1
184 test_expect_success
'blame -L Y,X (undocumented)' '
185 check_count -L6,3 B 1 B1 1 B2 1 D 1
188 test_expect_success
'blame -L X,+1' '
189 check_count -L3,+1 B2 1
192 test_expect_success
'blame -L X,+N' '
193 check_count -L3,+4 B 1 B1 1 B2 1 D 1
196 test_expect_success
'blame -L X,-1' '
197 check_count -L3,-1 B2 1
200 test_expect_success
'blame -L X,-N' '
201 check_count -L6,-4 B 1 B1 1 B2 1 D 1
204 test_expect_success
'blame -L /RE/ (RE to end)' '
205 check_count -L/evil/ C 1 "A U Thor" 1
208 test_expect_success
'blame -L /RE/,/RE2/' '
209 check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1
212 test_expect_success
'blame -L X,/RE/' '
213 check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1
216 test_expect_success
'blame -L /RE/,Y' '
217 check_count -L/99/,7 B1 1 D 1 "A U Thor" 1
220 test_expect_success
'blame -L /RE/,+N' '
221 check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1
224 test_expect_success
'blame -L /RE/,-N' '
225 check_count -L/99/,-3 B 1 B2 1 D 1
228 test_expect_success
'blame -L X (X > nlines)' '
229 test_must_fail $PROG -L12345 file
232 test_expect_success
'blame -L ,Y (Y > nlines)' '
233 test_must_fail $PROG -L,12345 file
236 test_expect_success
'setup -L :regex' '
237 tr Q "\\t" >hello.c <<-\EOF &&
238 int main(int argc, const char *argv[])
244 GIT_AUTHOR_NAME="F" GIT_AUTHOR_EMAIL="F@test.git" \
245 git commit -m "hello" &&
247 mv hello.c hello.orig &&
249 Qputs(\"goodbye\");" <hello.orig | tr Q "\\t" >hello.c &&
250 GIT_AUTHOR_NAME="G" GIT_AUTHOR_EMAIL="G@test.git" \
251 git commit -a -m "goodbye" &&
253 mv hello.c hello.orig &&
254 echo "#include <stdio.h>" >hello.c &&
255 cat hello.orig >>hello.c &&
256 tr Q "\\t" >>hello.c <<-\EOF
262 GIT_AUTHOR_NAME="H" GIT_AUTHOR_EMAIL="H@test.git" \
263 git commit -a -m "mail"
266 test_expect_success
'blame -L :literal' '
267 check_count -f hello.c -L:main F 4 G 1
270 test_expect_success
'blame -L :regex' '
271 check_count -f hello.c "-L:m[a-z][a-z]l" H 4
274 test_expect_success
'blame -L :nomatch' '
275 test_must_fail $PROG -L:nomatch hello.c
278 test_expect_success
'blame -L bogus' '
279 test_must_fail $PROG -L file &&
280 test_must_fail $PROG -L1,+ file &&
281 test_must_fail $PROG -L1,- file &&
282 test_must_fail $PROG -LX file &&
283 test_must_fail $PROG -L1,X file &&
284 test_must_fail $PROG -L1,+N file &&
285 test_must_fail $PROG -L1,-N file