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 function test_blame_all_lines_replaced {
165 local testroot=`test_init blame_all_lines_replaced`
167 got checkout $testroot/repo $testroot/wt > /dev/null
168 ret="$?"
169 if [ "$ret" != "0" ]; then
170 test_done "$testroot" "$ret"
171 return 1
172 fi
174 jot 8 > $testroot/wt/alpha
175 (cd $testroot/wt && got commit -m "change 1" > /dev/null)
176 local commit1=`git_show_head $testroot/repo`
177 local short_commit1=`trim_obj_id 32 $commit1`
178 local author_time=`git_show_author_time $testroot/repo`
180 (cd $testroot/wt && got blame alpha > $testroot/stdout)
182 d=`date -r $author_time +"%g/%m/%d"`
183 echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
184 echo "2) $short_commit1 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
185 echo "3) $short_commit1 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected
186 echo "4) $short_commit1 $d $GOT_AUTHOR_8 4" >> $testroot/stdout.expected
187 echo "5) $short_commit1 $d $GOT_AUTHOR_8 5" >> $testroot/stdout.expected
188 echo "6) $short_commit1 $d $GOT_AUTHOR_8 6" >> $testroot/stdout.expected
189 echo "7) $short_commit1 $d $GOT_AUTHOR_8 7" >> $testroot/stdout.expected
190 echo "8) $short_commit1 $d $GOT_AUTHOR_8 8" >> $testroot/stdout.expected
192 cmp -s $testroot/stdout.expected $testroot/stdout
193 ret="$?"
194 if [ "$ret" != "0" ]; then
195 diff -u $testroot/stdout.expected $testroot/stdout
196 fi
197 test_done "$testroot" "$ret"
201 function test_blame_lines_shifted_up {
202 local testroot=`test_init blame_lines_shifted_up`
204 got checkout $testroot/repo $testroot/wt > /dev/null
205 ret="$?"
206 if [ "$ret" != "0" ]; then
207 test_done "$testroot" "$ret"
208 return 1
209 fi
211 jot 8 > $testroot/wt/alpha
212 (cd $testroot/wt && got commit -m "change 1" > /dev/null)
213 local commit1=`git_show_head $testroot/repo`
214 local short_commit1=`trim_obj_id 32 $commit1`
215 local author_time=`git_show_author_time $testroot/repo`
217 sed -i -e '/^[345]$/d' $testroot/wt/alpha
218 (cd $testroot/wt && got commit -m "change 2" > /dev/null)
219 local commit2=`git_show_head $testroot/repo`
220 local short_commit2=`trim_obj_id 32 $commit2`
222 jot 2 > $testroot/wt/alpha
223 echo foo >> $testroot/wt/alpha
224 echo bar >> $testroot/wt/alpha
225 echo baz >> $testroot/wt/alpha
226 jot 8 6 8 1 >> $testroot/wt/alpha
227 (cd $testroot/wt && got commit -m "change 3" > /dev/null)
228 local commit3=`git_show_head $testroot/repo`
229 local short_commit3=`trim_obj_id 32 $commit3`
230 local author_time=`git_show_author_time $testroot/repo`
232 (cd $testroot/wt && got blame alpha > $testroot/stdout)
234 d=`date -r $author_time +"%g/%m/%d"`
235 echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
236 echo "2) $short_commit1 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
237 echo "3) $short_commit3 $d $GOT_AUTHOR_8 foo" >> $testroot/stdout.expected
238 echo "4) $short_commit3 $d $GOT_AUTHOR_8 bar" >> $testroot/stdout.expected
239 echo "5) $short_commit3 $d $GOT_AUTHOR_8 baz" >> $testroot/stdout.expected
240 echo "6) $short_commit1 $d $GOT_AUTHOR_8 6" >> $testroot/stdout.expected
241 echo "7) $short_commit1 $d $GOT_AUTHOR_8 7" >> $testroot/stdout.expected
242 echo "8) $short_commit1 $d $GOT_AUTHOR_8 8" >> $testroot/stdout.expected
244 cmp -s $testroot/stdout.expected $testroot/stdout
245 ret="$?"
246 if [ "$ret" != "0" ]; then
247 diff -u $testroot/stdout.expected $testroot/stdout
248 fi
250 test_done "$testroot" "$ret"
253 function test_blame_lines_shifted_down {
254 local testroot=`test_init blame_lines_shifted_down`
256 got checkout $testroot/repo $testroot/wt > /dev/null
257 ret="$?"
258 if [ "$ret" != "0" ]; then
259 test_done "$testroot" "$ret"
260 return 1
261 fi
263 jot 8 > $testroot/wt/alpha
264 (cd $testroot/wt && got commit -m "change 1" > /dev/null)
265 local commit1=`git_show_head $testroot/repo`
266 local short_commit1=`trim_obj_id 32 $commit1`
267 local author_time=`git_show_author_time $testroot/repo`
269 sed -i -e '/^8$/d' $testroot/wt/alpha
270 (cd $testroot/wt && got commit -m "change 2" > /dev/null)
271 local commit2=`git_show_head $testroot/repo`
272 local short_commit2=`trim_obj_id 32 $commit2`
274 jot 2 > $testroot/wt/alpha
275 echo foo >> $testroot/wt/alpha
276 echo bar >> $testroot/wt/alpha
277 echo baz >> $testroot/wt/alpha
278 jot 8 3 8 1 >> $testroot/wt/alpha
279 (cd $testroot/wt && got commit -m "change 3" > /dev/null)
280 local commit3=`git_show_head $testroot/repo`
281 local short_commit3=`trim_obj_id 32 $commit3`
282 local author_time=`git_show_author_time $testroot/repo`
284 (cd $testroot/wt && got blame alpha > $testroot/stdout)
286 d=`date -r $author_time +"%g/%m/%d"`
287 echo "01) $short_commit1 $d $GOT_AUTHOR_8 1" \
288 > $testroot/stdout.expected
289 echo "02) $short_commit1 $d $GOT_AUTHOR_8 2" \
290 >> $testroot/stdout.expected
291 echo "03) $short_commit3 $d $GOT_AUTHOR_8 foo" \
292 >> $testroot/stdout.expected
293 echo "04) $short_commit3 $d $GOT_AUTHOR_8 bar" \
294 >> $testroot/stdout.expected
295 echo "05) $short_commit3 $d $GOT_AUTHOR_8 baz" \
296 >> $testroot/stdout.expected
297 echo "06) $short_commit1 $d $GOT_AUTHOR_8 3" \
298 >> $testroot/stdout.expected
299 echo "07) $short_commit1 $d $GOT_AUTHOR_8 4" \
300 >> $testroot/stdout.expected
301 echo "08) $short_commit1 $d $GOT_AUTHOR_8 5" \
302 >> $testroot/stdout.expected
303 echo "09) $short_commit1 $d $GOT_AUTHOR_8 6" \
304 >> $testroot/stdout.expected
305 echo "10) $short_commit1 $d $GOT_AUTHOR_8 7" \
306 >> $testroot/stdout.expected
307 echo "11) $short_commit3 $d $GOT_AUTHOR_8 8" \
308 >> $testroot/stdout.expected
310 cmp -s $testroot/stdout.expected $testroot/stdout
311 ret="$?"
312 if [ "$ret" != "0" ]; then
313 diff -u $testroot/stdout.expected $testroot/stdout
314 fi
316 test_done "$testroot" "$ret"
319 function test_blame_commit_subsumed {
320 local testroot=`test_init blame_commit_subsumed`
322 got checkout $testroot/repo $testroot/wt > /dev/null
323 ret="$?"
324 if [ "$ret" != "0" ]; then
325 test_done "$testroot" "$ret"
326 return 1
327 fi
329 cat > $testroot/wt/alpha <<EOF
330 SUBDIRS = ext modules codedocs docs
332 if WITH_PDNS_SERVER
333 SUBDIRS += pdns
334 endif
336 EXTRA_DIST =
337 INSTALL
338 NOTICE
339 README
340 .version
341 build-aux/gen-version
342 codedocs/doxygen.conf
343 contrib/powerdns.solaris.init.d
344 pdns/named.conf.parsertest
345 regression-tests/zones/unit.test
347 ACLOCAL_AMFLAGS = -I m4
349 dvi: # do nothing to build dvi
350 EOF
351 (cd $testroot/wt && got commit -m "change 1" > /dev/null)
352 local commit1=`git_show_head $testroot/repo`
353 local short_commit1=`trim_obj_id 32 $commit1`
354 local author_time1=`git_show_author_time $testroot/repo`
355 local d1=`date -r $author_time1 +"%g/%m/%d"`
357 cat > $testroot/wt/alpha <<EOF
358 SUBDIRS = ext modules codedocs docs
360 SUBDIRS += pdns
362 EXTRA_DIST =
363 INSTALL
364 NOTICE
365 README
366 .version
367 build-aux/gen-version
368 codedocs/doxygen.conf
369 contrib/powerdns.solaris.init.d
370 pdns/named.conf.parsertest
371 regression-tests/zones/unit.test
373 ACLOCAL_AMFLAGS = -I m4
375 dvi: # do nothing to build dvi
376 EOF
377 # all changes in this commit will be subsumed by later commits
378 (cd $testroot/wt && got commit -m "change 2" > /dev/null)
379 local commit2=`git_show_head $testroot/repo`
380 local short_commit2=`trim_obj_id 32 $commit2`
381 local author_time2=`git_show_author_time $testroot/repo`
382 local d2=`date -r $author_time2 +"%g/%m/%d"`
384 cat > $testroot/wt/alpha <<EOF
385 SUBDIRS = ext modules pdns codedocs docs
387 EXTRA_DIST =
388 INSTALL
389 NOTICE
390 README
391 .version
392 build-aux/gen-version
393 codedocs/doxygen.conf
394 contrib/powerdns.solaris.init.d
395 pdns/named.conf.parsertest
396 regression-tests/zones/unit.test
398 ACLOCAL_AMFLAGS = -I m4
400 dvi: # do nothing to build dvi
401 EOF
402 (cd $testroot/wt && got commit -m "change 3" > /dev/null)
403 local commit3=`git_show_head $testroot/repo`
404 local short_commit3=`trim_obj_id 32 $commit3`
405 local author_time3=`git_show_author_time $testroot/repo`
406 local d3=`date -r $author_time3 +"%g/%m/%d"`
408 cat > $testroot/wt/alpha <<EOF
409 SUBDIRS = ext modules pdns codedocs docs
411 EXTRA_DIST =
412 INSTALL
413 NOTICE
414 README
415 COPYING
416 codedocs/doxygen.conf
417 contrib/powerdns.solaris.init.d
418 pdns/named.conf.parsertest
419 regression-tests/zones/unit.test
420 builder-support/gen-version
422 ACLOCAL_AMFLAGS = -I m4
424 dvi: # do nothing to build dvi
425 EOF
426 (cd $testroot/wt && got commit -m "change 4" > /dev/null)
427 local commit4=`git_show_head $testroot/repo`
428 local short_commit4=`trim_obj_id 32 $commit4`
429 local author_time4=`git_show_author_time $testroot/repo`
430 local d4=`date -r $author_time4 +"%g/%m/%d"`
432 (cd $testroot/wt && got blame alpha > $testroot/stdout)
434 echo -n "01) $short_commit3 $d3 $GOT_AUTHOR_8 " \
435 > $testroot/stdout.expected
436 echo "SUBDIRS = ext modules pdns codedocs docs" \
437 >> $testroot/stdout.expected
438 echo "02) $short_commit1 $d1 $GOT_AUTHOR_8 " \
439 >> $testroot/stdout.expected
440 echo -n "03) $short_commit1 $d1 $GOT_AUTHOR_8 " \
441 >> $testroot/stdout.expected
442 echo 'EXTRA_DIST =' >> $testroot/stdout.expected
443 echo -n "04) $short_commit1 $d1 $GOT_AUTHOR_8 " \
444 >> $testroot/stdout.expected
445 printf "\tINSTALL\n" >> $testroot/stdout.expected
446 echo -n "05) $short_commit1 $d1 $GOT_AUTHOR_8 " \
447 >> $testroot/stdout.expected
448 printf "\tNOTICE\n" >> $testroot/stdout.expected
449 echo -n "06) $short_commit1 $d1 $GOT_AUTHOR_8 " \
450 >> $testroot/stdout.expected
451 printf "\tREADME\n" >> $testroot/stdout.expected
452 echo -n "07) $short_commit4 $d4 $GOT_AUTHOR_8 " \
453 >> $testroot/stdout.expected
454 printf "\tCOPYING\n" >> $testroot/stdout.expected
455 echo -n "08) $short_commit1 $d1 $GOT_AUTHOR_8 " \
456 >> $testroot/stdout.expected
457 printf "\tcodedocs/doxygen.conf\n" >> $testroot/stdout.expected
458 echo -n "09) $short_commit1 $d1 $GOT_AUTHOR_8 " \
459 >> $testroot/stdout.expected
460 printf "\tcontrib/powerdns.solaris.init.d\n" \
461 >> $testroot/stdout.expected
462 echo -n "10) $short_commit1 $d1 $GOT_AUTHOR_8 " \
463 >> $testroot/stdout.expected
464 printf "\tpdns/named.conf.parsertest\n" >> $testroot/stdout.expected
465 echo -n "11) $short_commit1 $d1 $GOT_AUTHOR_8 " \
466 >> $testroot/stdout.expected
467 printf "\tregression-tests/zones/unit.test\n" \
468 >> $testroot/stdout.expected
469 echo -n "12) $short_commit4 $d4 $GOT_AUTHOR_8 " \
470 >> $testroot/stdout.expected
471 printf "\tbuilder-support/gen-version\n" >> $testroot/stdout.expected
472 echo "13) $short_commit1 $d1 $GOT_AUTHOR_8 " \
473 >> $testroot/stdout.expected
474 echo -n "14) $short_commit1 $d1 $GOT_AUTHOR_8 " \
475 >> $testroot/stdout.expected
476 echo "ACLOCAL_AMFLAGS = -I m4" \
477 >> $testroot/stdout.expected
478 echo "15) $short_commit1 $d1 $GOT_AUTHOR_8 " \
479 >> $testroot/stdout.expected
480 echo -n "16) $short_commit1 $d1 $GOT_AUTHOR_8 " \
481 >> $testroot/stdout.expected
482 echo "dvi: # do nothing to build dvi" \
483 >> $testroot/stdout.expected
485 cmp -s $testroot/stdout.expected $testroot/stdout
486 ret="$?"
487 if [ "$ret" != "0" ]; then
488 diff -u $testroot/stdout.expected $testroot/stdout
489 test_done "$testroot" "$ret"
490 return 1
491 fi
492 test_done "$testroot" "$ret"
495 run_test test_blame_basic
496 run_test test_blame_tag
497 run_test test_blame_file_single_line
498 run_test test_blame_file_single_line_no_newline
499 run_test test_blame_all_lines_replaced
500 run_test test_blame_lines_shifted_up
501 run_test test_blame_lines_shifted_down
502 run_test test_blame_commit_subsumed