git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] annotate/blame tests updates.

From
Junio C Hamano <junkio@cox.net>
Date
Mar 6, 2006, 06:12 UTC
Message-ID
<7vu0acaypd.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<440BA4DA.9060101@michonline.com>
Ryan Anderson <ryan@michonline.com> writes:
Show 6 quoted lines
>>+test_expect_success \
>>+    'check all lines blamed on A' \
>>+    '[ $(git annotate file | awk "{print \$3}" | grep -c "A") == 2 ]'
>>  
>>
> This should be $PROG as well, I suspect.

True. Also I am suspecting this awk being a but unsafe. The default author is "A U Thor <author@example.com>", and without FS specified awk would split at whitespaces.

I haven't pushed out the test-case sharing by Fredrik yet, but I have already taken it. This patch is on top of it.

-- >8 -- 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>
---
 t/annotate-tests.sh |   81 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 44 insertions(+), 37 deletions(-)
92a903acfd0904e6dd6d18112428429938783d19
diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh
index 54a4dfb..d25a7a1 100644
--- a/t/annotate-tests.sh
+++ b/t/annotate-tests.sh
@@ -1,6 +1,37 @@
 # This file isn't used as a test script directly, instead it is
 # sourced from t8001-annotate.sh and t8001-blame.sh.
 
+check_count () {
+	head=
+	case "$1" in -h) head="$2"; shift; shift ;; esac
+	$PROG file $head | perl -e '
+		my %expect = (@ARGV);
+		my %count = ();
+		while (<STDIN>) {
+			if (/^[0-9a-f]+\t\(([^\t]+)\t/) {
+				my $author = $1;
+				for ($author) { s/^\s*//; s/\s*$//; }
+				if (exists $expect{$author}) {
+					$count{$author}++;
+				}
+			}
+		}
+		my $bad = 0;
+		while (my ($author, $count) = each %count) {
+			my $ok;
+			if ($expect{$author} != $count) {
+				$bad = 1;
+				$ok = "bad";
+			}
+			else {
+				$ok = "good";
+			}
+			print STDERR "Author $author (expected $expect{$author}, attributed $count) $ok\n";
+		}
+		exit($bad);
+	' "$@"
+}
+
 test_expect_success \
     'prepare reference tree' \
     'echo "1A quick brown fox jumps over the" >file &&
@@ -10,7 +41,7 @@ test_expect_success \
 
 test_expect_success \
     'check all lines blamed on A' \
-    '[ $(git annotate file | awk "{print \$3}" | grep -c "A") == 2 ]'
+    'check_count A 2'
 
 test_expect_success \
     'Setup new lines blamed on B' \
@@ -19,12 +50,8 @@ test_expect_success \
      GIT_AUTHOR_NAME="B" git commit -a -m "Second."'
 
 test_expect_success \
-    'Two lines blamed on A' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "A") == 2 ]'
-
-test_expect_success \
-    'Two lines blamed on B' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "B") == 2 ]'
+    'Two lines blamed on A, two on B' \
+    'check_count A 2 B 2'
 
 test_expect_success \
     'merge-setup part 1' \
@@ -34,16 +61,8 @@ test_expect_success \
      GIT_AUTHOR_NAME="B1" git commit -a -m "Branch1-1"'
 
 test_expect_success \
-    'Two lines blamed on A' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "^A$") == 2 ]'
-
-test_expect_success \
-    'Two lines blamed on B' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "^B$") == 2 ]'
-
-test_expect_success \
-    'Two lines blamed on B1' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "^B1$") == 2 ]'
+    'Two lines blamed on A, two on B, two on B1' \
+    'check_count A 2 B 2 B1 2'
 
 test_expect_success \
     'merge-setup part 2' \
@@ -53,34 +72,22 @@ test_expect_success \
      GIT_AUTHOR_NAME="B2" git commit -a -m "Branch2-1"'
 
 test_expect_success \
-    'Two lines blamed on A' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "^A$") == 2 ]'
-
-test_expect_success \
-    'One line blamed on B' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "^B$") == 1 ]'
-
-test_expect_success \
-    'One line blamed on B2' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "^B2$") == 1 ]'
-
+    'Two lines blamed on A, one on B, one on B2' \
+    'check_count A 2 B 1 B2 1'
 
 test_expect_success \
     'merge-setup part 3' \
     'git pull . branch1'
 
 test_expect_success \
-    'Two lines blamed on A' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "^A$") == 2 ]'
+    'Two lines blamed on A, one on B, two on B1, one on B2' \
+    'check_count A 2 B 1 B1 2 B2 1'
 
 test_expect_success \
-    'One line blamed on B' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "^B$") == 1 ]'
+    'Annotating an old revision works' \
+    'check_count -h master A 2 B 2'
 
 test_expect_success \
-    'Two lines blamed on B1' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "^B1$") == 2 ]'
+    'Annotating an old revision works' \
+    'check_count -h master^ A 2'
 
-test_expect_success \
-    'One line blamed on B2' \
-    '[ $($PROG file | awk "{print \$3}" | grep -c "^B2$") == 1 ]'
-- 
1.2.4.g4668
Previous: Ryan Anderson
Message 19 of 19 in “git-blame: Use the same tests for git-blame as for git-annotate”
  1. git-blame: Use the same tests for git-blame as for git-annotateFredrik Kuivinen, Mar 5, 2006
  2. Ryan AndersonMar 5, 2006
  3. Junio C HamanoMar 6, 2006
  4. Martin LanghoffMar 6, 2006
  5. annotate: Support annotation of files on other revisions.Ryan Anderson, Mar 6, 2006
  6. Martin LanghoffMar 6, 2006
  7. Fredrik KuivinenMar 6, 2006
  8. A Large Angry SCMMar 6, 2006
  9. Ryan AndersonMar 6, 2006
  10. Shawn PearceMar 6, 2006
  11. Junio C HamanoMar 6, 2006
  12. Shawn PearceMar 6, 2006
  13. A Large Angry SCMMar 6, 2006
  14. Junio C HamanoMar 6, 2006
  15. Johannes SchindelinMar 6, 2006
  16. Johannes SchindelinMar 6, 2006
  17. Ryan AndersonMar 6, 2006
  18. Ryan AndersonMar 6, 2006
  19. annotate/blame tests updates.Junio C Hamano, Mar 6, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.