t4018 (funcname patterns): make configuration easier to track

Introduce a "test_config" function to set a configuration variable for use by a single test (automatically unsetting it when the assertion finishes). If this function is used consistently, the configuration used in a test_expect_success block can be read at the beginning of that block instead of requiring reading all the tests that come before. So it becomes a little easier to add new tests or rearrange existing ones without fear of breaking configuration. In particular, the test of alternation in xfuncname patterns also checks that xfuncname takes precedence over funcname variable as a sort of side-effect, since the latter leaks in from previous tests. In the new syntax, the test has to say explicitly what variables it is using, making the test clearer and a future regression in coverage from carelessly editing the script less likely. 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:22 UTC f792a0b88ec24dd20c29282b4e022c7b48abd59b
1 file changed +12 -7
t/t4018-diff-funcname.sh
+12 -7
@@ -32,6 +32,11 @@ EOF
32
33 sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
34
35 +test_config () {
36 + git config "$1" "$2" &&
37 + test_when_finished "git config --unset $1"
38 +}
39 +
40 builtin_patterns="bibtex cpp csharp fortran html java objc pascal perl php python ruby tex"
41 for p in $builtin_patterns
42 do
@@ -63,29 +68,29 @@ test_expect_success 'preset java pattern' '
68 grep "^@@.*@@ public static void main("
69 '
70
66 -git config diff.java.funcname '!static
67 -!String
68 -[^ ].*s.*'
69 -
71 test_expect_success 'custom pattern' '
72 + test_config diff.java.funcname "!static
73 +!String
74 +[^ ].*s.*" &&
75 git diff --no-index Beer.java Beer-correct.java |
76 grep "^@@.*@@ int special;$"
77 '
78
79 test_expect_success 'last regexp must not be negated' '
76 - git config diff.java.funcname "!static" &&
80 + 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:"
83 '
84
85 test_expect_success 'pattern which matches to end of line' '
82 - git config diff.java.funcname "Beer$" &&
86 + test_config diff.java.funcname "Beer$" &&
87 git diff --no-index Beer.java Beer-correct.java |
88 grep "^@@.*@@ Beer"
89 '
90
91 test_expect_success 'alternation in pattern' '
88 - git config diff.java.xfuncname "^[ ]*((public|static).*)$" &&
92 + test_config diff.java.funcname "Beer$" &&
93 + test_config diff.java.xfuncname "^[ ]*((public|static).*)$" &&
94 git diff --no-index Beer.java Beer-correct.java |
95 grep "^@@.*@@ public static void main("
96 '