Fix some more diff options changes.
[alt-git.git] / t / annotate-tests.sh
blob1148b0257dafd4e9b63e030052b47b527b5c0d3b
1 # This file isn't used as a test script directly, instead it is
2 # sourced from t8001-annotate.sh and t8001-blame.sh.
4 check_count () {
5 head=
6 case "$1" in -h) head="$2"; shift; shift ;; esac
7 $PROG file $head | perl -e '
8 my %expect = (@ARGV);
9 my %count = ();
10 while (<STDIN>) {
11 if (/^[0-9a-f]+\t\(([^\t]+)\t/) {
12 my $author = $1;
13 for ($author) { s/^\s*//; s/\s*$//; }
14 if (exists $expect{$author}) {
15 $count{$author}++;
19 my $bad = 0;
20 while (my ($author, $count) = each %count) {
21 my $ok;
22 if ($expect{$author} != $count) {
23 $bad = 1;
24 $ok = "bad";
26 else {
27 $ok = "good";
29 print STDERR "Author $author (expected $expect{$author}, attributed $count) $ok\n";
31 exit($bad);
32 ' "$@"
35 test_expect_success \
36 'prepare reference tree' \
37 'echo "1A quick brown fox jumps over the" >file &&
38 echo "lazy dog" >>file &&
39 git add file
40 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
42 test_expect_success \
43 'check all lines blamed on A' \
44 'check_count A 2'
46 test_expect_success \
47 'Setup new lines blamed on B' \
48 'echo "2A quick brown fox jumps over the" >>file &&
49 echo "lazy dog" >> file &&
50 GIT_AUTHOR_NAME="B" git commit -a -m "Second."'
52 test_expect_success \
53 'Two lines blamed on A, two on B' \
54 'check_count A 2 B 2'
56 test_expect_success \
57 'merge-setup part 1' \
58 'git checkout -b branch1 master &&
59 echo "3A slow green fox jumps into the" >> file &&
60 echo "well." >> file &&
61 GIT_AUTHOR_NAME="B1" git commit -a -m "Branch1-1"'
63 test_expect_success \
64 'Two lines blamed on A, two on B, two on B1' \
65 'check_count A 2 B 2 B1 2'
67 test_expect_success \
68 'merge-setup part 2' \
69 'git checkout -b branch2 master &&
70 sed -e "s/2A quick brown/4A quick brown lazy dog/" < file > file.new &&
71 mv file.new file &&
72 GIT_AUTHOR_NAME="B2" git commit -a -m "Branch2-1"'
74 test_expect_success \
75 'Two lines blamed on A, one on B, one on B2' \
76 'check_count A 2 B 1 B2 1'
78 test_expect_success \
79 'merge-setup part 3' \
80 'git pull . branch1'
82 test_expect_success \
83 'Two lines blamed on A, one on B, two on B1, one on B2' \
84 'check_count A 2 B 1 B1 2 B2 1'
86 test_expect_success \
87 'Annotating an old revision works' \
88 'check_count -h master A 2 B 2'
90 test_expect_success \
91 'Annotating an old revision works' \
92 'check_count -h master^ A 2'
94 test_expect_success \
95 'merge-setup part 4' \
96 'echo "evil merge." >>file &&
97 EDITOR=: VISUAL=: git commit -a --amend'
99 test_expect_success \
100 'Two lines blamed on A, one on B, two on B1, one on B2, one on A U Thor' \
101 'check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1'
103 test_expect_success \
104 'an incomplete line added' \
105 'echo "incomplete" | tr -d "\\012" >>file &&
106 GIT_AUTHOR_NAME="C" git commit -a -m "Incomplete"'
108 test_expect_success \
109 'With incomplete lines.' \
110 'check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1'
112 test_expect_success \
113 'some edit' \
114 'perl -p -i.orig -e "s/^1A.*\n$//; s/^3A/99/" file &&
115 GIT_AUTHOR_NAME="D" git commit -a -m "edit"'
117 test_expect_success \
118 'some edit' \
119 'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1'