Skip to content

Commit d64d6cd

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

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

t/t4018-diff-funcname.sh

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ test_description='Test custom diff function name patterns'
99

1010
LF='
1111
'
12-
13-
cat > Beer.java << EOF
12+
cat >Beer.java <<\EOF
1413
public class Beer
1514
{
1615
int special;
@@ -29,70 +28,72 @@ public class Beer
2928
}
3029
}
3130
EOF
32-
33-
sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
31+
sed 's/beer\\/beer,\\/' <Beer.java >Beer-correct.java
3432

3533
test_config () {
3634
git config "$1" "$2" &&
3735
test_when_finished "git config --unset $1"
3836
}
3937

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
4245
do
4346
test_expect_success "builtin $p pattern compiles" '
4447
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
4752
'
4853
test_expect_success "builtin $p wordRegex pattern compiles" '
4954
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
5359
'
5460
done
5561

5662
test_expect_success 'default behaviour' '
5763
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\$"
6065
'
6166

6267
test_expect_success 'set up .gitattributes declaring drivers to test' '
6368
echo "*.java diff=java" >.gitattributes
6469
'
6570

6671
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("
6973
'
7074

7175
test_expect_success 'custom pattern' '
7276
test_config diff.java.funcname "!static
7377
!String
7478
[^ ].*s.*" &&
75-
git diff --no-index Beer.java Beer-correct.java |
76-
grep "^@@.*@@ int special;$"
79+
test_expect_funcname "int special;\$"
7780
'
7881

7982
test_expect_success 'last regexp must not be negated' '
8083
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
8386
'
8487

8588
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\$"
8991
'
9092

9193
test_expect_success 'alternation in pattern' '
9294
test_config diff.java.funcname "Beer$" &&
9395
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("
9697
'
9798

9899
test_done

0 commit comments

Comments
 (0)