tests: clean after SANITY tests
Some of our tests try to make sure Git behaves sensibly in a read-only directory, by dropping 'w' permission bit before doing a test and then restoring it after it is done. The latter is needed for the test framework to clean after itself without leaving a leftover directory that cannot be removed. Ancient parts of tests however arrange the above with chmod a-w . && ... do the test ... status=$? chmod 775 . (exit $status) which obviously would not work if the test somehow dies before it has the chance to do "chmod 775". Rewrite them by following a more robust pattern recently written tests use, which is test_when_finished "chmod 775 ." && chmod a-w . && ... do the test ... Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 15, 2018 at 11:13 UTC
037714252f74ae77e816018e43b2504a1b057246
5 files changed
+6
-9
t/t0001-init.sh
+1
@@ -287,6 +287,7 @@ test_expect_success 'init notices EEXIST (2)' '
287
'
288
289
test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
290
+ test_when_finished "chmod +w newdir" &&
291
rm -fr newdir &&
292
mkdir newdir &&
293
chmod -w newdir &&
t/t0070-fundamental.sh
+1
-1
@@ -19,8 +19,8 @@ test_expect_success 'mktemp to nonexistent directory prints filename' '
19
20
test_expect_success POSIXPERM,SANITY 'mktemp to unwritable directory prints filename' '
21
mkdir cannotwrite &&
22
- chmod -w cannotwrite &&
22
test_when_finished "chmod +w cannotwrite" &&
23
+ chmod -w cannotwrite &&
24
test_must_fail test-mktemp cannotwrite/testXXXXXX 2>err &&
25
grep "cannotwrite/test" err
26
'
t/t1004-read-tree-m-u-wf.sh
+2
-4
@@ -179,6 +179,8 @@ test_expect_success 'funny symlink in work tree' '
179
180
test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
181
182
+ test_when_finished "chmod u+w a 2>/dev/null; rm -fr a b" &&
183
+
184
rm -fr a b &&
185
git reset --hard &&
186
@@ -188,10 +190,6 @@ test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
190
191
'
192
191
-# clean-up from the above test
192
-chmod a+w a 2>/dev/null
193
-rm -fr a b
194
-
193
test_expect_success 'D/F setup' '
194
195
git reset --hard &&
t/t5537-fetch-shallow.sh
+1
-1
@@ -175,8 +175,8 @@ EOF
175
176
test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' '
177
cp -R .git read-only.git &&
178
- find read-only.git -print | xargs chmod -w &&
178
test_when_finished "find read-only.git -type d -print | xargs chmod +w" &&
179
+ find read-only.git -print | xargs chmod -w &&
180
git clone --no-local --depth=2 read-only.git from-read-only &&
181
git --git-dir=from-read-only/.git log --format=%s >actual &&
182
cat >expect <<EOF &&
t/t7508-status.sh
+1
-3
@@ -1099,6 +1099,7 @@ EOF
1099
'
1100
1101
test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
1102
+ test_when_finished "chmod 775 .git" &&
1103
(
1104
chmod a-w .git &&
1105
# make dir1/tracked stat-dirty
@@ -1108,9 +1109,6 @@ test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository'
1109
# make sure "status" succeeded without writing index out
1110
git diff-files | grep dir1/tracked
1111
)
1111
- status=$?
1112
- chmod 775 .git
1113
- (exit $status)
1112
'
1113
1114
(cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm