All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Hansen <hansenr@google.com>
To: git@vger.kernel.org
Cc: davvid@gmail.com, j6t@kdbg.org, hansenr@google.com,
	sbeller@google.com, simon@ruderich.org
Subject: [PATCH v3 04/13] t7610: use test_when_finished for cleanup tasks
Date: Mon,  9 Jan 2017 00:42:29 -0500	[thread overview]
Message-ID: <20170109054238.42599-5-hansenr@google.com> (raw)
In-Reply-To: <20170109054238.42599-1-hansenr@google.com>

[-- Attachment #1: Type: text/plain, Size: 9927 bytes --]

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>
---
 t/t7610-mergetool.sh | 71 +++++++++++++++++++++++++++-------------------------
 1 file changed, 37 insertions(+), 34 deletions(-)

diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index 550838a1c..f62ceffdc 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -145,6 +145,11 @@ test_expect_success 'custom mergetool' '
 '
 
 test_expect_success 'mergetool crlf' '
+	test_when_finished "git reset --hard" &&
+	# This test_config line must go after the above reset line so that
+	# core.autocrlf is unconfigured before reset runs.  (The
+	# test_config command uses test_when_finished internally and
+	# test_when_finished is LIFO.)
 	test_config core.autocrlf true &&
 	git checkout -b test$test_count branch1 &&
 	test_must_fail git merge master >/dev/null 2>&1 &&
@@ -161,9 +166,7 @@ test_expect_success 'mergetool crlf' '
 	test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
 	git submodule update -N &&
 	test "$(cat submod/bar)" = "master submodule" &&
-	git commit -m "branch1 resolved with mergetool - autocrlf" &&
-	test_config core.autocrlf false &&
-	git reset --hard
+	git commit -m "branch1 resolved with mergetool - autocrlf"
 '
 
 test_expect_success 'mergetool in subdir' '
@@ -194,6 +197,7 @@ test_expect_success 'mergetool on file in parent dir' '
 '
 
 test_expect_success 'mergetool skips autoresolved' '
+	test_when_finished "git reset --hard" &&
 	git checkout -b test$test_count branch1 &&
 	git submodule update -N &&
 	test_must_fail git merge master &&
@@ -202,8 +206,7 @@ test_expect_success 'mergetool skips autoresolved' '
 	( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
 	( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
 	output="$(git mergetool --no-prompt)" &&
-	test "$output" = "No files need merging" &&
-	git reset --hard
+	test "$output" = "No files need merging"
 '
 
 test_expect_success 'mergetool merges all from subdir' '
@@ -223,6 +226,7 @@ test_expect_success 'mergetool merges all from subdir' '
 '
 
 test_expect_success 'mergetool skips resolved paths when rerere is active' '
+	test_when_finished "git reset --hard" &&
 	test_config rerere.enabled true &&
 	rm -rf .git/rr-cache &&
 	git checkout -b test$test_count branch1 &&
@@ -232,8 +236,7 @@ test_expect_success 'mergetool skips resolved paths when rerere is active' '
 	( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) &&
 	git submodule update -N &&
 	output="$(yes "n" | git mergetool --no-prompt)" &&
-	test "$output" = "No files need merging" &&
-	git reset --hard
+	test "$output" = "No files need merging"
 '
 
 test_expect_success 'conflicted stash sets up rerere'  '
@@ -264,6 +267,7 @@ test_expect_success 'conflicted stash sets up rerere'  '
 '
 
 test_expect_success 'mergetool takes partial path' '
+	test_when_finished "git reset --hard" &&
 	git reset --hard &&
 	test_config rerere.enabled false &&
 	git checkout -b test$test_count branch1 &&
@@ -272,11 +276,11 @@ test_expect_success 'mergetool takes partial path' '
 
 	( yes "" | git mergetool subdir ) &&
 
-	test "$(cat subdir/file3)" = "master new sub" &&
-	git reset --hard
+	test "$(cat subdir/file3)" = "master new sub"
 '
 
 test_expect_success 'mergetool delete/delete conflict' '
+	test_when_finished "git reset --hard HEAD" &&
 	git checkout move-to-c &&
 	test_must_fail git merge move-to-b &&
 	echo d | git mergetool a/a/file.txt &&
@@ -288,29 +292,30 @@ test_expect_success 'mergetool delete/delete conflict' '
 	git reset --hard HEAD &&
 	test_must_fail git merge move-to-b &&
 	! echo a | git mergetool a/a/file.txt &&
-	! test -f a/a/file.txt &&
-	git reset --hard HEAD
+	! test -f a/a/file.txt
 '
 
 test_expect_success 'mergetool produces no errors when keepBackup is used' '
+	test_when_finished "git reset --hard HEAD" &&
 	test_config mergetool.keepBackup true &&
 	test_must_fail git merge move-to-b &&
 	: >expect &&
 	echo d | git mergetool a/a/file.txt 2>actual &&
 	test_cmp expect actual &&
-	! test -d a &&
-	git reset --hard HEAD
+	! test -d a
 '
 
 test_expect_success 'mergetool honors tempfile config for deleted files' '
+	test_when_finished "git reset --hard HEAD" &&
 	test_config mergetool.keepTemporaries false &&
 	test_must_fail git merge move-to-b &&
 	echo d | git mergetool a/a/file.txt &&
-	! test -d a &&
-	git reset --hard HEAD
+	! test -d a
 '
 
 test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
+	test_when_finished "git reset --hard HEAD" &&
+	test_when_finished "git clean -fdx" &&
 	test_config mergetool.keepTemporaries true &&
 	test_must_fail git merge move-to-b &&
 	! (echo a; echo n) | git mergetool a/a/file.txt &&
@@ -321,12 +326,11 @@ test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
 	file_REMOTE_.txt
 	EOF
 	ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
-	test_cmp expect actual &&
-	git clean -fdx &&
-	git reset --hard HEAD
+	test_cmp expect actual
 '
 
 test_expect_success 'deleted vs modified submodule' '
+	test_when_finished "git reset --hard HEAD" &&
 	git checkout -b test$test_count branch1 &&
 	git submodule update -N &&
 	mv submod submod-movedaside &&
@@ -391,8 +395,7 @@ test_expect_success 'deleted vs modified submodule' '
 	test "$(cat submod/bar)" = "master submodule" &&
 	output="$(git mergetool --no-prompt)" &&
 	test "$output" = "No files need merging" &&
-	git commit -m "Merge resolved by keeping module" &&
-	git reset --hard HEAD
+	git commit -m "Merge resolved by keeping module"
 '
 
 test_expect_success 'file vs modified submodule' '
@@ -479,6 +482,7 @@ test_expect_success 'submodule in subdirectory' '
 		git commit -m "add initial versions"
 		)
 	) &&
+	test_when_finished "rm -rf subdir/subdir_module" &&
 	git submodule add git://example.com/subsubmodule subdir/subdir_module &&
 	git add subdir/subdir_module &&
 	git commit -m "add submodule in subdirectory" &&
@@ -523,8 +527,7 @@ test_expect_success 'submodule in subdirectory' '
 	test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
 	git submodule update -N &&
 	test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" &&
-	git commit -m "branch1 resolved with mergetool" &&
-	rm -rf subdir/subdir_module
+	git commit -m "branch1 resolved with mergetool"
 '
 
 test_expect_success 'directory vs modified submodule' '
@@ -578,34 +581,34 @@ test_expect_success 'directory vs modified submodule' '
 '
 
 test_expect_success 'file with no base' '
+	test_when_finished "git reset --hard master >/dev/null 2>&1" &&
 	git checkout -b test$test_count branch1 &&
 	test_must_fail git merge master &&
 	git mergetool --no-prompt --tool mybase -- both &&
 	>expected &&
-	test_cmp both expected &&
-	git reset --hard master >/dev/null 2>&1
+	test_cmp both expected
 '
 
 test_expect_success 'custom commands override built-ins' '
+	test_when_finished "git reset --hard master >/dev/null 2>&1" &&
 	git checkout -b test$test_count branch1 &&
 	test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
 	test_config mergetool.defaults.trustExitCode true &&
 	test_must_fail git merge master &&
 	git mergetool --no-prompt --tool defaults -- both &&
 	echo master both added >expected &&
-	test_cmp both expected &&
-	git reset --hard master >/dev/null 2>&1
+	test_cmp both expected
 '
 
 test_expect_success 'filenames seen by tools start with ./' '
+	test_when_finished "git reset --hard master >/dev/null 2>&1" &&
 	git checkout -b test$test_count branch1 &&
 	test_config mergetool.writeToTemp false &&
 	test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
 	test_config mergetool.myecho.trustExitCode true &&
 	test_must_fail git merge master &&
 	git mergetool --no-prompt --tool myecho -- both >actual &&
-	grep ^\./both_LOCAL_ actual >/dev/null &&
-	git reset --hard master >/dev/null 2>&1
+	grep ^\./both_LOCAL_ actual >/dev/null
 '
 
 test_lazy_prereq MKTEMP '
@@ -614,6 +617,7 @@ test_lazy_prereq MKTEMP '
 '
 
 test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
+	test_when_finished "git reset --hard master >/dev/null 2>&1" &&
 	git checkout -b test$test_count branch1 &&
 	test_config mergetool.writeToTemp true &&
 	test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
@@ -621,11 +625,11 @@ test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToT
 	test_must_fail git merge master &&
 	git mergetool --no-prompt --tool myecho -- both >actual &&
 	test_must_fail grep ^\./both_LOCAL_ actual >/dev/null &&
-	grep /both_LOCAL_ actual >/dev/null &&
-	git reset --hard master >/dev/null 2>&1
+	grep /both_LOCAL_ actual >/dev/null
 '
 
 test_expect_success 'diff.orderFile configuration is honored' '
+	test_when_finished "git reset --hard >/dev/null" &&
 	git checkout order-file-side2 &&
 	test_config diff.orderFile order-file &&
 	test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
@@ -640,10 +644,10 @@ test_expect_success 'diff.orderFile configuration is honored' '
 	EOF
 	git mergetool --no-prompt --tool myecho >output &&
 	git grep --no-index -h -A2 Merging: output >actual &&
-	test_cmp expect actual &&
-	git reset --hard >/dev/null
+	test_cmp expect actual
 '
 test_expect_success 'mergetool -Oorder-file is honored' '
+	test_when_finished "git reset --hard >/dev/null 2>&1" &&
 	test_config diff.orderFile order-file &&
 	test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
 	test_config mergetool.myecho.trustExitCode true &&
@@ -667,8 +671,7 @@ test_expect_success 'mergetool -Oorder-file is honored' '
 	EOF
 	git mergetool -Oorder-file --no-prompt --tool myecho >output &&
 	git grep --no-index -h -A2 Merging: output >actual &&
-	test_cmp expect actual &&
-	git reset --hard >/dev/null 2>&1
+	test_cmp expect actual
 '
 
 test_done
-- 
2.11.0.390.gc69c2f50cf-goog


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4845 bytes --]

  parent reply	other threads:[~2017-01-09  5:43 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-04  0:50 [PATCH 0/4] fix mergetool+rerere+subdir regression Richard Hansen
2017-01-04  0:50 ` [PATCH 1/4] t7610: update branch names to match test number Richard Hansen
2017-01-04  0:50 ` [PATCH 2/4] t7610: make tests more independent and debuggable Richard Hansen
2017-01-04 20:27   ` Stefan Beller
2017-01-05 15:41     ` Richard Hansen
2017-01-05 15:46     ` Richard Hansen
2017-01-05 12:20   ` Simon Ruderich
2017-01-05 15:48     ` Richard Hansen
2017-01-04  0:50 ` [PATCH 3/4] t7610: add test case for rerere+mergetool+subdir bug Richard Hansen
2017-01-04  0:50 ` [PATCH 4/4] mergetool: fix running in subdir when rerere enabled Richard Hansen
2017-01-06  1:09 ` [PATCH v2 0/4] fix mergetool+rerere+subdir regression Richard Hansen
2017-01-06  1:09   ` [PATCH v2 1/4] t7610: update branch names to match test number Richard Hansen
2017-01-06  1:09   ` [PATCH v2 2/4] t7610: make tests more independent and debuggable Richard Hansen
2017-01-06  1:31     ` Stefan Beller
2017-01-07  1:53       ` Richard Hansen
2017-01-06  1:09   ` [PATCH v2 3/4] t7610: add test case for rerere+mergetool+subdir bug Richard Hansen
2017-01-06  1:09   ` [PATCH v2 4/4] mergetool: fix running in subdir when rerere enabled Richard Hansen
2017-01-06  9:42     ` Johannes Sixt
2017-01-07  2:16       ` Richard Hansen
2017-01-09  5:42   ` [PATCH v3 00/13] fix mergetool+rerere+subdir regression Richard Hansen
2017-01-09  5:42     ` [PATCH v3 01/13] .mailmap: Use my personal email address as my canonical Richard Hansen
2017-01-09  5:42     ` [PATCH v3 02/13] t7610: update branch names to match test number Richard Hansen
2017-01-09  5:42     ` [PATCH v3 03/13] t7610: Move setup code to the 'setup' test case Richard Hansen
2017-01-09  5:42     ` Richard Hansen [this message]
2017-01-09  5:42     ` [PATCH v3 05/13] t7610: don't rely on state from previous test Richard Hansen
2017-01-09  5:42     ` [PATCH v3 06/13] t7610: run 'git reset --hard' after each test to clean up Richard Hansen
2017-01-09  5:42     ` [PATCH v3 07/13] t7610: delete some now-unnecessary 'git reset --hard' lines Richard Hansen
2017-01-09  5:42     ` [PATCH v3 08/13] t7610: always work on a test-specific branch Richard Hansen
2017-01-09  5:42     ` [PATCH v3 09/13] t7610: don't assume the checked-out commit Richard Hansen
2017-01-09  5:42     ` [PATCH v3 10/13] t7610: spell 'git reset --hard' consistently Richard Hansen
2017-01-09  5:42     ` [PATCH v3 11/13] t7610: add test case for rerere+mergetool+subdir bug Richard Hansen
2017-01-09  5:42     ` [PATCH v3 12/13] mergetool: take the "-O" out of $orderfile Richard Hansen
2017-01-09  5:42     ` [PATCH v3 13/13] mergetool: fix running in subdir when rerere enabled Richard Hansen
2017-01-09 18:12       ` Junio C Hamano
2017-01-09 19:05         ` Junio C Hamano
2017-01-09 19:53           ` Johannes Sixt
2017-01-09 22:57           ` Richard Hansen
2017-01-09 23:29           ` Junio C Hamano
2017-01-09 23:32             ` Junio C Hamano
2017-01-09 23:50             ` Richard Hansen
2017-01-09 18:49     ` [PATCH v3 00/13] fix mergetool+rerere+subdir regression Stefan Beller
2017-01-09 23:29     ` [PATCH v4 00/14] " Richard Hansen
2017-01-09 23:29       ` [PATCH v4 01/14] .mailmap: Use my personal email address as my canonical Richard Hansen
2017-01-09 23:29       ` [PATCH v4 02/14] rev-parse doc: use "--" in the --prefix example Richard Hansen
2017-01-09 23:29       ` [PATCH v4 03/14] t7610: update branch names to match test number Richard Hansen
2017-01-09 23:29       ` [PATCH v4 04/14] t7610: Move setup code to the 'setup' test case Richard Hansen
2017-01-09 23:29       ` [PATCH v4 05/14] t7610: use test_when_finished for cleanup tasks Richard Hansen
2017-01-09 23:29       ` [PATCH v4 06/14] t7610: don't rely on state from previous test Richard Hansen
2017-01-09 23:29       ` [PATCH v4 07/14] t7610: run 'git reset --hard' after each test to clean up Richard Hansen
2017-01-09 23:29       ` [PATCH v4 08/14] t7610: delete some now-unnecessary 'git reset --hard' lines Richard Hansen
2017-01-09 23:29       ` [PATCH v4 09/14] t7610: always work on a test-specific branch Richard Hansen
2017-01-09 23:29       ` [PATCH v4 10/14] t7610: don't assume the checked-out commit Richard Hansen
2017-01-09 23:29       ` [PATCH v4 11/14] t7610: spell 'git reset --hard' consistently Richard Hansen
2017-01-09 23:29       ` [PATCH v4 12/14] t7610: add test case for rerere+mergetool+subdir bug Richard Hansen
2017-01-09 23:29       ` [PATCH v4 13/14] mergetool: take the "-O" out of $orderfile Richard Hansen
2017-01-09 23:29       ` [PATCH v4 14/14] mergetool: fix running in subdir when rerere enabled Richard Hansen
2017-01-10  6:17         ` Johannes Sixt
2017-01-10 17:09           ` Richard Hansen
2017-01-10 19:25           ` Junio C Hamano
2017-01-10 20:29             ` Johannes Sixt
2017-01-10 20:41       ` [PATCH v5 00/14] fix mergetool+rerere+subdir regression Richard Hansen
2017-01-10 20:41         ` [PATCH v5 01/14] .mailmap: Use my personal email address as my canonical Richard Hansen
2017-01-10 20:41         ` [PATCH v5 02/14] rev-parse doc: pass "--" to rev-parse in the --prefix example Richard Hansen
2017-01-10 20:41         ` [PATCH v5 03/14] t7610: update branch names to match test number Richard Hansen
2017-01-10 20:41         ` [PATCH v5 04/14] t7610: Move setup code to the 'setup' test case Richard Hansen
2017-01-10 20:41         ` [PATCH v5 05/14] t7610: use test_when_finished for cleanup tasks Richard Hansen
2017-01-10 20:41         ` [PATCH v5 06/14] t7610: don't rely on state from previous test Richard Hansen
2017-01-10 20:41         ` [PATCH v5 07/14] t7610: run 'git reset --hard' after each test to clean up Richard Hansen
2017-01-10 20:41         ` [PATCH v5 08/14] t7610: delete some now-unnecessary 'git reset --hard' lines Richard Hansen
2017-01-10 20:41         ` [PATCH v5 09/14] t7610: always work on a test-specific branch Richard Hansen
2017-01-10 20:41         ` [PATCH v5 10/14] t7610: don't assume the checked-out commit Richard Hansen
2017-01-10 20:41         ` [PATCH v5 11/14] t7610: spell 'git reset --hard' consistently Richard Hansen
2017-01-10 20:42         ` [PATCH v5 12/14] t7610: add test case for rerere+mergetool+subdir bug Richard Hansen
2017-01-10 20:42         ` [PATCH v5 13/14] mergetool: take the "-O" out of $orderfile Richard Hansen
2017-01-10 20:42         ` [PATCH v5 14/14] mergetool: fix running in subdir when rerere enabled Richard Hansen
2017-01-10  4:36 ` [PATCH 0/4] fix mergetool+rerere+subdir regression David Aguilar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170109054238.42599-5-hansenr@google.com \
    --to=hansenr@google.com \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=sbeller@google.com \
    --cc=simon@ruderich.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.