annotate/blame tests updates.
This rewrites the result check code a bit. The earlier one using awk was splitting columns at any whitespace, which confused lines attributed incorrectly to the merge made by the default author "A U Thor <author@example.com>" with lines attributed to author "A". The latest test by Ryan to add the "starting from older commit" test is also included, with another older commit test. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Mar 5, 2006 at 22:07 UTC
92a903acfd0904e6dd6d18112428429938783d19
1 file changed
+44
-37
t/annotate-tests.sh
+44
-37
@@ -1,6 +1,37 @@
1
# This file isn't used as a test script directly, instead it is
2
# sourced from t8001-annotate.sh and t8001-blame.sh.
3
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}++;
16
+ }
17
+ }
18
+ }
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";
25
+ }
26
+ else {
27
+ $ok = "good";
28
+ }
29
+ print STDERR "Author $author (expected $expect{$author}, attributed $count) $ok\n";
30
+ }
31
+ exit($bad);
32
+ ' "$@"
33
+}
34
+
35
test_expect_success \
36
'prepare reference tree' \
37
'echo "1A quick brown fox jumps over the" >file &&
@@ -10,7 +41,7 @@ test_expect_success \
41
42
test_expect_success \
43
'check all lines blamed on A' \
13
- '[ $(git annotate file | awk "{print \$3}" | grep -c "A") == 2 ]'
44
+ 'check_count A 2'
45
46
test_expect_success \
47
'Setup new lines blamed on B' \
@@ -19,12 +50,8 @@ test_expect_success \
50
GIT_AUTHOR_NAME="B" git commit -a -m "Second."'
51
52
test_expect_success \
22
- 'Two lines blamed on A' \
23
- '[ $($PROG file | awk "{print \$3}" | grep -c "A") == 2 ]'
24
-
25
-test_expect_success \
26
- 'Two lines blamed on B' \
27
- '[ $($PROG file | awk "{print \$3}" | grep -c "B") == 2 ]'
53
+ 'Two lines blamed on A, two on B' \
54
+ 'check_count A 2 B 2'
55
56
test_expect_success \
57
'merge-setup part 1' \
@@ -34,16 +61,8 @@ test_expect_success \
61
GIT_AUTHOR_NAME="B1" git commit -a -m "Branch1-1"'
62
63
test_expect_success \
37
- 'Two lines blamed on A' \
38
- '[ $($PROG file | awk "{print \$3}" | grep -c "^A$") == 2 ]'
39
-
40
-test_expect_success \
41
- 'Two lines blamed on B' \
42
- '[ $($PROG file | awk "{print \$3}" | grep -c "^B$") == 2 ]'
43
-
44
-test_expect_success \
45
- 'Two lines blamed on B1' \
46
- '[ $($PROG file | awk "{print \$3}" | grep -c "^B1$") == 2 ]'
64
+ 'Two lines blamed on A, two on B, two on B1' \
65
+ 'check_count A 2 B 2 B1 2'
66
67
test_expect_success \
68
'merge-setup part 2' \
@@ -53,34 +72,22 @@ test_expect_success \
72
GIT_AUTHOR_NAME="B2" git commit -a -m "Branch2-1"'
73
74
test_expect_success \
56
- 'Two lines blamed on A' \
57
- '[ $($PROG file | awk "{print \$3}" | grep -c "^A$") == 2 ]'
58
-
59
-test_expect_success \
60
- 'One line blamed on B' \
61
- '[ $($PROG file | awk "{print \$3}" | grep -c "^B$") == 1 ]'
62
-
63
-test_expect_success \
64
- 'One line blamed on B2' \
65
- '[ $($PROG file | awk "{print \$3}" | grep -c "^B2$") == 1 ]'
66
-
75
+ 'Two lines blamed on A, one on B, one on B2' \
76
+ 'check_count A 2 B 1 B2 1'
77
78
test_expect_success \
79
'merge-setup part 3' \
80
'git pull . branch1'
81
82
test_expect_success \
73
- 'Two lines blamed on A' \
74
- '[ $($PROG file | awk "{print \$3}" | grep -c "^A$") == 2 ]'
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'
85
86
test_expect_success \
77
- 'One line blamed on B' \
78
- '[ $($PROG file | awk "{print \$3}" | grep -c "^B$") == 1 ]'
87
+ 'Annotating an old revision works' \
88
+ 'check_count -h master A 2 B 2'
89
90
test_expect_success \
81
- 'Two lines blamed on B1' \
82
- '[ $($PROG file | awk "{print \$3}" | grep -c "^B1$") == 2 ]'
91
+ 'Annotating an old revision works' \
92
+ 'check_count -h master^ A 2'
93
84
-test_expect_success \
85
- 'One line blamed on B2' \
86
- '[ $($PROG file | awk "{print \$3}" | grep -c "^B2$") == 1 ]'