t4018: convert custom pattern test to the new infrastructure
[git/debian.git] / t / t4018-diff-funcname.sh
blob5ac744f3973ea6c73326ce4d260530f46c552665
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='Test custom diff function name patterns'
8 . ./test-lib.sh
10 LF='
12 cat >Beer.java <<\EOF
13 public class Beer
15 int special;
16 public static void main(String args[])
18 String s=" ";
19 for(int x = 99; x > 0; x--)
21 System.out.print(x + " bottles of beer on the wall "
22 + x + " bottles of beer\n"
23 + "Take one down, pass it around, " + (x - 1)
24 + " bottles of beer on the wall.\n");
26 System.out.print("Go to the store, buy some more,\n"
27 + "99 bottles of beer on the wall.\n");
30 EOF
31 sed 's/beer\\/beer,\\/' <Beer.java >Beer-correct.java
33 test_expect_success 'setup' '
34 # a non-trivial custom pattern
35 git config diff.custom1.funcname "!static
36 !String
37 [^ ].*s.*" &&
39 # a custom pattern which matches to end of line
40 git config diff.custom2.funcname "......Beer\$" &&
42 # alternation in pattern
43 git config diff.custom3.funcname "Beer$" &&
44 git config diff.custom3.xfuncname "^[ ]*((public|static).*)$"
47 diffpatterns="
48 ada
49 bibtex
50 cpp
51 csharp
52 fortran
53 html
54 java
55 matlab
56 objc
57 pascal
58 perl
59 php
60 python
61 ruby
62 tex
63 custom1
64 custom2
65 custom3
68 for p in $diffpatterns
70 test_expect_success "builtin $p pattern compiles" '
71 echo "*.java diff=$p" >.gitattributes &&
72 test_expect_code 1 git diff --no-index \
73 Beer.java Beer-correct.java 2>msg &&
74 ! grep fatal msg &&
75 ! grep error msg
77 test_expect_success "builtin $p wordRegex pattern compiles" '
78 echo "*.java diff=$p" >.gitattributes &&
79 test_expect_code 1 git diff --no-index --word-diff \
80 Beer.java Beer-correct.java 2>msg &&
81 ! grep fatal msg &&
82 ! grep error msg
84 done
86 test_expect_success 'set up .gitattributes declaring drivers to test' '
87 cat >.gitattributes <<-\EOF
88 *.java diff=java
89 EOF
92 test_expect_success 'last regexp must not be negated' '
93 test_config diff.java.funcname "!static" &&
94 test_expect_code 128 git diff --no-index Beer.java Beer-correct.java 2>msg &&
95 grep ": Last expression must not be negated:" msg
98 test_expect_success 'setup hunk header tests' '
99 for i in $diffpatterns
101 echo "$i-* diff=$i"
102 done > .gitattributes &&
104 # add all test files to the index
106 cd "$TEST_DIRECTORY"/t4018 &&
107 git --git-dir="$TRASH_DIRECTORY/.git" add .
108 ) &&
110 # place modified files in the worktree
111 for i in $(git ls-files)
113 sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
114 done
117 # check each individual file
118 for i in $(git ls-files)
120 if grep broken "$i" >/dev/null 2>&1
121 then
122 result=failure
123 else
124 result=success
126 test_expect_$result "hunk header: $i" "
127 test_when_finished 'cat actual' && # for debugging only
128 git diff -U1 $i >actual &&
129 grep '@@ .* @@.*RIGHT' actual
131 done
133 test_done