5ac744f3973ea6c73326ce4d260530f46c552665
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='Test custom diff function name patterns'
7
8. ./test-lib.sh
9
10LF='
11'
12cat >Beer.java <<\EOF
13public class Beer
14{
15 int special;
16 public static void main(String args[])
17 {
18 String s=" ";
19 for(int x = 99; x > 0; x--)
20 {
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");
25 }
26 System.out.print("Go to the store, buy some more,\n"
27 + "99 bottles of beer on the wall.\n");
28 }
29}
30EOF
31sed 's/beer\\/beer,\\/' <Beer.java >Beer-correct.java
32
33test_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'
46
47diffpatterns="
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
66"
67
68for p in $diffpatterns
69do
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
76 '
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
83 '
84done
85
86test_expect_success 'set up .gitattributes declaring drivers to test' '
87 cat >.gitattributes <<-\EOF
88 *.java diff=java
89 EOF
90'
91
92test_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
96'
97
98test_expect_success 'setup hunk header tests' '
99 for i in $diffpatterns
100 do
101 echo "$i-* diff=$i"
102 done > .gitattributes &&
103
104 # add all test files to the index
105 (
106 cd "$TEST_DIRECTORY"/t4018 &&
107 git --git-dir="$TRASH_DIRECTORY/.git" add .
108 ) &&
109
110 # place modified files in the worktree
111 for i in $(git ls-files)
112 do
113 sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
114 done
115'
116
117# check each individual file
118for i in $(git ls-files)
119do
120 if grep broken "$i" >/dev/null 2>&1
121 then
122 result=failure
123 else
124 result=success
125 fi
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
130 "
131done
132
133test_done