Skip to content

Commit 31f4c83

Browse files
committed
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 <[email protected]>
1 parent 1c0ab5c commit 31f4c83

File tree

1 file changed

+121
-123
lines changed

1 file changed

+121
-123
lines changed

t/t7102-reset.sh

Lines changed: 121 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' '
8282
test_i18ncmp .expected .actual
8383
'
8484

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-
9385
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+
9494
test_must_fail git reset aaaaaa &&
9595
test_must_fail git reset --mixed aaaaaa &&
9696
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
191191
check_changes $head5
192192
'
193193

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
210194
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
211211
git reset --soft HEAD^ &&
212212
check_changes $head5p1 &&
213213
test "$(git rev-parse ORIG_HEAD)" = \
214214
$head5
215215
'
216216

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
225217
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
226226
echo "3rd line 2nd file" >>secondfile &&
227227
git commit -a -C ORIG_HEAD &&
228228
head4=$(git rev-parse --verify HEAD) &&
@@ -231,54 +231,54 @@ test_expect_success 'changing files and redo the last commit should succeed' '
231231
$head5
232232
'
233233

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
243234
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
244244
git reset --hard HEAD~2 &&
245245
check_changes $head5p2 &&
246246
test "$(git rev-parse ORIG_HEAD)" = \
247247
$head4
248248
'
249249

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
281250
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
282282
git rm first &&
283283
git mv second secondfile &&
284284
@@ -288,46 +288,45 @@ test_expect_success 'redoing changes adding them without commit them should succ
288288
check_changes $head5p2
289289
'
290290

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
314291
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
315315
git reset &&
316316
check_changes $head5p2 &&
317317
test "$(git rev-parse ORIG_HEAD)" = $head5p2
318318
'
319319

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
327320
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
328328
git add secondfile &&
329329
git reset --hard $head5p2 &&
330-
331330
git rm first &&
332331
git mv second secondfile &&
333332
git commit -a -m "remove 1st and rename 2nd" &&
@@ -340,15 +339,15 @@ test_expect_success 'redoing the last two commits should succeed' '
340339
check_changes $head5
341340
'
342341

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
351342
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
352351
git branch branch1 &&
353352
git branch branch2 &&
354353
@@ -366,14 +365,14 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' '
366365
check_changes $head3
367366
'
368367

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
376368
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
377376
git reset --hard HEAD^ &&
378377
check_changes $head5 &&
379378
@@ -460,12 +459,11 @@ test_expect_success 'resetting an unmodified path is a no-op' '
460459
git diff-index --cached --exit-code HEAD
461460
'
462461

463-
cat >expect <<EOF
464-
Unstaged changes after reset:
465-
M file2
466-
EOF
467-
468462
test_expect_success '--mixed refreshes the index' '
463+
cat >expect <<-\EOF &&
464+
Unstaged changes after reset:
465+
M file2
466+
EOF
469467
echo 123 >>file2 &&
470468
git reset --mixed HEAD >output &&
471469
test_i18ncmp expect output

0 commit comments

Comments
 (0)