Merge branch 'ds/reprepare-alternates-when-repreparing-packfiles'
[alt-git.git] / t / t4032-diff-inter-hunk-context.sh
blob7db92d0d9f461aca48fb4ebf014cd03cb1401a1c
1 #!/bin/sh
3 test_description='diff hunk fusing'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 f() {
9 echo $1
10 i=1
11 while test $i -le $2
13 echo $i
14 i=$(expr $i + 1)
15 done
16 echo $3
19 t() {
20 use_config=
21 git config --unset diff.interHunkContext
23 case $# in
24 4) hunks=$4; cmd="diff -U$3";;
25 5) hunks=$5; cmd="diff -U$3 --inter-hunk-context=$4";;
26 6) hunks=$5; cmd="diff -U$3"; git config diff.interHunkContext $4; use_config="(diff.interHunkContext=$4) ";;
27 esac
28 label="$use_config$cmd, $1 common $2"
29 file=f$1
30 expected=expected.$file.$3.$hunks
32 if ! test -f $file
33 then
34 f A $1 B >$file
35 git add $file
36 git commit -q -m. $file
37 f X $1 Y >$file
40 test_expect_success "$label: count hunks ($hunks)" "
41 test $(git $cmd $file | grep '^@@ ' | wc -l) = $hunks
44 test -f $expected &&
45 test_expect_success "$label: check output" "
46 git $cmd $file | grep -v '^index ' >actual &&
47 test_cmp $expected actual
51 cat <<EOF >expected.f1.0.1 || exit 1
52 diff --git a/f1 b/f1
53 --- a/f1
54 +++ b/f1
55 @@ -1,3 +1,3 @@
61 EOF
63 cat <<EOF >expected.f1.0.2 || exit 1
64 diff --git a/f1 b/f1
65 --- a/f1
66 +++ b/f1
67 @@ -1 +1 @@
70 @@ -3 +3 @@ A
73 EOF
75 # common lines ctx intrctx hunks
76 t 1 line 0 2
77 t 1 line 0 0 2
78 t 1 line 0 1 1
79 t 1 line 0 2 1
80 t 1 line 1 1
82 t 2 lines 0 2
83 t 2 lines 0 0 2
84 t 2 lines 0 1 2
85 t 2 lines 0 2 1
86 t 2 lines 1 1
88 t 3 lines 1 2
89 t 3 lines 1 0 2
90 t 3 lines 1 1 1
91 t 3 lines 1 2 1
93 t 9 lines 3 2
94 t 9 lines 3 2 2
95 t 9 lines 3 3 1
97 # use diff.interHunkContext?
98 t 1 line 0 0 2 config
99 t 1 line 0 1 1 config
100 t 1 line 0 2 1 config
101 t 9 lines 3 3 1 config
102 t 2 lines 0 0 2 config
103 t 2 lines 0 1 2 config
104 t 2 lines 0 2 1 config
105 t 3 lines 1 0 2 config
106 t 3 lines 1 1 1 config
107 t 3 lines 1 2 1 config
108 t 9 lines 3 2 2 config
109 t 9 lines 3 3 1 config
111 test_expect_success 'diff.interHunkContext invalid' '
112 git config diff.interHunkContext asdf &&
113 test_must_fail git diff &&
114 git config diff.interHunkContext -1 &&
115 test_must_fail git diff
118 test_done