Skip to content

Commit f1b75fb

Browse files
j6tgitster
authored andcommitted
t4018: convert custom pattern test to the new infrastructure
For the test case "matches to end of line", extend the pattern by a few wildcards so that the pattern captures the "RIGHT" token, which is needed for verification, without mentioning it in the pattern. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent dd4dc5c commit f1b75fb

File tree

4 files changed

+58
-24
lines changed

4 files changed

+58
-24
lines changed

t/t4018-diff-funcname.sh

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@ public class Beer
3030
EOF
3131
sed 's/beer\\/beer,\\/' <Beer.java >Beer-correct.java
3232

33-
test_expect_funcname () {
34-
lang=${2-java}
35-
test_expect_code 1 git diff --no-index -U1 \
36-
"Beer.$lang" "Beer-correct.$lang" >diff &&
37-
grep "^@@.*@@ $1" diff
38-
}
33+
test_expect_success 'setup' '
34+
# a non-trivial custom pattern
35+
git config diff.custom1.funcname "!static
36+
!String
37+
[^ ].*s.*" &&
38+
39+
# a custom pattern which matches to end of line
40+
git config diff.custom2.funcname "......Beer\$" &&
41+
42+
# alternation in pattern
43+
git config diff.custom3.funcname "Beer$" &&
44+
git config diff.custom3.xfuncname "^[ ]*((public|static).*)$"
45+
'
3946

4047
diffpatterns="
4148
ada
@@ -53,6 +60,9 @@ diffpatterns="
5360
python
5461
ruby
5562
tex
63+
custom1
64+
custom2
65+
custom3
5666
"
5767

5868
for p in $diffpatterns
@@ -79,30 +89,12 @@ test_expect_success 'set up .gitattributes declaring drivers to test' '
7989
EOF
8090
'
8191

82-
test_expect_success 'custom pattern' '
83-
test_config diff.java.funcname "!static
84-
!String
85-
[^ ].*s.*" &&
86-
test_expect_funcname "int special;\$"
87-
'
88-
8992
test_expect_success 'last regexp must not be negated' '
9093
test_config diff.java.funcname "!static" &&
9194
test_expect_code 128 git diff --no-index Beer.java Beer-correct.java 2>msg &&
9295
grep ": Last expression must not be negated:" msg
9396
'
9497

95-
test_expect_success 'pattern which matches to end of line' '
96-
test_config diff.java.funcname "Beer\$" &&
97-
test_expect_funcname "Beer\$"
98-
'
99-
100-
test_expect_success 'alternation in pattern' '
101-
test_config diff.java.funcname "Beer$" &&
102-
test_config diff.java.xfuncname "^[ ]*((public|static).*)$" &&
103-
test_expect_funcname "public static void main("
104-
'
105-
10698
test_expect_success 'setup hunk header tests' '
10799
for i in $diffpatterns
108100
do

t/t4018/custom1-pattern

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Beer
2+
{
3+
int special, RIGHT;
4+
public static void main(String args[])
5+
{
6+
String s=" ";
7+
for(int x = 99; x > 0; x--)
8+
{
9+
System.out.print(x + " bottles of beer on the wall "
10+
+ x + " bottles of beer\n" // ChangeMe
11+
+ "Take one down, pass it around, " + (x - 1)
12+
+ " bottles of beer on the wall.\n");
13+
}
14+
System.out.print("Go to the store, buy some more,\n"
15+
+ "99 bottles of beer on the wall.\n");
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class RIGHT_Beer
2+
{
3+
int special;
4+
public static void main(String args[])
5+
{
6+
System.out.print("ChangeMe");
7+
}
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Beer
2+
{
3+
int special;
4+
public static void main(String RIGHT[])
5+
{
6+
String s=" ";
7+
for(int x = 99; x > 0; x--)
8+
{
9+
System.out.print(x + " bottles of beer on the wall "
10+
+ x + " bottles of beer\n" // ChangeMe
11+
+ "Take one down, pass it around, " + (x - 1)
12+
+ " bottles of beer on the wall.\n");
13+
}
14+
System.out.print("Go to the store, buy some more,\n"
15+
+ "99 bottles of beer on the wall.\n");
16+
}
17+
}

0 commit comments

Comments
 (0)