@matheusbsbs / matheus-bagliano / commits / c91cfd1916
Fork 0

tests: A SANITY test prereq for testing if we're root

Some tests depend on not being able to write to files after chmod -w. This doesn't work when running the tests as root. Change test-lib.sh to test if this works, and if so it sets a new SANITY test prerequisite. The tests that use this previously failed when run under root. There was already a test for this in t3600-rm.sh, added by Junio C Hamano in 2283645 in 2006. That check now uses the new SANITY prerequisite. Some of this was resurrected from the "Tests in Cygwin" thread in May 2009: http://thread.gmane.org/gmane.comp.version-control.git/116729/focus=118385 Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Aug 6, 2010 at 22:09 UTC c91cfd19160be63e97f28dce8c9af421b61c9938
9 files changed +24 -32
t/README
+5
@@ -523,6 +523,11 @@ use these, and "test_set_prereq" for how to define your own.
523 The filesystem we're on supports symbolic links. E.g. a FAT
524 filesystem doesn't support these. See 704a3143 for details.
525
526 + - SANITY
527 +
528 + Test is not run by root user, and an attempt to write to an
529 + unwritable file is expected to fail correctly.
530 +
531 Tips for Writing Tests
532 ----------------------
533
t/t0001-init.sh
+1 -1
@@ -301,7 +301,7 @@ test_expect_success 'init notices EEXIST (2)' '
301 )
302 '
303
304 -test_expect_success POSIXPERM 'init notices EPERM' '
304 +test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
305 rm -fr newdir &&
306 (
307 mkdir newdir &&
t/t0004-unwritable.sh
+4 -4
@@ -15,7 +15,7 @@ test_expect_success setup '
15
16 '
17
18 -test_expect_success POSIXPERM 'write-tree should notice unwritable repository' '
18 +test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable repository' '
19
20 (
21 chmod a-w .git/objects .git/objects/?? &&
@@ -27,7 +27,7 @@ test_expect_success POSIXPERM 'write-tree should notice unwritable repository' '
27
28 '
29
30 -test_expect_success POSIXPERM 'commit should notice unwritable repository' '
30 +test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' '
31
32 (
33 chmod a-w .git/objects .git/objects/?? &&
@@ -39,7 +39,7 @@ test_expect_success POSIXPERM 'commit should notice unwritable repository' '
39
40 '
41
42 -test_expect_success POSIXPERM 'update-index should notice unwritable repository' '
42 +test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repository' '
43
44 (
45 echo 6O >file &&
@@ -52,7 +52,7 @@ test_expect_success POSIXPERM 'update-index should notice unwritable repository'
52
53 '
54
55 -test_expect_success POSIXPERM 'add should notice unwritable repository' '
55 +test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' '
56
57 (
58 echo b >file &&
t/t1004-read-tree-m-u-wf.sh
+1 -1
@@ -177,7 +177,7 @@ test_expect_success SYMLINKS 'funny symlink in work tree' '
177
178 '
179
180 -test_expect_success SYMLINKS 'funny symlink in work tree, un-unlink-able' '
180 +test_expect_success SYMLINKS,SANITY 'funny symlink in work tree, un-unlink-able' '
181
182 rm -fr a b &&
183 git reset --hard &&
t/t3600-rm.sh
-16
@@ -28,22 +28,6 @@ embedded' &&
28 git commit -m 'add files with tabs and newlines'
29 "
30
31 -# Determine rm behavior
32 -# Later we will try removing an unremovable path to make sure
33 -# git rm barfs, but if the test is run as root that cannot be
34 -# arranged.
35 -: >test-file
36 -chmod a-w .
37 -rm -f test-file 2>/dev/null
38 -if test -f test-file
39 -then
40 - test_set_prereq RO_DIR
41 -else
42 - skip_all='skipping removal failure test (perhaps running as root?)'
43 -fi
44 -chmod 775 .
45 -rm -f test-file
46 -
31 test_expect_success \
32 'Pre-check that foo exists and is in index before git rm foo' \
33 '[ -f foo ] && git ls-files --error-unmatch foo'
t/t3700-add.sh
+5 -5
@@ -179,7 +179,7 @@ test_expect_success 'git add --refresh' '
179 test -z "`git diff-index HEAD -- foo`"
180 '
181
182 -test_expect_success POSIXPERM 'git add should fail atomically upon an unreadable file' '
182 +test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unreadable file' '
183 git reset --hard &&
184 date >foo1 &&
185 date >foo2 &&
@@ -190,7 +190,7 @@ test_expect_success POSIXPERM 'git add should fail atomically upon an unreadable
190
191 rm -f foo2
192
193 -test_expect_success POSIXPERM 'git add --ignore-errors' '
193 +test_expect_success POSIXPERM,SANITY 'git add --ignore-errors' '
194 git reset --hard &&
195 date >foo1 &&
196 date >foo2 &&
@@ -201,7 +201,7 @@ test_expect_success POSIXPERM 'git add --ignore-errors' '
201
202 rm -f foo2
203
204 -test_expect_success POSIXPERM 'git add (add.ignore-errors)' '
204 +test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors)' '
205 git config add.ignore-errors 1 &&
206 git reset --hard &&
207 date >foo1 &&
@@ -212,7 +212,7 @@ test_expect_success POSIXPERM 'git add (add.ignore-errors)' '
212 '
213 rm -f foo2
214
215 -test_expect_success POSIXPERM 'git add (add.ignore-errors = false)' '
215 +test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
216 git config add.ignore-errors 0 &&
217 git reset --hard &&
218 date >foo1 &&
@@ -223,7 +223,7 @@ test_expect_success POSIXPERM 'git add (add.ignore-errors = false)' '
223 '
224 rm -f foo2
225
226 -test_expect_success POSIXPERM '--no-ignore-errors overrides config' '
226 +test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
227 git config add.ignore-errors 1 &&
228 git reset --hard &&
229 date >foo1 &&
t/t7300-clean.sh
+3 -4
@@ -388,16 +388,15 @@ test_expect_success 'core.excludesfile' '
388
389 '
390
391 -test_expect_success 'removal failure' '
391 +test_expect_success SANITY 'removal failure' '
392
393 mkdir foo &&
394 touch foo/bar &&
395 (exec <foo/bar &&
396 chmod 0 foo &&
397 - test_must_fail git clean -f -d)
398 -
397 + test_must_fail git clean -f -d &&
398 + chmod 755 foo)
399 '
400 -chmod 755 foo
400
401 test_expect_success 'nested git work tree' '
402 rm -fr foo bar &&
t/t7508-status.sh
+1 -1
@@ -793,7 +793,7 @@ test_expect_success 'commit --dry-run submodule summary (--amend)' '
793 test_cmp expect output
794 '
795
796 -test_expect_success POSIXPERM 'status succeeds in a read-only repository' '
796 +test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
797 (
798 chmod a-w .git &&
799 # make dir1/tracked stat-dirty
t/test-lib.sh
+4
@@ -897,3 +897,7 @@ test -z "$NO_PYTHON" && test_set_prereq PYTHON
897 # test whether the filesystem supports symbolic links
898 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
899 rm -f y
900 +
901 +# When the tests are run as root, permission tests will report that
902 +# things are writable when they shouldn't be.
903 +test -w / || test_set_prereq SANITY