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
10test_expect_success 'setup' '
11 # a non-trivial custom pattern
12 git config diff.custom1.funcname "!static
13!String
14[^ ].*s.*" &&
15
16 # a custom pattern which matches to end of line
17 git config diff.custom2.funcname "......Beer\$" &&
18
19 # alternation in pattern
20 git config diff.custom3.funcname "Beer$" &&
21 git config diff.custom3.xfuncname "^[ ]*((public|static).*)$" &&
22
23 # for regexp compilation tests
24 echo A >A.java &&
25 echo B >B.java
26'
27
28diffpatterns="
29 ada
30 bibtex
31 cpp
32 csharp
33 fortran
34 html
35 java
36 matlab
37 objc
38 pascal
39 perl
40 php
41 python
42 ruby
43 tex
44 custom1
45 custom2
46 custom3
47"
48
49for p in $diffpatterns
50do
51 test_expect_success "builtin $p pattern compiles" '
52 echo "*.java diff=$p" >.gitattributes &&
53 test_expect_code 1 git diff --no-index \
54 A.java B.java 2>msg &&
55 test_i18ngrep ! fatal msg &&
56 test_i18ngrep ! error msg
57 '
58 test_expect_success "builtin $p wordRegex pattern compiles" '
59 echo "*.java diff=$p" >.gitattributes &&
60 test_expect_code 1 git diff --no-index --word-diff \
61 A.java B.java 2>msg &&
62 test_i18ngrep ! fatal msg &&
63 test_i18ngrep ! error msg
64 '
65done
66
67test_expect_success 'last regexp must not be negated' '
68 echo "*.java diff=java" >.gitattributes &&
69 test_config diff.java.funcname "!static" &&
70 test_expect_code 128 git diff --no-index A.java B.java 2>msg &&
71 test_i18ngrep ": Last expression must not be negated:" msg
72'
73
74test_expect_success 'setup hunk header tests' '
75 for i in $diffpatterns
76 do
77 echo "$i-* diff=$i"
78 done > .gitattributes &&
79
80 # add all test files to the index
81 (
82 cd "$TEST_DIRECTORY"/t4018 &&
83 git --git-dir="$TRASH_DIRECTORY/.git" add .
84 ) &&
85
86 # place modified files in the worktree
87 for i in $(git ls-files)
88 do
89 sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
90 done
91'
92
93# check each individual file
94for i in $(git ls-files)
95do
96 if grep broken "$i" >/dev/null 2>&1
97 then
98 result=failure
99 else
100 result=success
101 fi
102 test_expect_$result "hunk header: $i" "
103 test_when_finished 'cat actual' && # for debugging only
104 git diff -U1 $i >actual &&
105 grep '@@ .* @@.*RIGHT' actual
106 "
107done
108
109test_done