@matheusbsbs / matheus-bagliano / commits / 4c0734578f
Fork 0

t7600 (merge): modernize style

Guard setup commands with test_expect_success, so they are easier to visually skip over and get to the good part. While at it: - use "printf '%s\n' a b ..." instead of "cat <<EOF" for test vectors with short lines; - use test_cmp instead of test foo = bar where possible, for better output with -v on failure; - do not go to extraordinary lengths to print a relevant message when test commands fail. There is a patch in flight that could be used to restore the nice error messages in a cleaner way. Cc: Lars Hjemli <hjemli@gmail.com> Cc: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Aug 17, 2010 at 01:53 UTC 4c0734578f3eee3fe6282014257edfcd7084174b
1 file changed +101 -187
t/t7600-merge.sh
+101 -187
@@ -5,189 +5,103 @@
5
6 test_description='git merge
7
8 -Testing basic merge operations/option parsing.'
8 +Testing basic merge operations/option parsing.
9 +
10 +! [c0] commit 0
11 + ! [c1] commit 1
12 + ! [c2] commit 2
13 + ! [c3] commit 3
14 + ! [c4] c4
15 + ! [c5] c5
16 + ! [c6] c6
17 + * [master] Merge commit 'c1'
18 +--------
19 + - [master] Merge commit 'c1'
20 + + * [c1] commit 1
21 + + [c6] c6
22 + + [c5] c5
23 + ++ [c4] c4
24 + ++++ [c3] commit 3
25 + + [c2] commit 2
26 ++++++++* [c0] commit 0
27 +'
28
29 . ./test-lib.sh
30
12 -cat >file <<EOF
13 -1
14 -2
15 -3
16 -4
17 -5
18 -6
19 -7
20 -8
21 -9
22 -EOF
23 -
24 -cat >file.1 <<EOF
25 -1 X
26 -2
27 -3
28 -4
29 -5
30 -6
31 -7
32 -8
33 -9
34 -EOF
35 -
36 -cat >file.5 <<EOF
37 -1
38 -2
39 -3
40 -4
41 -5 X
42 -6
43 -7
44 -8
45 -9
46 -EOF
47 -
48 -cat >file.9 <<EOF
49 -1
50 -2
51 -3
52 -4
53 -5
54 -6
55 -7
56 -8
57 -9 X
58 -EOF
59 -
60 -cat >result.1 <<EOF
61 -1 X
62 -2
63 -3
64 -4
65 -5
66 -6
67 -7
68 -8
69 -9
70 -EOF
71 -
72 -cat >result.1-5 <<EOF
73 -1 X
74 -2
75 -3
76 -4
77 -5 X
78 -6
79 -7
80 -8
81 -9
82 -EOF
83 -
84 -cat >result.1-5-9 <<EOF
85 -1 X
86 -2
87 -3
88 -4
89 -5 X
90 -6
91 -7
92 -8
93 -9 X
94 -EOF
95 -
96 -create_merge_msgs() {
97 - echo "Merge commit 'c2'" >msg.1-5 &&
98 - echo "Merge commit 'c2'; commit 'c3'" >msg.1-5-9 &&
99 - echo "Squashed commit of the following:" >squash.1 &&
100 - echo >>squash.1 &&
101 - git log --no-merges ^HEAD c1 >>squash.1 &&
102 - echo "Squashed commit of the following:" >squash.1-5 &&
103 - echo >>squash.1-5 &&
104 - git log --no-merges ^HEAD c2 >>squash.1-5 &&
105 - echo "Squashed commit of the following:" >squash.1-5-9 &&
106 - echo >>squash.1-5-9 &&
107 - git log --no-merges ^HEAD c2 c3 >>squash.1-5-9 &&
108 - echo > msg.nolog &&
109 - echo "* commit 'c3':" >msg.log &&
110 - echo " commit 3" >>msg.log &&
111 - echo >>msg.log
112 -}
113 -
114 -verify_diff() {
115 - if ! test_cmp "$1" "$2"
116 - then
117 - echo "$3"
118 - false
119 - fi
120 -}
121 -
122 -verify_merge() {
123 - verify_diff "$2" "$1" "[OOPS] bad merge result" &&
124 - if test $(git ls-files -u | wc -l) -gt 0
125 - then
126 - echo "[OOPS] unmerged files"
127 - false
128 - fi &&
129 - if test_must_fail git diff --exit-code
130 - then
131 - echo "[OOPS] working tree != index"
132 - false
133 - fi &&
134 - if test -n "$3"
135 - then
136 - git show -s --pretty=format:%s HEAD >msg.act &&
137 - verify_diff "$3" msg.act "[OOPS] bad merge message"
138 - fi
139 -}
140 -
141 -verify_head() {
142 - if test "$1" != "$(git rev-parse HEAD)"
143 - then
144 - echo "[OOPS] HEAD != $1"
145 - false
146 - fi
147 -}
148 -
149 -verify_parents() {
150 - i=1
151 - while test $# -gt 0
152 - do
153 - if test "$1" != "$(git rev-parse HEAD^$i)"
31 +test_expect_success 'set up test data and helpers' '
32 + printf "%s\n" 1 2 3 4 5 6 7 8 9 >file &&
33 + printf "%s\n" "1 X" 2 3 4 5 6 7 8 9 >file.1 &&
34 + printf "%s\n" 1 2 3 4 "5 X" 6 7 8 9 >file.5 &&
35 + printf "%s\n" 1 2 3 4 5 6 7 8 "9 X" >file.9 &&
36 + printf "%s\n" "1 X" 2 3 4 5 6 7 8 9 >result.1 &&
37 + printf "%s\n" "1 X" 2 3 4 "5 X" 6 7 8 9 >result.1-5 &&
38 + printf "%s\n" "1 X" 2 3 4 "5 X" 6 7 8 "9 X" >result.1-5-9 &&
39 +
40 + create_merge_msgs() {
41 + echo "Merge commit '\''c2'\''" >msg.1-5 &&
42 + echo "Merge commit '\''c2'\''; commit '\''c3'\''" >msg.1-5-9 &&
43 + {
44 + echo "Squashed commit of the following:" &&
45 + echo &&
46 + git log --no-merges ^HEAD c1
47 + } >squash.1 &&
48 + {
49 + echo "Squashed commit of the following:" &&
50 + echo &&
51 + git log --no-merges ^HEAD c2
52 + } >squash.1-5 &&
53 + {
54 + echo "Squashed commit of the following:" &&
55 + echo &&
56 + git log --no-merges ^HEAD c2 c3
57 + } >squash.1-5-9 &&
58 + echo >msg.nolog &&
59 + {
60 + echo "* commit '\''c3'\'':" &&
61 + echo " commit 3" &&
62 + echo
63 + } >msg.log
64 + } &&
65 +
66 + verify_merge() {
67 + test_cmp "$2" "$1" &&
68 + git update-index --refresh &&
69 + git diff --exit-code &&
70 + if test -n "$3"
71 then
155 - echo "[OOPS] HEAD^$i != $1"
156 - return 1
72 + git show -s --pretty=format:%s HEAD >msg.act &&
73 + test_cmp "$3" msg.act
74 fi
158 - i=$(expr $i + 1)
159 - shift
160 - done
161 -}
162 -
163 -verify_mergeheads() {
164 - i=1
165 - if ! test -f .git/MERGE_HEAD
166 - then
167 - echo "[OOPS] MERGE_HEAD is missing"
168 - false
169 - fi &&
170 - while test $# -gt 0
171 - do
172 - head=$(head -n $i .git/MERGE_HEAD | sed -ne \$p)
173 - if test "$1" != "$head"
174 - then
175 - echo "[OOPS] MERGE_HEAD $i != $1"
75 + } &&
76 +
77 + verify_head() {
78 + echo "$1" >head.expected &&
79 + git rev-parse HEAD >head.actual &&
80 + test_cmp head.expected head.actual
81 + } &&
82 +
83 + verify_parents() {
84 + printf "%s\n" "$@" >parents.expected &&
85 + >parents.actual &&
86 + i=1 &&
87 + while test $i -le $#
88 + do
89 + git rev-parse HEAD^$i >>parents.actual &&
90 + i=$(expr $i + 1) ||
91 return 1
177 - fi
178 - i=$(expr $i + 1)
179 - shift
180 - done
181 -}
92 + done &&
93 + test_cmp parents.expected parents.actual
94 + } &&
95
183 -verify_no_mergehead() {
184 - if test -f .git/MERGE_HEAD
185 - then
186 - echo "[OOPS] MERGE_HEAD exists"
187 - false
188 - fi
189 -}
96 + verify_mergeheads() {
97 + printf "%s\n" "$@" >mergehead.expected &&
98 + test_cmp mergehead.expected .git/MERGE_HEAD
99 + } &&
100
101 + verify_no_mergehead() {
102 + ! test -e .git/MERGE_HEAD
103 + }
104 +'
105
106 test_expect_success 'setup' '
107 git add file &&
@@ -316,7 +230,7 @@ test_expect_success 'merge c0 with c1 (squash)' '
230 verify_merge file result.1 &&
231 verify_head $c0 &&
232 verify_no_mergehead &&
319 - verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message"
233 + test_cmp squash.1 .git/SQUASH_MSG
234 '
235
236 test_debug 'gitk --all'
@@ -327,7 +241,7 @@ test_expect_success 'merge c0 with c1 (squash, ff-only)' '
241 verify_merge file result.1 &&
242 verify_head $c0 &&
243 verify_no_mergehead &&
330 - verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message"
244 + test_cmp squash.1 .git/SQUASH_MSG
245 '
246
247 test_debug 'gitk --all'
@@ -338,7 +252,7 @@ test_expect_success 'merge c1 with c2 (squash)' '
252 verify_merge file result.1-5 &&
253 verify_head $c1 &&
254 verify_no_mergehead &&
341 - verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
255 + test_cmp squash.1-5 .git/SQUASH_MSG
256 '
257
258 test_debug 'gitk --all'
@@ -356,7 +270,7 @@ test_expect_success 'merge c1 with c2 and c3 (squash)' '
270 verify_merge file result.1-5-9 &&
271 verify_head $c1 &&
272 verify_no_mergehead &&
359 - verify_diff squash.1-5-9 .git/SQUASH_MSG "[OOPS] bad squash message"
273 + test_cmp squash.1-5-9 .git/SQUASH_MSG
274 '
275
276 test_debug 'gitk --all'
@@ -379,7 +293,7 @@ test_expect_success 'merge c1 with c2 (squash in config)' '
293 verify_merge file result.1-5 &&
294 verify_head $c1 &&
295 verify_no_mergehead &&
382 - verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
296 + test_cmp squash.1-5 .git/SQUASH_MSG
297 '
298
299 test_debug 'gitk --all'
@@ -485,17 +399,17 @@ test_expect_success 'merge log message' '
399 git reset --hard c0 &&
400 git merge --no-log c2 &&
401 git show -s --pretty=format:%b HEAD >msg.act &&
488 - verify_diff msg.nolog msg.act "[OOPS] bad merge log message" &&
402 + test_cmp msg.nolog msg.act &&
403
404 git merge --log c3 &&
405 git show -s --pretty=format:%b HEAD >msg.act &&
492 - verify_diff msg.log msg.act "[OOPS] bad merge log message" &&
406 + test_cmp msg.log msg.act &&
407
408 git reset --hard HEAD^ &&
409 git config merge.log yes &&
410 git merge c3 &&
411 git show -s --pretty=format:%b HEAD >msg.act &&
498 - verify_diff msg.log msg.act "[OOPS] bad merge log message"
412 + test_cmp msg.log msg.act
413 '
414
415 test_debug 'gitk --all'
@@ -545,7 +459,7 @@ test_debug 'gitk --all'
459
460 test_expect_success 'in-index merge' '
461 git reset --hard c0 &&
548 - git merge --no-ff -s resolve c1 > out &&
462 + git merge --no-ff -s resolve c1 >out &&
463 grep "Wonderful." out &&
464 verify_parents $c0 $c1
465 '
@@ -567,16 +481,16 @@ EOF
481
482 test_expect_success 'merge early part of c2' '
483 git reset --hard c3 &&
570 - echo c4 > c4.c &&
484 + echo c4 >c4.c &&
485 git add c4.c &&
486 git commit -m c4 &&
487 git tag c4 &&
574 - echo c5 > c5.c &&
488 + echo c5 >c5.c &&
489 git add c5.c &&
490 git commit -m c5 &&
491 git tag c5 &&
492 git reset --hard c3 &&
579 - echo c6 > c6.c &&
493 + echo c6 >c6.c &&
494 git add c6.c &&
495 git commit -m c6 &&
496 git tag c6 &&