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

[PATCH 3/6] t8001/t8002 (blame): add blame -L tests

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 17, 2013, 21:25 UTC
Message-ID
<1374096332-7891-4-git-send-email-sunshine@sunshineco.com>
In-Reply-To
<1374096332-7891-1-git-send-email-sunshine@sunshineco.com>

With the exception of a couple "corner case" checks in t8003 (and some indirect tests in t4211 of -L parsing code shared by log -L), there is no systematic checking of blame -L. Add tests to check blame -L directly.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 t/annotate-tests.sh | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 101 insertions(+), 3 deletions(-)
diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh
index 3aa6964..b6a7478 100644
--- a/t/annotate-tests.sh
+++ b/t/annotate-tests.sh
@@ -3,9 +3,17 @@
 
 check_count () {
 	head= &&
-	case "$1" in -h) head="$2"; shift; shift ;; esac &&
-	echo "$PROG file $head" >&4 &&
-	$PROG file $head >actual &&
+	options= &&
+	while :
+	do
+		case "$1" in
+		-h) head="$2"; shift; shift ;;
+		-*) options="$options $1"; shift ;;
+		*) break ;;
+		esac
+	done &&
+	echo "$PROG $options file $head" >&4 &&
+	$PROG $options file $head >actual &&
 	perl -e '
 		my %expect = (@ARGV);
 		my %count = map { $_ => 0 } keys %expect;
@@ -142,3 +150,93 @@ test_expect_success 'setup obfuscated email' '
 test_expect_success 'blame obfuscated email' '
 	check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
 '
+
+test_expect_success 'blame -L 1 (all)' '
+	check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
+'
+
+test_expect_success 'blame -L , (all)' '
+	check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
+'
+
+test_expect_success 'blame -L X (X to end)' '
+	check_count -L5 B1 1 C 1 D 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L X, (X to end)' '
+	check_count -L5, B1 1 C 1 D 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L ,Y (up to Y)' '
+	check_count -L,3 A 1 B2 1 E 1
+'
+
+test_expect_success 'blame -L X,X' '
+	check_count -L3,3 B2 1
+'
+
+test_expect_success 'blame -L X,Y' '
+	check_count -L3,6 B 1 B1 1 B2 1 D 1
+'
+
+test_expect_success 'blame -L Y,X (undocumented)' '
+	check_count -L6,3 B 1 B1 1 B2 1 D 1
+'
+
+test_expect_success 'blame -L X,+1' '
+	check_count -L3,+1 B2 1
+'
+
+test_expect_success 'blame -L X,+N' '
+	check_count -L3,+4 B 1 B1 1 B2 1 D 1
+'
+
+test_expect_success 'blame -L X,-1' '
+	check_count -L3,-1 B2 1
+'
+
+test_expect_success 'blame -L X,-N' '
+	check_count -L6,-4 B 1 B1 1 B2 1 D 1
+'
+
+test_expect_success 'blame -L /RE/ (RE to end)' '
+	check_count -L/evil/ C 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L /RE/,/RE2/' '
+	check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1
+'
+
+test_expect_success 'blame -L X,/RE/' '
+	check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L /RE/,Y' '
+	check_count -L/99/,7 B1 1 D 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L /RE/,+N' '
+	check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L /RE/,-N' '
+	check_count -L/99/,-3 B 1 B2 1 D 1
+'
+
+test_expect_success 'blame -L X (X > nlines)' '
+	test_must_fail $PROG -L12345 file
+'
+
+test_expect_success 'blame -L ,Y (Y > nlines)' '
+	test_must_fail $PROG -L,12345 file
+'
+
+test_expect_success 'blame -L bogus' '
+	test_must_fail $PROG -L file &&
+	test_must_fail $PROG -L1,+ file &&
+	test_must_fail $PROG -L1,- file &&
+	test_must_fail $PROG -LX file &&
+	test_must_fail $PROG -L1,X file &&
+	test_must_fail $PROG -L1,+N file &&
+	test_must_fail $PROG -L1,-N file
+'
-- 
1.8.3.3.1016.g4f0baba
Previous: Eric SunshineNext: Eric Sunshine
Message 4 of 12 in “fix blame -L regression; add tests”
  1. 0/6 fix blame -L regression; add testsEric Sunshine, Jul 17, 2013
  2. 1/6 line-range: fix "blame -L X,-N" regressionEric Sunshine, Jul 17, 2013
  3. 2/6 t8001/t8002 (blame): modernize styleEric Sunshine, Jul 17, 2013
  4. 3/6 t8001/t8002 (blame): add blame -L testsEric Sunshine, Jul 17, 2013
  5. 4/6 t8001/t8002 (blame): add blame -L :funcname testsEric Sunshine, Jul 17, 2013
  6. 5/6 blame-options.txt: place each -L option variation on its own lineEric Sunshine, Jul 17, 2013
  7. Thomas RastJul 18, 2013
  8. Junio C HamanoJul 18, 2013
  9. Thomas RastJul 22, 2013
  10. Junio C HamanoJul 22, 2013
  11. 6/6 blame-options.txt: explain that -L <start> and <end> are optionalEric Sunshine, Jul 17, 2013
  12. Thomas RastJul 18, 2013

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.