]> git.ipfire.org Git - thirdparty/git.git/blame - t/annotate-tests.sh
t8001/t8002 (blame): add blame -L tests
[thirdparty/git.git] / t / annotate-tests.sh
CommitLineData
8752d11d 1# This file isn't used as a test script directly, instead it is
9b01f003 2# sourced from t8001-annotate.sh and t8002-blame.sh.
8752d11d 3
92a903ac 4check_count () {
e37f39c1 5 head= &&
03e15fc0
ES
6 options= &&
7 while :
8 do
9 case "$1" in
10 -h) head="$2"; shift; shift ;;
11 -*) options="$options $1"; shift ;;
12 *) break ;;
13 esac
14 done &&
15 echo "$PROG $options file $head" >&4 &&
16 $PROG $options file $head >actual &&
e37f39c1 17 perl -e '
92a903ac 18 my %expect = (@ARGV);
27eea66b 19 my %count = map { $_ => 0 } keys %expect;
92a903ac
JH
20 while (<STDIN>) {
21 if (/^[0-9a-f]+\t\(([^\t]+)\t/) {
22 my $author = $1;
23 for ($author) { s/^\s*//; s/\s*$//; }
27eea66b 24 $count{$author}++;
92a903ac
JH
25 }
26 }
27 my $bad = 0;
28 while (my ($author, $count) = each %count) {
29 my $ok;
27eea66b
KB
30 my $value = 0;
31 $value = $expect{$author} if defined $expect{$author};
32 if ($value != $count) {
92a903ac
JH
33 $bad = 1;
34 $ok = "bad";
35 }
36 else {
37 $ok = "good";
38 }
27eea66b 39 print STDERR "Author $author (expected $value, attributed $count) $ok\n";
92a903ac
JH
40 }
41 exit($bad);
e37f39c1 42 ' "$@" <actual
92a903ac
JH
43}
44
e37f39c1
ES
45test_expect_success 'setup A lines' '
46 echo "1A quick brown fox jumps over the" >file &&
47 echo "lazy dog" >>file &&
48 git add file &&
49 GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \
50 git commit -a -m "Initial."
51'
52
53test_expect_success 'blame 1 author' '
54 check_count A 2
55'
56
57test_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."
62'
63
64test_expect_success 'blame 2 authors' '
65 check_count A 2 B 2
66'
67
68test_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"
74'
75
76test_expect_success 'blame 2 authors + 1 branch1 author' '
77 check_count A 2 B 2 B1 2
78'
79
80test_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 &&
83 mv file.new file &&
84 GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" \
85 git commit -a -m "Branch2-1"
86'
87
88test_expect_success 'blame 2 authors + 1 branch2 author' '
89 check_count A 2 B 1 B2 1
90'
91
92test_expect_success 'merge branch1 & branch2' '
93 git pull . branch1
94'
95
96test_expect_success 'blame 2 authors + 2 merged-in authors' '
97 check_count A 2 B 1 B1 2 B2 1
98'
99
100test_expect_success 'blame ancestor' '
101 check_count -h master A 2 B 2
102'
103
104test_expect_success 'blame great-ancestor' '
105 check_count -h master^ A 2
106'
107
108test_expect_success 'setup evil merge' '
109 echo "evil merge." >>file &&
110 git commit -a --amend
111'
112
113test_expect_success 'blame evil merge' '
114 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
115'
116
117test_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"
121'
122
123test_expect_success 'blame incomplete line' '
124 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1
125'
126
127test_expect_success 'setup edits' '
128 mv file file.orig &&
129 {
130 cat file.orig &&
131 echo
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"
136'
137
138test_expect_success 'blame edits' '
139 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1
140'
141
142test_expect_success 'setup obfuscated email' '
143 echo "No robots allowed" >file.new &&
144 cat file >>file.new &&
145 mv file.new file &&
146 GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \
147 git commit -a -m "norobots"
148'
149
150test_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
152'
03e15fc0
ES
153
154test_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
156'
157
158test_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
160'
161
162test_expect_success 'blame -L X (X to end)' '
163 check_count -L5 B1 1 C 1 D 1 "A U Thor" 1
164'
165
166test_expect_success 'blame -L X, (X to end)' '
167 check_count -L5, B1 1 C 1 D 1 "A U Thor" 1
168'
169
170test_expect_success 'blame -L ,Y (up to Y)' '
171 check_count -L,3 A 1 B2 1 E 1
172'
173
174test_expect_success 'blame -L X,X' '
175 check_count -L3,3 B2 1
176'
177
178test_expect_success 'blame -L X,Y' '
179 check_count -L3,6 B 1 B1 1 B2 1 D 1
180'
181
182test_expect_success 'blame -L Y,X (undocumented)' '
183 check_count -L6,3 B 1 B1 1 B2 1 D 1
184'
185
186test_expect_success 'blame -L X,+1' '
187 check_count -L3,+1 B2 1
188'
189
190test_expect_success 'blame -L X,+N' '
191 check_count -L3,+4 B 1 B1 1 B2 1 D 1
192'
193
194test_expect_success 'blame -L X,-1' '
195 check_count -L3,-1 B2 1
196'
197
198test_expect_success 'blame -L X,-N' '
199 check_count -L6,-4 B 1 B1 1 B2 1 D 1
200'
201
202test_expect_success 'blame -L /RE/ (RE to end)' '
203 check_count -L/evil/ C 1 "A U Thor" 1
204'
205
206test_expect_success 'blame -L /RE/,/RE2/' '
207 check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1
208'
209
210test_expect_success 'blame -L X,/RE/' '
211 check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1
212'
213
214test_expect_success 'blame -L /RE/,Y' '
215 check_count -L/99/,7 B1 1 D 1 "A U Thor" 1
216'
217
218test_expect_success 'blame -L /RE/,+N' '
219 check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1
220'
221
222test_expect_success 'blame -L /RE/,-N' '
223 check_count -L/99/,-3 B 1 B2 1 D 1
224'
225
226test_expect_success 'blame -L X (X > nlines)' '
227 test_must_fail $PROG -L12345 file
228'
229
230test_expect_success 'blame -L ,Y (Y > nlines)' '
231 test_must_fail $PROG -L,12345 file
232'
233
234test_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
242'