]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4018-diff-funcname.sh
Git 2.31.5
[thirdparty/git.git] / t / t4018-diff-funcname.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes E. Schindelin
4 #
5
6 test_description='Test custom diff function name patterns'
7
8 . ./test-lib.sh
9
10 test_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
28 diffpatterns="
29 ada
30 bash
31 bibtex
32 cpp
33 csharp
34 css
35 dts
36 elixir
37 fortran
38 fountain
39 golang
40 html
41 java
42 markdown
43 matlab
44 objc
45 pascal
46 perl
47 php
48 python
49 ruby
50 rust
51 tex
52 custom1
53 custom2
54 custom3
55 "
56
57 for p in $diffpatterns
58 do
59 test_expect_success "builtin $p pattern compiles" '
60 echo "*.java diff=$p" >.gitattributes &&
61 test_expect_code 1 git diff --no-index \
62 A.java B.java 2>msg &&
63 test_i18ngrep ! fatal msg &&
64 test_i18ngrep ! error msg
65 '
66 test_expect_success "builtin $p wordRegex pattern compiles" '
67 echo "*.java diff=$p" >.gitattributes &&
68 test_expect_code 1 git diff --no-index --word-diff \
69 A.java B.java 2>msg &&
70 test_i18ngrep ! fatal msg &&
71 test_i18ngrep ! error msg
72 '
73 done
74
75 test_expect_success 'last regexp must not be negated' '
76 echo "*.java diff=java" >.gitattributes &&
77 test_config diff.java.funcname "!static" &&
78 test_expect_code 128 git diff --no-index A.java B.java 2>msg &&
79 test_i18ngrep ": Last expression must not be negated:" msg
80 '
81
82 test_expect_success 'setup hunk header tests' '
83 for i in $diffpatterns
84 do
85 echo "$i-* diff=$i"
86 done > .gitattributes &&
87
88 # add all test files to the index
89 (
90 cd "$TEST_DIRECTORY"/t4018 &&
91 git --git-dir="$TRASH_DIRECTORY/.git" add .
92 ) &&
93
94 # place modified files in the worktree
95 for i in $(git ls-files)
96 do
97 sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
98 done
99 '
100
101 # check each individual file
102 for i in $(git ls-files)
103 do
104 if grep broken "$i" >/dev/null 2>&1
105 then
106 result=failure
107 else
108 result=success
109 fi
110 test_expect_$result "hunk header: $i" "
111 git diff -U1 $i >actual &&
112 grep '@@ .* @@.*RIGHT' actual
113 "
114 done
115
116 test_done