t5583: fix shebang line
[alt-git.git] / t / t4018-diff-funcname.sh
blob42a2b9a13b7a5bd6cf28cfbe9bbfb9a5a3e5f3e6
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='Test custom diff function name patterns'
8 . ./test-lib.sh
10 test_expect_success 'setup' '
11 # a non-trivial custom pattern
12 git config diff.custom1.funcname "!static
13 !String
14 [^ ].*s.*" &&
16 # a custom pattern which matches to end of line
17 git config diff.custom2.funcname "......Beer\$" &&
19 # alternation in pattern
20 git config diff.custom3.funcname "Beer$" &&
21 git config diff.custom3.xfuncname "^[ ]*((public|static).*)$" &&
23 # for regexp compilation tests
24 echo A >A.java &&
25 echo B >B.java
28 test_expect_success 'setup: test-tool userdiff' '
29 # Make sure additions to builtin_drivers are sorted
30 test_when_finished "rm builtin-drivers.sorted" &&
31 test-tool userdiff list-builtin-drivers >builtin-drivers &&
32 test_file_not_empty builtin-drivers &&
33 sort <builtin-drivers >builtin-drivers.sorted &&
34 test_cmp builtin-drivers.sorted builtin-drivers &&
36 # Ditto, but "custom" requires the .git directory and config
37 # to be setup and read.
38 test_when_finished "rm custom-drivers.sorted" &&
39 test-tool userdiff list-custom-drivers >custom-drivers &&
40 test_file_not_empty custom-drivers &&
41 sort <custom-drivers >custom-drivers.sorted &&
42 test_cmp custom-drivers.sorted custom-drivers
45 diffpatterns="
46 $(cat builtin-drivers)
47 $(cat custom-drivers)
50 for p in $diffpatterns
52 test_expect_success "builtin $p pattern compiles" '
53 echo "*.java diff=$p" >.gitattributes &&
54 test_expect_code 1 git diff --no-index \
55 A.java B.java 2>msg &&
56 test_i18ngrep ! fatal msg &&
57 test_i18ngrep ! error msg
59 test_expect_success "builtin $p wordRegex pattern compiles" '
60 echo "*.java diff=$p" >.gitattributes &&
61 test_expect_code 1 git diff --no-index --word-diff \
62 A.java B.java 2>msg &&
63 test_i18ngrep ! fatal msg &&
64 test_i18ngrep ! error msg
66 done
68 test_expect_success 'last regexp must not be negated' '
69 echo "*.java diff=java" >.gitattributes &&
70 test_config diff.java.funcname "!static" &&
71 test_expect_code 128 git diff --no-index A.java B.java 2>msg &&
72 test_i18ngrep ": Last expression must not be negated:" msg
75 test_expect_success 'setup hunk header tests' '
76 for i in $diffpatterns
78 echo "$i-* diff=$i" || return 1
79 done > .gitattributes &&
81 # add all test files to the index
83 cd "$TEST_DIRECTORY"/t4018 &&
84 git --git-dir="$TRASH_DIRECTORY/.git" add .
85 ) &&
87 # place modified files in the worktree
88 for i in $(git ls-files)
90 sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
91 done
94 # check each individual file
95 for i in $(git ls-files)
97 test_expect_success "hunk header: $i" "
98 git diff -U1 $i >actual &&
99 grep '@@ .* @@.*RIGHT' actual
101 done
103 test_done