t6022 (renaming merge): chain test commands with &&
Using 'return' in an attempt to end a test assertion can have unpredictable results (probably escaping from test_run_ and breaking its bookkeeping). Redo the control flow using helpers like test_expect_code and git diff --exit-code, so each test assertion can follow the usual form command that should succeed && command that should succeed && command that should succeed && ... Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Oct 31, 2010 at 02:34 UTC
cae3aa79aaa62f414c38a44b3073767b1def3a6b
1 file changed
+92
-190
t/t6022-merge-rename.sh
+92
-190
@@ -94,245 +94,147 @@ git checkout master'
94
95
test_expect_success 'pull renaming branch into unrenaming one' \
96
'
97
- git show-branch
98
- git pull . white && {
99
- echo "BAD: should have conflicted"
100
- return 1
101
- }
102
- git ls-files -s
103
- test "$(git ls-files -u B | wc -l)" -eq 3 || {
104
- echo "BAD: should have left stages for B"
105
- return 1
106
- }
107
- test "$(git ls-files -s N | wc -l)" -eq 1 || {
108
- echo "BAD: should have merged N"
109
- return 1
110
- }
97
+ git show-branch &&
98
+ test_expect_code 1 git pull . white &&
99
+ git ls-files -s &&
100
+ git ls-files -u B >b.stages &&
101
+ test_line_count = 3 b.stages &&
102
+ git ls-files -s N >n.stages &&
103
+ test_line_count = 1 n.stages &&
104
sed -ne "/^g/{
105
p
106
q
114
- }" B | grep master || {
115
- echo "BAD: should have listed our change first"
116
- return 1
117
- }
118
- test "$(git diff white N | wc -l)" -eq 0 || {
119
- echo "BAD: should have taken colored branch"
120
- return 1
121
- }
107
+ }" B | grep master &&
108
+ git diff --exit-code white N
109
'
110
111
test_expect_success 'pull renaming branch into another renaming one' \
112
'
126
- rm -f B
127
- git reset --hard
128
- git checkout red
129
- git pull . white && {
130
- echo "BAD: should have conflicted"
131
- return 1
132
- }
133
- test "$(git ls-files -u B | wc -l)" -eq 3 || {
134
- echo "BAD: should have left stages"
135
- return 1
136
- }
137
- test "$(git ls-files -s N | wc -l)" -eq 1 || {
138
- echo "BAD: should have merged N"
139
- return 1
140
- }
113
+ rm -f B &&
114
+ git reset --hard &&
115
+ git checkout red &&
116
+ test_expect_code 1 git pull . white &&
117
+ git ls-files -u B >b.stages &&
118
+ test_line_count = 3 b.stages &&
119
+ git ls-files -s N >n.stages &&
120
+ test_line_count = 1 n.stages &&
121
sed -ne "/^g/{
122
p
123
q
144
- }" B | grep red || {
145
- echo "BAD: should have listed our change first"
146
- return 1
147
- }
148
- test "$(git diff white N | wc -l)" -eq 0 || {
149
- echo "BAD: should have taken colored branch"
150
- return 1
151
- }
124
+ }" B | grep red &&
125
+ git diff --exit-code white N
126
'
127
128
test_expect_success 'pull unrenaming branch into renaming one' \
129
'
156
- git reset --hard
157
- git show-branch
158
- git pull . master && {
159
- echo "BAD: should have conflicted"
160
- return 1
161
- }
162
- test "$(git ls-files -u B | wc -l)" -eq 3 || {
163
- echo "BAD: should have left stages"
164
- return 1
165
- }
166
- test "$(git ls-files -s N | wc -l)" -eq 1 || {
167
- echo "BAD: should have merged N"
168
- return 1
169
- }
130
+ git reset --hard &&
131
+ git show-branch &&
132
+ test_expect_code 1 git pull . master &&
133
+ git ls-files -u B >b.stages &&
134
+ test_line_count = 3 b.stages &&
135
+ git ls-files -s N >n.stages &&
136
+ test_line_count = 1 n.stages &&
137
sed -ne "/^g/{
138
p
139
q
173
- }" B | grep red || {
174
- echo "BAD: should have listed our change first"
175
- return 1
176
- }
177
- test "$(git diff white N | wc -l)" -eq 0 || {
178
- echo "BAD: should have taken colored branch"
179
- return 1
180
- }
140
+ }" B | grep red &&
141
+ git diff --exit-code white N
142
'
143
144
test_expect_success 'pull conflicting renames' \
145
'
185
- git reset --hard
186
- git show-branch
187
- git pull . blue && {
188
- echo "BAD: should have conflicted"
189
- return 1
190
- }
191
- test "$(git ls-files -u A | wc -l)" -eq 1 || {
192
- echo "BAD: should have left a stage"
193
- return 1
194
- }
195
- test "$(git ls-files -u B | wc -l)" -eq 1 || {
196
- echo "BAD: should have left a stage"
197
- return 1
198
- }
199
- test "$(git ls-files -u C | wc -l)" -eq 1 || {
200
- echo "BAD: should have left a stage"
201
- return 1
202
- }
203
- test "$(git ls-files -s N | wc -l)" -eq 1 || {
204
- echo "BAD: should have merged N"
205
- return 1
206
- }
146
+ git reset --hard &&
147
+ git show-branch &&
148
+ test_expect_code 1 git pull . blue &&
149
+ git ls-files -u A >a.stages &&
150
+ test_line_count = 1 a.stages &&
151
+ git ls-files -u B >b.stages &&
152
+ test_line_count = 1 b.stages &&
153
+ git ls-files -u C >c.stages &&
154
+ test_line_count = 1 c.stages &&
155
+ git ls-files -s N >n.stages &&
156
+ test_line_count = 1 n.stages &&
157
sed -ne "/^g/{
158
p
159
q
210
- }" B | grep red || {
211
- echo "BAD: should have listed our change first"
212
- return 1
213
- }
214
- test "$(git diff white N | wc -l)" -eq 0 || {
215
- echo "BAD: should have taken colored branch"
216
- return 1
217
- }
160
+ }" B | grep red &&
161
+ git diff --exit-code white N
162
'
163
164
test_expect_success 'interference with untracked working tree file' '
221
-
222
- git reset --hard
223
- git show-branch
224
- echo >A this file should not matter
225
- git pull . white && {
226
- echo "BAD: should have conflicted"
227
- return 1
228
- }
229
- test -f A || {
230
- echo "BAD: should have left A intact"
231
- return 1
232
- }
165
+ git reset --hard &&
166
+ git show-branch &&
167
+ echo >A this file should not matter &&
168
+ test_expect_code 1 git pull . white &&
169
+ test_path_is_file A
170
'
171
172
test_expect_success 'interference with untracked working tree file' '
236
-
237
- git reset --hard
238
- git checkout white
239
- git show-branch
240
- rm -f A
241
- echo >A this file should not matter
242
- git pull . red && {
243
- echo "BAD: should have conflicted"
244
- return 1
245
- }
246
- test -f A || {
247
- echo "BAD: should have left A intact"
248
- return 1
249
- }
173
+ git reset --hard &&
174
+ git checkout white &&
175
+ git show-branch &&
176
+ rm -f A &&
177
+ echo >A this file should not matter &&
178
+ test_expect_code 1 git pull . red &&
179
+ test_path_is_file A
180
'
181
182
test_expect_success 'interference with untracked working tree file' '
253
-
254
- git reset --hard
255
- rm -f A M
256
- git checkout -f master
257
- git tag -f anchor
258
- git show-branch
259
- git pull . yellow || {
260
- echo "BAD: should have cleanly merged"
261
- return 1
262
- }
263
- test -f M && {
264
- echo "BAD: should have removed M"
265
- return 1
266
- }
183
+ git reset --hard &&
184
+ rm -f A M &&
185
+ git checkout -f master &&
186
+ git tag -f anchor &&
187
+ git show-branch &&
188
+ git pull . yellow &&
189
+ test_path_is_missing M &&
190
git reset --hard anchor
191
'
192
193
test_expect_success 'updated working tree file should prevent the merge' '
271
-
272
- git reset --hard
273
- rm -f A M
274
- git checkout -f master
275
- git tag -f anchor
276
- git show-branch
277
- echo >>M one line addition
278
- cat M >M.saved
279
- git pull . yellow && {
280
- echo "BAD: should have complained"
281
- return 1
282
- }
283
- test_cmp M M.saved || {
284
- echo "BAD: should have left M intact"
285
- return 1
286
- }
194
+ git reset --hard &&
195
+ rm -f A M &&
196
+ git checkout -f master &&
197
+ git tag -f anchor &&
198
+ git show-branch &&
199
+ echo >>M one line addition &&
200
+ cat M >M.saved &&
201
+ test_expect_code 128 git pull . yellow &&
202
+ test_cmp M M.saved &&
203
rm -f M.saved
204
'
205
206
test_expect_success 'updated working tree file should prevent the merge' '
291
-
292
- git reset --hard
293
- rm -f A M
294
- git checkout -f master
295
- git tag -f anchor
296
- git show-branch
297
- echo >>M one line addition
298
- cat M >M.saved
299
- git update-index M
300
- git pull . yellow && {
301
- echo "BAD: should have complained"
302
- return 1
303
- }
304
- test_cmp M M.saved || {
305
- echo "BAD: should have left M intact"
306
- return 1
307
- }
207
+ git reset --hard &&
208
+ rm -f A M &&
209
+ git checkout -f master &&
210
+ git tag -f anchor &&
211
+ git show-branch &&
212
+ echo >>M one line addition &&
213
+ cat M >M.saved &&
214
+ git update-index M &&
215
+ test_expect_code 128 git pull . yellow &&
216
+ test_cmp M M.saved &&
217
rm -f M.saved
218
'
219
220
test_expect_success 'interference with untracked working tree file' '
312
-
313
- git reset --hard
314
- rm -f A M
315
- git checkout -f yellow
316
- git tag -f anchor
317
- git show-branch
318
- echo >M this file should not matter
319
- git pull . master || {
320
- echo "BAD: should have cleanly merged"
321
- return 1
322
- }
323
- test -f M || {
324
- echo "BAD: should have left M intact"
325
- return 1
326
- }
327
- git ls-files -s | grep M && {
328
- echo "BAD: M must be untracked in the result"
329
- return 1
330
- }
221
+ git reset --hard &&
222
+ rm -f A M &&
223
+ git checkout -f yellow &&
224
+ git tag -f anchor &&
225
+ git show-branch &&
226
+ echo >M this file should not matter &&
227
+ git pull . master &&
228
+ test_path_is_file M &&
229
+ ! {
230
+ git ls-files -s |
231
+ grep M
232
+ } &&
233
git reset --hard anchor
234
'
235
236
test_expect_success 'merge of identical changes in a renamed file' '
335
- rm -f A M N
237
+ rm -f A M N &&
238
git reset --hard &&
239
git checkout change+rename &&
240
GIT_MERGE_VERBOSITY=3 git merge change | grep "^Skipped B" &&