[PATCH 01/29] t7508: use test_when_finished() instead of managing exit code manually

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This test manages its own exit code in order to perform a cleanup action
unconditionally, whether the test succeeds or fails overall. In doing
so, it intentionally breaks the &&-chain. Such manual exit code
management to ensure cleanup predates the invention of
test_when_finished().

An upcoming change will teach --chain-lint to detect &&-chain breakage
inside subshells, so this manual exit code management with intentional
&&-chain breakage will run afoul of --chain-lint. Therefore, replace
the manual exit code handling with test_when_finished() and a normal
&&-chain. While at it, drop the now-unnecessary subshell.

Signed-off-by: Eric Sunshine <sunshine@xxxxxxxxxxxxxx>
---

Notes:
    This series is built atop 'master'. If the series is queued there,
    this patch is needed to avoid test-suite breakage. However, the
    issue fixed by this patch is already also fixed by
    'jc/clean-after-sanity-tests' in 'next' (although, that patch
    doesn't bother dropping the now-unnecessary subshell, like this
    patch does.)

 t/t7508-status.sh | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 18a40257fb..67bf4393bb 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1099,18 +1099,14 @@ EOF
 '
 
 test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
-	(
-		chmod a-w .git &&
-		# make dir1/tracked stat-dirty
-		>dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
-		git status -s >output &&
-		! grep dir1/tracked output &&
-		# make sure "status" succeeded without writing index out
-		git diff-files | grep dir1/tracked
-	)
-	status=$?
-	chmod 775 .git
-	(exit $status)
+	chmod a-w .git &&
+	test_when_finished "chmod 775 .git" &&
+	# make dir1/tracked stat-dirty
+	>dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
+	git status -s >output &&
+	! grep dir1/tracked output &&
+	# make sure "status" succeeded without writing index out
+	git diff-files | grep dir1/tracked
 '
 
 (cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm
-- 
2.18.0.419.gfe4b301394




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux