Skip to content

Commit f792a0b

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b5e459 commit f792a0b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

t/t4018-diff-funcname.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ EOF
3232

3333
sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
3434

35+
test_config () {
36+
git config "$1" "$2" &&
37+
test_when_finished "git config --unset $1"
38+
}
39+
3540
builtin_patterns="bibtex cpp csharp fortran html java objc pascal perl php python ruby tex"
3641
for p in $builtin_patterns
3742
do
@@ -63,29 +68,29 @@ test_expect_success 'preset java pattern' '
6368
grep "^@@.*@@ public static void main("
6469
'
6570

66-
git config diff.java.funcname '!static
67-
!String
68-
[^ ].*s.*'
69-
7071
test_expect_success 'custom pattern' '
72+
test_config diff.java.funcname "!static
73+
!String
74+
[^ ].*s.*" &&
7175
git diff --no-index Beer.java Beer-correct.java |
7276
grep "^@@.*@@ int special;$"
7377
'
7478

7579
test_expect_success 'last regexp must not be negated' '
76-
git config diff.java.funcname "!static" &&
80+
test_config diff.java.funcname "!static" &&
7781
git diff --no-index Beer.java Beer-correct.java 2>&1 |
7882
grep "fatal: Last expression must not be negated:"
7983
'
8084

8185
test_expect_success 'pattern which matches to end of line' '
82-
git config diff.java.funcname "Beer$" &&
86+
test_config diff.java.funcname "Beer$" &&
8387
git diff --no-index Beer.java Beer-correct.java |
8488
grep "^@@.*@@ Beer"
8589
'
8690

8791
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).*)$" &&
8994
git diff --no-index Beer.java Beer-correct.java |
9095
grep "^@@.*@@ public static void main("
9196
'

0 commit comments

Comments
 (0)