interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4032-diff-inter-hunk-context.sh

125 lines · 2169 bytes Raw Blame History
1#!/bin/sh
2
3test_description='diff hunk fusing'
4
5. ./test-lib.sh
6
7f() {
8 echo $1
9 i=1
10 while test $i -le $2
11 do
12 echo $i
13 i=$(expr $i + 1)
14 done
15 echo $3
16}
17
18t() {
19 use_config=
20 git config --unset diff.interHunkContext || :
21
22 case $# in
23 4) hunks=$4; cmd="diff -U$3";;
24 5) hunks=$5; cmd="diff -U$3 --inter-hunk-context=$4";;
25 6) hunks=$5; cmd="diff -U$3"; git config diff.interHunkContext $4; use_config="(diff.interHunkContext=$4) ";;
26 esac
27 label="$use_config$cmd, $1 common $2"
28 file=f$1
29 expected=expected.$file.$3.$hunks
30
31 if ! test -f $file
32 then
33 f A $1 B >$file
34 git add $file
35 git commit -q -m. $file
36 f X $1 Y >$file
37 fi
38
39 test_expect_success "$label: count hunks ($hunks)" "
40 test $(git $cmd $file | grep '^@@ ' | wc -l) = $hunks
41 "
42
43 if test -f $expected
44 then
45 test_expect_success "$label: check output" "
46 git $cmd $file | grep -v '^index ' >actual &&
47 test_cmp $expected actual
48 "
49 fi
50}
51
52cat <<EOF >expected.f1.0.1 || exit 1
53diff --git a/f1 b/f1
54--- a/f1
55+++ b/f1
56@@ -1,3 +1,3 @@
57-A
58+X
59 1
60-B
61+Y
62EOF
63
64cat <<EOF >expected.f1.0.2 || exit 1
65diff --git a/f1 b/f1
66--- a/f1
67+++ b/f1
68@@ -1 +1 @@
69-A
70+X
71@@ -3 +3 @@ A
72-B
73+Y
74EOF
75
76# common lines ctx intrctx hunks
77t 1 line 0 2
78t 1 line 0 0 2
79t 1 line 0 1 1
80t 1 line 0 2 1
81t 1 line 1 1
82
83t 2 lines 0 2
84t 2 lines 0 0 2
85t 2 lines 0 1 2
86t 2 lines 0 2 1
87t 2 lines 1 1
88
89t 3 lines 1 2
90t 3 lines 1 0 2
91t 3 lines 1 1 1
92t 3 lines 1 2 1
93
94t 9 lines 3 2
95t 9 lines 3 2 2
96t 9 lines 3 3 1
97
98# use diff.interHunkContext?
99t 1 line 0 0 2 config
100t 1 line 0 1 1 config
101t 1 line 0 2 1 config
102t 9 lines 3 3 1 config
103t 2 lines 0 0 2 config
104t 2 lines 0 1 2 config
105t 2 lines 0 2 1 config
106t 3 lines 1 0 2 config
107t 3 lines 1 1 1 config
108t 3 lines 1 2 1 config
109t 9 lines 3 2 2 config
110t 9 lines 3 3 1 config
111
112test_expect_success 'diff.interHunkContext invalid' '
113 git config diff.interHunkContext asdf &&
114 test_must_fail git diff &&
115 git config diff.interHunkContext -1 &&
116 test_must_fail git diff
117'
118
119test_expect_success '--inter-hunk-context rejects negative value' '
120 test_unconfig diff.interHunkContext &&
121 test_must_fail git diff --inter-hunk-context=-1 2>err &&
122 test_grep "expects a non-negative integer" err
123'
124
125test_done