Skip to content

Commit 5d64229

Browse files
jiangxingitster
authored andcommitted
t1301: use test_when_finished for cleanup
Refactor several test cases to use "test_when_finished" for cleanup. 1. For first of these, we used to clean-up outside the test, but instead let's use test_when_finished for that. 2. For the second, we used to leave "new" after we are done, but not use it at all later. Now we do clean up. 3. For the rest, these child.git test repositories used to follow "initialize what we are going to use to a known state before we use" pattern, which is not wrong per-se, but now we use "clean up the cruft we made after we are done" pattern, which may arguably be better simply because the test that makes cruft should know what cruft it created better than whatever comes later that may not know. Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0883a2 commit 5d64229

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

t/t1301-shared-repo.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test_expect_success 'shared = 0400 (faulty permission u-w)' '
2525
for u in 002 022
2626
do
2727
test_expect_success POSIXPERM "shared=1 does not clear bits preset by umask $u" '
28+
test_when_finished "rm -rf sub" &&
2829
mkdir sub && (
2930
cd sub &&
3031
umask $u &&
@@ -42,7 +43,6 @@ do
4243
;;
4344
esac
4445
'
45-
rm -rf sub
4646
done
4747

4848
test_expect_success 'shared=all' '
@@ -132,6 +132,7 @@ test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' '
132132
'
133133

134134
test_expect_success POSIXPERM 'forced modes' '
135+
test_when_finished "rm -rf new" &&
135136
mkdir -p templates/hooks &&
136137
echo update-server-info >templates/hooks/post-update &&
137138
chmod +x templates/hooks/post-update &&
@@ -174,6 +175,7 @@ test_expect_success POSIXPERM 'forced modes' '
174175
'
175176

176177
test_expect_success POSIXPERM 'remote init does not use config from cwd' '
178+
test_when_finished "rm -rf child.git" &&
177179
git config core.sharedrepository 0666 &&
178180
umask 0022 &&
179181
git init --bare child.git &&
@@ -193,7 +195,7 @@ test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' '
193195
'
194196

195197
test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)' '
196-
rm -rf child.git &&
198+
test_when_finished "rm -rf child.git" &&
197199
umask 0022 &&
198200
git init --bare --shared=0666 child.git &&
199201
test_path_is_missing child.git/foo &&
@@ -204,7 +206,7 @@ test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)'
204206
'
205207

206208
test_expect_success POSIXPERM 'template can set core.sharedrepository' '
207-
rm -rf child.git &&
209+
test_when_finished "rm -rf child.git" &&
208210
umask 0022 &&
209211
git config core.sharedrepository 0666 &&
210212
cp .git/config templates/config &&

0 commit comments

Comments
 (0)