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

[PATCH 3/7] t4018 (funcname patterns): minor cleanups

From
Jonathan Nieder <jrnieder@gmail.com>
Date
May 21, 2011, 19:25 UTC
Message-ID
<20110521192514.GD10530@elie>
In-Reply-To
<20110521185314.GA10530@elie>

Introduce a test_expect_funcname function to make a diff and apply a regexp anchored on the left to the function name it writes, avoiding some repetition.

Omit the space after >, <<, and < operators for consistency with other scripts. Quote the <<here document delimiter and $ signs in quotes so readers don't have to worry about the effect of shell metacharacters.

Remove some unnecessary blank lines.

Run "git diff" as a separate command instead of as upstream of a pipe that checks its output, so the exit status can be tested. In particular, this way if "git diff" starts segfaulting the test harness will notice.

Allow "error:" as a synonym for "fatal:" when checking error messages, since whether a command uses die() or "return error()" is a small implementation detail.

Anchor some more regexes on the right.

None of the above is very important on its own; the point is just to make the script a little easier to read and the code less scary to modify.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 t/t4018-diff-funcname.sh |   49 +++++++++++++++++++++++----------------------
 1 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index ce0a0e3..ad74c60 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -9,8 +9,7 @@ test_description='Test custom diff function name patterns'
 
 LF='
 '
-
-cat > Beer.java << EOF
+cat >Beer.java <<\EOF
 public class Beer
 {
 	int special;
@@ -29,34 +28,40 @@ public class Beer
 	}
 }
 EOF
-
-sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
+sed 's/beer\\/beer,\\/' <Beer.java >Beer-correct.java
 
 test_config () {
 	git config "$1" "$2" &&
 	test_when_finished "git config --unset $1"
 }
 
-builtin_patterns="bibtex cpp csharp fortran html java objc pascal perl php python ruby tex"
-for p in $builtin_patterns
+test_expect_funcname () {
+	test_expect_code 1 git diff --no-index \
+		Beer.java Beer-correct.java >diff &&
+	grep "^@@.*@@ $1" diff
+}
+
+for p in bibtex cpp csharp fortran html java objc pascal perl php python ruby tex
 do
 	test_expect_success "builtin $p pattern compiles" '
 		echo "*.java diff=$p" >.gitattributes &&
-		! { git diff --no-index Beer.java Beer-correct.java 2>&1 |
-			grep "fatal" > /dev/null; }
+		test_expect_code 1 git diff --no-index \
+			Beer.java Beer-correct.java 2>msg &&
+		! grep fatal msg &&
+		! grep error msg
 	'
 	test_expect_success "builtin $p wordRegex pattern compiles" '
 		echo "*.java diff=$p" >.gitattributes &&
-		! { git diff --no-index --word-diff \
-			Beer.java Beer-correct.java 2>&1 |
-			grep "fatal" > /dev/null; }
+		test_expect_code 1 git diff --no-index --word-diff \
+			Beer.java Beer-correct.java 2>msg &&
+		! grep fatal msg &&
+		! grep error msg
 	'
 done
 
 test_expect_success 'default behaviour' '
 	rm -f .gitattributes &&
-	git diff --no-index Beer.java Beer-correct.java |
-	grep "^@@.*@@ public class Beer"
+	test_expect_funcname "public class Beer\$"
 '
 
 test_expect_success 'set up .gitattributes declaring drivers to test' '
@@ -64,35 +69,31 @@ test_expect_success 'set up .gitattributes declaring drivers to test' '
 '
 
 test_expect_success 'preset java pattern' '
-	git diff --no-index Beer.java Beer-correct.java |
-	grep "^@@.*@@ public static void main("
+	test_expect_funcname "public static void main("
 '
 
 test_expect_success 'custom pattern' '
 	test_config diff.java.funcname "!static
 !String
 [^ 	].*s.*" &&
-	git diff --no-index Beer.java Beer-correct.java |
-	grep "^@@.*@@ int special;$"
+	test_expect_funcname "int special;\$"
 '
 
 test_expect_success 'last regexp must not be negated' '
 	test_config diff.java.funcname "!static" &&
-	git diff --no-index Beer.java Beer-correct.java 2>&1 |
-	grep "fatal: Last expression must not be negated:"
+	test_expect_code 128 git diff --no-index Beer.java Beer-correct.java 2>msg &&
+	grep ": Last expression must not be negated:" msg
 '
 
 test_expect_success 'pattern which matches to end of line' '
-	test_config diff.java.funcname "Beer$" &&
-	git diff --no-index Beer.java Beer-correct.java |
-	grep "^@@.*@@ Beer"
+	test_config diff.java.funcname "Beer\$" &&
+	test_expect_funcname "Beer\$"
 '
 
 test_expect_success 'alternation in pattern' '
 	test_config diff.java.funcname "Beer$" &&
 	test_config diff.java.xfuncname "^[ 	]*((public|static).*)$" &&
-	git diff --no-index Beer.java Beer-correct.java |
-	grep "^@@.*@@ public static void main("
+	test_expect_funcname "public static void main("
 '
 
 test_done
-- 
1.7.5.1
Previous: Jonathan NiederNext: Jonathan Nieder
Message 7 of 13 in “Problems with Git's "perl" userdiff driver”
  1. Ævar Arnfjörð BjarmasonMay 15, 2011
  2. Junio C HamanoMay 15, 2011
  3. Ævar Arnfjörð BjarmasonMay 15, 2011
  4. 0/7 Re: Problems with Git's "perl" userdiff driverJonathan Nieder, May 21, 2011
  5. 1/7 t4018 (funcname patterns): make .gitattributes state easier to trackJonathan Nieder, May 21, 2011
  6. 2/7 t4018 (funcname patterns): make configuration easier to trackJonathan Nieder, May 21, 2011
  7. 3/7 t4018 (funcname patterns): minor cleanupsJonathan Nieder, May 21, 2011
  8. 4/7 userdiff/perl: anchor "sub" and "package" patterns on the leftJonathan Nieder, May 21, 2011
  9. 5/7 userdiff/perl: match full line of POD headersJonathan Nieder, May 21, 2011
  10. 6/7 userdiff/perl: catch sub with brace on second lineJonathan Nieder, May 21, 2011
  11. 8/7 userdiff/perl: tighten BEGIN/END block pattern to reject here-doc delimitersJonathan Nieder, May 22, 2011
  12. 7/7 tests: make test_expect_code quieter on successJonathan Nieder, May 21, 2011
  13. Ævar Arnfjörð BjarmasonMay 22, 2011

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.