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