1 # This file isn't used as a test script directly, instead it is
2 # sourced from t8001-annotate.sh and t8002-blame.sh.
10 -h) head="$2"; shift; shift ;;
11 -*) options
="$options $1"; shift ;;
15 echo "$PROG $options file $head" >&4 &&
16 $PROG $options file $head >actual
&&
19 my %count = map { $_ => 0 } keys %expect;
21 if (/^[0-9a-f]+\t\(([^\t]+)\t/) {
23 for ($author) { s/^\s*//; s/\s*$//; }
28 while (my ($author, $count) = each %count) {
31 $value = $expect{$author} if defined $expect{$author};
32 if ($value != $count) {
39 print STDERR "Author $author (expected $value, attributed $count) $ok\n";
45 test_expect_success
'setup A lines' '
46 echo "1A quick brown fox jumps over the" >file &&
47 echo "lazy dog" >>file &&
49 GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \
50 git commit -a -m "Initial."
53 test_expect_success
'blame 1 author' '
57 test_expect_success
'setup B lines' '
58 echo "2A quick brown fox jumps over the" >>file &&
59 echo "lazy dog" >>file &&
60 GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \
61 git commit -a -m "Second."
64 test_expect_success
'blame 2 authors' '
68 test_expect_success
'setup B1 lines (branch1)' '
69 git checkout -b branch1 master &&
70 echo "3A slow green fox jumps into the" >>file &&
71 echo "well." >>file &&
72 GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" \
73 git commit -a -m "Branch1-1"
76 test_expect_success
'blame 2 authors + 1 branch1 author' '
77 check_count A 2 B 2 B1 2
80 test_expect_success
'setup B2 lines (branch2)' '
81 git checkout -b branch2 master &&
82 sed -e "s/2A quick brown/4A quick brown lazy dog/" <file >file.new &&
84 GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" \
85 git commit -a -m "Branch2-1"
88 test_expect_success
'blame 2 authors + 1 branch2 author' '
89 check_count A 2 B 1 B2 1
92 test_expect_success
'merge branch1 & branch2' '
96 test_expect_success
'blame 2 authors + 2 merged-in authors' '
97 check_count A 2 B 1 B1 2 B2 1
100 test_expect_success
'blame ancestor' '
101 check_count -h master A 2 B 2
104 test_expect_success
'blame great-ancestor' '
105 check_count -h master^ A 2
108 test_expect_success
'setup evil merge' '
109 echo "evil merge." >>file &&
110 git commit -a --amend
113 test_expect_success
'blame evil merge' '
114 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
117 test_expect_success
'setup incomplete line' '
118 echo "incomplete" | tr -d "\\012" >>file &&
119 GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \
120 git commit -a -m "Incomplete"
123 test_expect_success
'blame incomplete line' '
124 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1
127 test_expect_success
'setup edits' '
132 } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" >file &&
133 echo "incomplete" | tr -d "\\012" >>file &&
134 GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" \
135 git commit -a -m "edit"
138 test_expect_success
'blame edits' '
139 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1
142 test_expect_success
'setup obfuscated email' '
143 echo "No robots allowed" >file.new &&
144 cat file >>file.new &&
146 GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \
147 git commit -a -m "norobots"
150 test_expect_success
'blame obfuscated email' '
151 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
154 test_expect_success
'blame -L 1 (all)' '
155 check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
158 test_expect_success
'blame -L , (all)' '
159 check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
162 test_expect_success
'blame -L X (X to end)' '
163 check_count -L5 B1 1 C 1 D 1 "A U Thor" 1
166 test_expect_success
'blame -L X, (X to end)' '
167 check_count -L5, B1 1 C 1 D 1 "A U Thor" 1
170 test_expect_success
'blame -L ,Y (up to Y)' '
171 check_count -L,3 A 1 B2 1 E 1
174 test_expect_success
'blame -L X,X' '
175 check_count -L3,3 B2 1
178 test_expect_success
'blame -L X,Y' '
179 check_count -L3,6 B 1 B1 1 B2 1 D 1
182 test_expect_success
'blame -L Y,X (undocumented)' '
183 check_count -L6,3 B 1 B1 1 B2 1 D 1
186 test_expect_success
'blame -L X,+1' '
187 check_count -L3,+1 B2 1
190 test_expect_success
'blame -L X,+N' '
191 check_count -L3,+4 B 1 B1 1 B2 1 D 1
194 test_expect_success
'blame -L X,-1' '
195 check_count -L3,-1 B2 1
198 test_expect_success
'blame -L X,-N' '
199 check_count -L6,-4 B 1 B1 1 B2 1 D 1
202 test_expect_success
'blame -L /RE/ (RE to end)' '
203 check_count -L/evil/ C 1 "A U Thor" 1
206 test_expect_success
'blame -L /RE/,/RE2/' '
207 check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1
210 test_expect_success
'blame -L X,/RE/' '
211 check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1
214 test_expect_success
'blame -L /RE/,Y' '
215 check_count -L/99/,7 B1 1 D 1 "A U Thor" 1
218 test_expect_success
'blame -L /RE/,+N' '
219 check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1
222 test_expect_success
'blame -L /RE/,-N' '
223 check_count -L/99/,-3 B 1 B2 1 D 1
226 test_expect_success
'blame -L X (X > nlines)' '
227 test_must_fail $PROG -L12345 file
230 test_expect_success
'blame -L ,Y (Y > nlines)' '
231 test_must_fail $PROG -L,12345 file
234 test_expect_success
'blame -L bogus' '
235 test_must_fail $PROG -L file &&
236 test_must_fail $PROG -L1,+ file &&
237 test_must_fail $PROG -L1,- file &&
238 test_must_fail $PROG -LX file &&
239 test_must_fail $PROG -L1,X file &&
240 test_must_fail $PROG -L1,+N file &&
241 test_must_fail $PROG -L1,-N file