t7102: prepare expected output inside test_expect_* block

That way we can notice if there is a breakage/bug in the parts of the test that prepare the expected outcome, which is how modern tests are arranged. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 21, 2020 at 22:55 UTC 31f4c833acc0dda28e5fa04a457db2787328c78b
1 file changed +121 -123
t/t7102-reset.sh
+121 -123
@@ -82,15 +82,15 @@ test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' '
82 test_i18ncmp .expected .actual
83 '
84
85 ->.diff_expect
86 ->.cached_expect
87 -cat >.cat_expect <<EOF
88 -secondfile:
89 -1st line 2nd file
90 -2nd line 2nd file
91 -EOF
92 -
85 test_expect_success 'giving a non existing revision should fail' '
86 + >.diff_expect &&
87 + >.cached_expect &&
88 + cat >.cat_expect <<-\EOF &&
89 + secondfile:
90 + 1st line 2nd file
91 + 2nd line 2nd file
92 + EOF
93 +
94 test_must_fail git reset aaaaaa &&
95 test_must_fail git reset --mixed aaaaaa &&
96 test_must_fail git reset --soft aaaaaa &&
@@ -191,38 +191,38 @@ test_expect_success 'resetting to HEAD with no changes should succeed and do not
191 check_changes $head5
192 '
193
194 ->.diff_expect
195 -cat >.cached_expect <<EOF
196 -diff --git a/secondfile b/secondfile
197 -index $head5p1s..$head5s 100644
198 ---- a/secondfile
199 -+++ b/secondfile
200 -@@ -1 +1,2 @@
201 --2nd file
202 -+1st line 2nd file
203 -+2nd line 2nd file
204 -EOF
205 -cat >.cat_expect <<EOF
206 -secondfile:
207 -1st line 2nd file
208 -2nd line 2nd file
209 -EOF
194 test_expect_success '--soft reset only should show changes in diff --cached' '
195 + >.diff_expect &&
196 + cat >.cached_expect <<-EOF &&
197 + diff --git a/secondfile b/secondfile
198 + index $head5p1s..$head5s 100644
199 + --- a/secondfile
200 + +++ b/secondfile
201 + @@ -1 +1,2 @@
202 + -2nd file
203 + +1st line 2nd file
204 + +2nd line 2nd file
205 + EOF
206 + cat >.cat_expect <<-\EOF &&
207 + secondfile:
208 + 1st line 2nd file
209 + 2nd line 2nd file
210 + EOF
211 git reset --soft HEAD^ &&
212 check_changes $head5p1 &&
213 test "$(git rev-parse ORIG_HEAD)" = \
214 $head5
215 '
216
217 ->.diff_expect
218 ->.cached_expect
219 -cat >.cat_expect <<EOF
220 -secondfile:
221 -1st line 2nd file
222 -2nd line 2nd file
223 -3rd line 2nd file
224 -EOF
217 test_expect_success 'changing files and redo the last commit should succeed' '
218 + >.diff_expect &&
219 + >.cached_expect &&
220 + cat >.cat_expect <<-\EOF &&
221 + secondfile:
222 + 1st line 2nd file
223 + 2nd line 2nd file
224 + 3rd line 2nd file
225 + EOF
226 echo "3rd line 2nd file" >>secondfile &&
227 git commit -a -C ORIG_HEAD &&
228 head4=$(git rev-parse --verify HEAD) &&
@@ -231,54 +231,54 @@ test_expect_success 'changing files and redo the last commit should succeed' '
231 $head5
232 '
233
234 ->.diff_expect
235 ->.cached_expect
236 -cat >.cat_expect <<EOF
237 -first:
238 -1st file
239 -2nd line 1st file
240 -second:
241 -2nd file
242 -EOF
234 test_expect_success '--hard reset should change the files and undo commits permanently' '
235 + >.diff_expect &&
236 + >.cached_expect &&
237 + cat >.cat_expect <<-\EOF &&
238 + first:
239 + 1st file
240 + 2nd line 1st file
241 + second:
242 + 2nd file
243 + EOF
244 git reset --hard HEAD~2 &&
245 check_changes $head5p2 &&
246 test "$(git rev-parse ORIG_HEAD)" = \
247 $head4
248 '
249
250 ->.diff_expect
251 -cat >.cached_expect <<EOF
252 -diff --git a/first b/first
253 -deleted file mode 100644
254 -index $head5p2f..0000000
255 ---- a/first
256 -+++ /dev/null
257 -@@ -1,2 +0,0 @@
258 --1st file
259 --2nd line 1st file
260 -diff --git a/second b/second
261 -deleted file mode 100644
262 -index $head5p1s..0000000
263 ---- a/second
264 -+++ /dev/null
265 -@@ -1 +0,0 @@
266 --2nd file
267 -diff --git a/secondfile b/secondfile
268 -new file mode 100644
269 -index 0000000..$head5s
270 ---- /dev/null
271 -+++ b/secondfile
272 -@@ -0,0 +1,2 @@
273 -+1st line 2nd file
274 -+2nd line 2nd file
275 -EOF
276 -cat >.cat_expect <<EOF
277 -secondfile:
278 -1st line 2nd file
279 -2nd line 2nd file
280 -EOF
250 test_expect_success 'redoing changes adding them without commit them should succeed' '
251 + >.diff_expect &&
252 + cat >.cached_expect <<-EOF &&
253 + diff --git a/first b/first
254 + deleted file mode 100644
255 + index $head5p2f..0000000
256 + --- a/first
257 + +++ /dev/null
258 + @@ -1,2 +0,0 @@
259 + -1st file
260 + -2nd line 1st file
261 + diff --git a/second b/second
262 + deleted file mode 100644
263 + index $head5p1s..0000000
264 + --- a/second
265 + +++ /dev/null
266 + @@ -1 +0,0 @@
267 + -2nd file
268 + diff --git a/secondfile b/secondfile
269 + new file mode 100644
270 + index 0000000..$head5s
271 + --- /dev/null
272 + +++ b/secondfile
273 + @@ -0,0 +1,2 @@
274 + +1st line 2nd file
275 + +2nd line 2nd file
276 + EOF
277 + cat >.cat_expect <<-\EOF &&
278 + secondfile:
279 + 1st line 2nd file
280 + 2nd line 2nd file
281 + EOF
282 git rm first &&
283 git mv second secondfile &&
284
@@ -288,46 +288,45 @@ test_expect_success 'redoing changes adding them without commit them should succ
288 check_changes $head5p2
289 '
290
291 -cat >.diff_expect <<EOF
292 -diff --git a/first b/first
293 -deleted file mode 100644
294 -index $head5p2f..0000000
295 ---- a/first
296 -+++ /dev/null
297 -@@ -1,2 +0,0 @@
298 --1st file
299 --2nd line 1st file
300 -diff --git a/second b/second
301 -deleted file mode 100644
302 -index $head5p1s..0000000
303 ---- a/second
304 -+++ /dev/null
305 -@@ -1 +0,0 @@
306 --2nd file
307 -EOF
308 ->.cached_expect
309 -cat >.cat_expect <<EOF
310 -secondfile:
311 -1st line 2nd file
312 -2nd line 2nd file
313 -EOF
291 test_expect_success '--mixed reset to HEAD should unadd the files' '
292 + cat >.diff_expect <<-EOF &&
293 + diff --git a/first b/first
294 + deleted file mode 100644
295 + index $head5p2f..0000000
296 + --- a/first
297 + +++ /dev/null
298 + @@ -1,2 +0,0 @@
299 + -1st file
300 + -2nd line 1st file
301 + diff --git a/second b/second
302 + deleted file mode 100644
303 + index $head5p1s..0000000
304 + --- a/second
305 + +++ /dev/null
306 + @@ -1 +0,0 @@
307 + -2nd file
308 + EOF
309 + >.cached_expect &&
310 + cat >.cat_expect <<-\EOF &&
311 + secondfile:
312 + 1st line 2nd file
313 + 2nd line 2nd file
314 + EOF
315 git reset &&
316 check_changes $head5p2 &&
317 test "$(git rev-parse ORIG_HEAD)" = $head5p2
318 '
319
320 ->.diff_expect
321 ->.cached_expect
322 -cat >.cat_expect <<EOF
323 -secondfile:
324 -1st line 2nd file
325 -2nd line 2nd file
326 -EOF
320 test_expect_success 'redoing the last two commits should succeed' '
321 + >.diff_expect &&
322 + >.cached_expect &&
323 + cat >.cat_expect <<-\EOF &&
324 + secondfile:
325 + 1st line 2nd file
326 + 2nd line 2nd file
327 + EOF
328 git add secondfile &&
329 git reset --hard $head5p2 &&
330 -
330 git rm first &&
331 git mv second secondfile &&
332 git commit -a -m "remove 1st and rename 2nd" &&
@@ -340,15 +339,15 @@ test_expect_success 'redoing the last two commits should succeed' '
339 check_changes $head5
340 '
341
343 ->.diff_expect
344 ->.cached_expect
345 -cat >.cat_expect <<EOF
346 -secondfile:
347 -1st line 2nd file
348 -2nd line 2nd file
349 -3rd line in branch2
350 -EOF
342 test_expect_success '--hard reset to HEAD should clear a failed merge' '
343 + >.diff_expect &&
344 + >.cached_expect &&
345 + cat >.cat_expect <<-\EOF &&
346 + secondfile:
347 + 1st line 2nd file
348 + 2nd line 2nd file
349 + 3rd line in branch2
350 + EOF
351 git branch branch1 &&
352 git branch branch2 &&
353
@@ -366,14 +365,14 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' '
365 check_changes $head3
366 '
367
369 ->.diff_expect
370 ->.cached_expect
371 -cat >.cat_expect <<EOF
372 -secondfile:
373 -1st line 2nd file
374 -2nd line 2nd file
375 -EOF
368 test_expect_success '--hard reset to ORIG_HEAD should clear a fast-forward merge' '
369 + >.diff_expect &&
370 + >.cached_expect &&
371 + cat >.cat_expect <<-\EOF &&
372 + secondfile:
373 + 1st line 2nd file
374 + 2nd line 2nd file
375 + EOF
376 git reset --hard HEAD^ &&
377 check_changes $head5 &&
378
@@ -460,12 +459,11 @@ test_expect_success 'resetting an unmodified path is a no-op' '
459 git diff-index --cached --exit-code HEAD
460 '
461
463 -cat >expect <<EOF
464 -Unstaged changes after reset:
465 -M file2
466 -EOF
467 -
462 test_expect_success '--mixed refreshes the index' '
463 + cat >expect <<-\EOF &&
464 + Unstaged changes after reset:
465 + M file2
466 + EOF
467 echo 123 >>file2 &&
468 git reset --mixed HEAD >output &&
469 test_i18ncmp expect output