t4018 (funcname patterns): minor cleanups

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed May 21, 2011 at 14:25 UTC d64d6cdc2071d1eb7f6a45118edc42627e6fc692
1 file changed +25 -24
t/t4018-diff-funcname.sh
+25 -24
@@ -9,8 +9,7 @@ test_description='Test custom diff function name patterns'
9
10 LF='
11 '
12 -
13 -cat > Beer.java << EOF
12 +cat >Beer.java <<\EOF
13 public class Beer
14 {
15 int special;
@@ -29,34 +28,40 @@ public class Beer
28 }
29 }
30 EOF
32 -
33 -sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
31 +sed 's/beer\\/beer,\\/' <Beer.java >Beer-correct.java
32
33 test_config () {
34 git config "$1" "$2" &&
35 test_when_finished "git config --unset $1"
36 }
37
40 -builtin_patterns="bibtex cpp csharp fortran html java objc pascal perl php python ruby tex"
41 -for p in $builtin_patterns
38 +test_expect_funcname () {
39 + test_expect_code 1 git diff --no-index \
40 + Beer.java Beer-correct.java >diff &&
41 + grep "^@@.*@@ $1" diff
42 +}
43 +
44 +for p in bibtex cpp csharp fortran html java objc pascal perl php python ruby tex
45 do
46 test_expect_success "builtin $p pattern compiles" '
47 echo "*.java diff=$p" >.gitattributes &&
45 - ! { git diff --no-index Beer.java Beer-correct.java 2>&1 |
46 - grep "fatal" > /dev/null; }
48 + test_expect_code 1 git diff --no-index \
49 + Beer.java Beer-correct.java 2>msg &&
50 + ! grep fatal msg &&
51 + ! grep error msg
52 '
53 test_expect_success "builtin $p wordRegex pattern compiles" '
54 echo "*.java diff=$p" >.gitattributes &&
50 - ! { git diff --no-index --word-diff \
51 - Beer.java Beer-correct.java 2>&1 |
52 - grep "fatal" > /dev/null; }
55 + test_expect_code 1 git diff --no-index --word-diff \
56 + Beer.java Beer-correct.java 2>msg &&
57 + ! grep fatal msg &&
58 + ! grep error msg
59 '
60 done
61
62 test_expect_success 'default behaviour' '
63 rm -f .gitattributes &&
58 - git diff --no-index Beer.java Beer-correct.java |
59 - grep "^@@.*@@ public class Beer"
64 + test_expect_funcname "public class Beer\$"
65 '
66
67 test_expect_success 'set up .gitattributes declaring drivers to test' '
@@ -64,35 +69,31 @@ test_expect_success 'set up .gitattributes declaring drivers to test' '
69 '
70
71 test_expect_success 'preset java pattern' '
67 - git diff --no-index Beer.java Beer-correct.java |
68 - grep "^@@.*@@ public static void main("
72 + test_expect_funcname "public static void main("
73 '
74
75 test_expect_success 'custom pattern' '
76 test_config diff.java.funcname "!static
77 !String
78 [^ ].*s.*" &&
75 - git diff --no-index Beer.java Beer-correct.java |
76 - grep "^@@.*@@ int special;$"
79 + test_expect_funcname "int special;\$"
80 '
81
82 test_expect_success 'last regexp must not be negated' '
83 test_config diff.java.funcname "!static" &&
81 - git diff --no-index Beer.java Beer-correct.java 2>&1 |
82 - grep "fatal: Last expression must not be negated:"
84 + test_expect_code 128 git diff --no-index Beer.java Beer-correct.java 2>msg &&
85 + grep ": Last expression must not be negated:" msg
86 '
87
88 test_expect_success 'pattern which matches to end of line' '
86 - test_config diff.java.funcname "Beer$" &&
87 - git diff --no-index Beer.java Beer-correct.java |
88 - grep "^@@.*@@ Beer"
89 + test_config diff.java.funcname "Beer\$" &&
90 + test_expect_funcname "Beer\$"
91 '
92
93 test_expect_success 'alternation in pattern' '
94 test_config diff.java.funcname "Beer$" &&
95 test_config diff.java.xfuncname "^[ ]*((public|static).*)$" &&
94 - git diff --no-index Beer.java Beer-correct.java |
95 - grep "^@@.*@@ public static void main("
96 + test_expect_funcname "public static void main("
97 '
98
99 test_done