t7610: use test_when_finished for cleanup tasks

This is a step toward making the tests more independent so that if one test fails it doesn't cause subsequent tests to fail. Signed-off-by: Richard Hansen <hansenr@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Richard Hansen committed Jan 10, 2017 at 15:41 UTC 614eb27f0212a875dd6a8ea057ecb4af80d6111d
1 file changed +37 -34
t/t7610-mergetool.sh
+37 -34
@@ -145,6 +145,11 @@ test_expect_success 'custom mergetool' '
145 '
146
147 test_expect_success 'mergetool crlf' '
148 + test_when_finished "git reset --hard" &&
149 + # This test_config line must go after the above reset line so that
150 + # core.autocrlf is unconfigured before reset runs. (The
151 + # test_config command uses test_when_finished internally and
152 + # test_when_finished is LIFO.)
153 test_config core.autocrlf true &&
154 git checkout -b test$test_count branch1 &&
155 test_must_fail git merge master >/dev/null 2>&1 &&
@@ -161,9 +166,7 @@ test_expect_success 'mergetool crlf' '
166 test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
167 git submodule update -N &&
168 test "$(cat submod/bar)" = "master submodule" &&
164 - git commit -m "branch1 resolved with mergetool - autocrlf" &&
165 - test_config core.autocrlf false &&
166 - git reset --hard
169 + git commit -m "branch1 resolved with mergetool - autocrlf"
170 '
171
172 test_expect_success 'mergetool in subdir' '
@@ -194,6 +197,7 @@ test_expect_success 'mergetool on file in parent dir' '
197 '
198
199 test_expect_success 'mergetool skips autoresolved' '
200 + test_when_finished "git reset --hard" &&
201 git checkout -b test$test_count branch1 &&
202 git submodule update -N &&
203 test_must_fail git merge master &&
@@ -202,8 +206,7 @@ test_expect_success 'mergetool skips autoresolved' '
206 ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
207 ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
208 output="$(git mergetool --no-prompt)" &&
205 - test "$output" = "No files need merging" &&
206 - git reset --hard
209 + test "$output" = "No files need merging"
210 '
211
212 test_expect_success 'mergetool merges all from subdir' '
@@ -223,6 +226,7 @@ test_expect_success 'mergetool merges all from subdir' '
226 '
227
228 test_expect_success 'mergetool skips resolved paths when rerere is active' '
229 + test_when_finished "git reset --hard" &&
230 test_config rerere.enabled true &&
231 rm -rf .git/rr-cache &&
232 git checkout -b test$test_count branch1 &&
@@ -232,8 +236,7 @@ test_expect_success 'mergetool skips resolved paths when rerere is active' '
236 ( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) &&
237 git submodule update -N &&
238 output="$(yes "n" | git mergetool --no-prompt)" &&
235 - test "$output" = "No files need merging" &&
236 - git reset --hard
239 + test "$output" = "No files need merging"
240 '
241
242 test_expect_success 'conflicted stash sets up rerere' '
@@ -264,6 +267,7 @@ test_expect_success 'conflicted stash sets up rerere' '
267 '
268
269 test_expect_success 'mergetool takes partial path' '
270 + test_when_finished "git reset --hard" &&
271 git reset --hard &&
272 test_config rerere.enabled false &&
273 git checkout -b test$test_count branch1 &&
@@ -272,11 +276,11 @@ test_expect_success 'mergetool takes partial path' '
276
277 ( yes "" | git mergetool subdir ) &&
278
275 - test "$(cat subdir/file3)" = "master new sub" &&
276 - git reset --hard
279 + test "$(cat subdir/file3)" = "master new sub"
280 '
281
282 test_expect_success 'mergetool delete/delete conflict' '
283 + test_when_finished "git reset --hard HEAD" &&
284 git checkout move-to-c &&
285 test_must_fail git merge move-to-b &&
286 echo d | git mergetool a/a/file.txt &&
@@ -288,29 +292,30 @@ test_expect_success 'mergetool delete/delete conflict' '
292 git reset --hard HEAD &&
293 test_must_fail git merge move-to-b &&
294 ! echo a | git mergetool a/a/file.txt &&
291 - ! test -f a/a/file.txt &&
292 - git reset --hard HEAD
295 + ! test -f a/a/file.txt
296 '
297
298 test_expect_success 'mergetool produces no errors when keepBackup is used' '
299 + test_when_finished "git reset --hard HEAD" &&
300 test_config mergetool.keepBackup true &&
301 test_must_fail git merge move-to-b &&
302 : >expect &&
303 echo d | git mergetool a/a/file.txt 2>actual &&
304 test_cmp expect actual &&
301 - ! test -d a &&
302 - git reset --hard HEAD
305 + ! test -d a
306 '
307
308 test_expect_success 'mergetool honors tempfile config for deleted files' '
309 + test_when_finished "git reset --hard HEAD" &&
310 test_config mergetool.keepTemporaries false &&
311 test_must_fail git merge move-to-b &&
312 echo d | git mergetool a/a/file.txt &&
309 - ! test -d a &&
310 - git reset --hard HEAD
313 + ! test -d a
314 '
315
316 test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
317 + test_when_finished "git reset --hard HEAD" &&
318 + test_when_finished "git clean -fdx" &&
319 test_config mergetool.keepTemporaries true &&
320 test_must_fail git merge move-to-b &&
321 ! (echo a; echo n) | git mergetool a/a/file.txt &&
@@ -321,12 +326,11 @@ test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
326 file_REMOTE_.txt
327 EOF
328 ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
324 - test_cmp expect actual &&
325 - git clean -fdx &&
326 - git reset --hard HEAD
329 + test_cmp expect actual
330 '
331
332 test_expect_success 'deleted vs modified submodule' '
333 + test_when_finished "git reset --hard HEAD" &&
334 git checkout -b test$test_count branch1 &&
335 git submodule update -N &&
336 mv submod submod-movedaside &&
@@ -391,8 +395,7 @@ test_expect_success 'deleted vs modified submodule' '
395 test "$(cat submod/bar)" = "master submodule" &&
396 output="$(git mergetool --no-prompt)" &&
397 test "$output" = "No files need merging" &&
394 - git commit -m "Merge resolved by keeping module" &&
395 - git reset --hard HEAD
398 + git commit -m "Merge resolved by keeping module"
399 '
400
401 test_expect_success 'file vs modified submodule' '
@@ -479,6 +482,7 @@ test_expect_success 'submodule in subdirectory' '
482 git commit -m "add initial versions"
483 )
484 ) &&
485 + test_when_finished "rm -rf subdir/subdir_module" &&
486 git submodule add git://example.com/subsubmodule subdir/subdir_module &&
487 git add subdir/subdir_module &&
488 git commit -m "add submodule in subdirectory" &&
@@ -523,8 +527,7 @@ test_expect_success 'submodule in subdirectory' '
527 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
528 git submodule update -N &&
529 test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" &&
526 - git commit -m "branch1 resolved with mergetool" &&
527 - rm -rf subdir/subdir_module
530 + git commit -m "branch1 resolved with mergetool"
531 '
532
533 test_expect_success 'directory vs modified submodule' '
@@ -578,34 +581,34 @@ test_expect_success 'directory vs modified submodule' '
581 '
582
583 test_expect_success 'file with no base' '
584 + test_when_finished "git reset --hard master >/dev/null 2>&1" &&
585 git checkout -b test$test_count branch1 &&
586 test_must_fail git merge master &&
587 git mergetool --no-prompt --tool mybase -- both &&
588 >expected &&
585 - test_cmp both expected &&
586 - git reset --hard master >/dev/null 2>&1
589 + test_cmp both expected
590 '
591
592 test_expect_success 'custom commands override built-ins' '
593 + test_when_finished "git reset --hard master >/dev/null 2>&1" &&
594 git checkout -b test$test_count branch1 &&
595 test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
596 test_config mergetool.defaults.trustExitCode true &&
597 test_must_fail git merge master &&
598 git mergetool --no-prompt --tool defaults -- both &&
599 echo master both added >expected &&
596 - test_cmp both expected &&
597 - git reset --hard master >/dev/null 2>&1
600 + test_cmp both expected
601 '
602
603 test_expect_success 'filenames seen by tools start with ./' '
604 + test_when_finished "git reset --hard master >/dev/null 2>&1" &&
605 git checkout -b test$test_count branch1 &&
606 test_config mergetool.writeToTemp false &&
607 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
608 test_config mergetool.myecho.trustExitCode true &&
609 test_must_fail git merge master &&
610 git mergetool --no-prompt --tool myecho -- both >actual &&
607 - grep ^\./both_LOCAL_ actual >/dev/null &&
608 - git reset --hard master >/dev/null 2>&1
611 + grep ^\./both_LOCAL_ actual >/dev/null
612 '
613
614 test_lazy_prereq MKTEMP '
@@ -615,6 +618,7 @@ test_lazy_prereq MKTEMP '
618 '
619
620 test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
621 + test_when_finished "git reset --hard master >/dev/null 2>&1" &&
622 git checkout -b test$test_count branch1 &&
623 test_config mergetool.writeToTemp true &&
624 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
@@ -622,11 +626,11 @@ test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToT
626 test_must_fail git merge master &&
627 git mergetool --no-prompt --tool myecho -- both >actual &&
628 test_must_fail grep ^\./both_LOCAL_ actual >/dev/null &&
625 - grep /both_LOCAL_ actual >/dev/null &&
626 - git reset --hard master >/dev/null 2>&1
629 + grep /both_LOCAL_ actual >/dev/null
630 '
631
632 test_expect_success 'diff.orderFile configuration is honored' '
633 + test_when_finished "git reset --hard >/dev/null" &&
634 git checkout order-file-side2 &&
635 test_config diff.orderFile order-file &&
636 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
@@ -641,10 +645,10 @@ test_expect_success 'diff.orderFile configuration is honored' '
645 EOF
646 git mergetool --no-prompt --tool myecho >output &&
647 git grep --no-index -h -A2 Merging: output >actual &&
644 - test_cmp expect actual &&
645 - git reset --hard >/dev/null
648 + test_cmp expect actual
649 '
650 test_expect_success 'mergetool -Oorder-file is honored' '
651 + test_when_finished "git reset --hard >/dev/null 2>&1" &&
652 test_config diff.orderFile order-file &&
653 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
654 test_config mergetool.myecho.trustExitCode true &&
@@ -668,8 +672,7 @@ test_expect_success 'mergetool -Oorder-file is honored' '
672 EOF
673 git mergetool -Oorder-file --no-prompt --tool myecho >output &&
674 git grep --no-index -h -A2 Merging: output >actual &&
671 - test_cmp expect actual &&
672 - git reset --hard >/dev/null 2>&1
675 + test_cmp expect actual
676 '
677
678 test_done