]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4018-diff-funcname.sh
userdiff tests: explicitly test "default" pattern
[thirdparty/git.git] / t / t4018-diff-funcname.sh
CommitLineData
f258475a
JH
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
f1b75fba
JS
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$" &&
ad5070fb
JS
21 git config diff.custom3.xfuncname "^[ ]*((public|static).*)$" &&
22
23 # for regexp compilation tests
24 echo A >A.java &&
25 echo B >B.java
f1b75fba 26'
d64d6cdc 27
bfa7d014
JS
28diffpatterns="
29 ada
2ff6c346 30 bash
bfa7d014
JS
31 bibtex
32 cpp
33 csharp
0719f3ee 34 css
3c81760b 35 dts
a807200f 36 elixir
bfa7d014 37 fortran
69f9c87d 38 fountain
1dbf0c0a 39 golang
bfa7d014
JS
40 html
41 java
09dad925 42 markdown
bfa7d014
JS
43 matlab
44 objc
45 pascal
46 perl
47 php
48 python
49 ruby
d74e7860 50 rust
bfa7d014 51 tex
132bf259 52 default
f1b75fba
JS
53 custom1
54 custom2
55 custom3
bfa7d014
JS
56"
57
58for p in $diffpatterns
e3bf5e43
BC
59do
60 test_expect_success "builtin $p pattern compiles" '
5b5e4594 61 echo "*.java diff=$p" >.gitattributes &&
d64d6cdc 62 test_expect_code 1 git diff --no-index \
ad5070fb 63 A.java B.java 2>msg &&
41ca19b6
JS
64 test_i18ngrep ! fatal msg &&
65 test_i18ngrep ! error msg
e3bf5e43 66 '
bff42061 67 test_expect_success "builtin $p wordRegex pattern compiles" '
5b5e4594 68 echo "*.java diff=$p" >.gitattributes &&
d64d6cdc 69 test_expect_code 1 git diff --no-index --word-diff \
ad5070fb 70 A.java B.java 2>msg &&
41ca19b6
JS
71 test_i18ngrep ! fatal msg &&
72 test_i18ngrep ! error msg
bff42061 73 '
e3bf5e43
BC
74done
75
f258475a 76test_expect_success 'last regexp must not be negated' '
ad5070fb 77 echo "*.java diff=java" >.gitattributes &&
f792a0b8 78 test_config diff.java.funcname "!static" &&
ad5070fb
JS
79 test_expect_code 128 git diff --no-index A.java B.java 2>msg &&
80 test_i18ngrep ": Last expression must not be negated:" msg
f258475a
JH
81'
82
bfa7d014
JS
83test_expect_success 'setup hunk header tests' '
84 for i in $diffpatterns
85 do
86 echo "$i-* diff=$i"
87 done > .gitattributes &&
88
89 # add all test files to the index
90 (
91 cd "$TEST_DIRECTORY"/t4018 &&
92 git --git-dir="$TRASH_DIRECTORY/.git" add .
93 ) &&
94
95 # place modified files in the worktree
96 for i in $(git ls-files)
97 do
98 sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
99 done
100'
101
102# check each individual file
103for i in $(git ls-files)
104do
105 if grep broken "$i" >/dev/null 2>&1
106 then
107 result=failure
108 else
109 result=success
110 fi
111 test_expect_$result "hunk header: $i" "
bfa7d014
JS
112 git diff -U1 $i >actual &&
113 grep '@@ .* @@.*RIGHT' actual
114 "
115done
116
f258475a 117test_done