Skip to content

Commit

Permalink
tests: A SANITY test prereq for testing if we're root
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ævar Arnfjörð Bjarmason authored and Junio C Hamano committed Aug 18, 2010
1 parent be53dee commit c91cfd1
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 32 deletions.
5 changes: 5 additions & 0 deletions t/README
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ use these, and "test_set_prereq" for how to define your own.
The filesystem we're on supports symbolic links. E.g. a FAT
filesystem doesn't support these. See 704a3143 for details.

- SANITY

Test is not run by root user, and an attempt to write to an
unwritable file is expected to fail correctly.

Tips for Writing Tests
----------------------

Expand Down
2 changes: 1 addition & 1 deletion t/t0001-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ test_expect_success 'init notices EEXIST (2)' '
)
'

test_expect_success POSIXPERM 'init notices EPERM' '
test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
rm -fr newdir &&
(
mkdir newdir &&
Expand Down
8 changes: 4 additions & 4 deletions t/t0004-unwritable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_expect_success setup '
'

test_expect_success POSIXPERM 'write-tree should notice unwritable repository' '
test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable repository' '
(
chmod a-w .git/objects .git/objects/?? &&
Expand All @@ -27,7 +27,7 @@ test_expect_success POSIXPERM 'write-tree should notice unwritable repository' '
'

test_expect_success POSIXPERM 'commit should notice unwritable repository' '
test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' '
(
chmod a-w .git/objects .git/objects/?? &&
Expand All @@ -39,7 +39,7 @@ test_expect_success POSIXPERM 'commit should notice unwritable repository' '
'

test_expect_success POSIXPERM 'update-index should notice unwritable repository' '
test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repository' '
(
echo 6O >file &&
Expand All @@ -52,7 +52,7 @@ test_expect_success POSIXPERM 'update-index should notice unwritable repository'
'

test_expect_success POSIXPERM 'add should notice unwritable repository' '
test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' '
(
echo b >file &&
Expand Down
2 changes: 1 addition & 1 deletion t/t1004-read-tree-m-u-wf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ test_expect_success SYMLINKS 'funny symlink in work tree' '
'

test_expect_success SYMLINKS 'funny symlink in work tree, un-unlink-able' '
test_expect_success SYMLINKS,SANITY 'funny symlink in work tree, un-unlink-able' '
rm -fr a b &&
git reset --hard &&
Expand Down
16 changes: 0 additions & 16 deletions t/t3600-rm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ embedded' &&
git commit -m 'add files with tabs and newlines'
"

# Determine rm behavior
# Later we will try removing an unremovable path to make sure
# git rm barfs, but if the test is run as root that cannot be
# arranged.
: >test-file
chmod a-w .
rm -f test-file 2>/dev/null
if test -f test-file
then
test_set_prereq RO_DIR
else
skip_all='skipping removal failure test (perhaps running as root?)'
fi
chmod 775 .
rm -f test-file

test_expect_success \
'Pre-check that foo exists and is in index before git rm foo' \
'[ -f foo ] && git ls-files --error-unmatch foo'
Expand Down
10 changes: 5 additions & 5 deletions t/t3700-add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ test_expect_success 'git add --refresh' '
test -z "`git diff-index HEAD -- foo`"
'

test_expect_success POSIXPERM 'git add should fail atomically upon an unreadable file' '
test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unreadable file' '
git reset --hard &&
date >foo1 &&
date >foo2 &&
Expand All @@ -190,7 +190,7 @@ test_expect_success POSIXPERM 'git add should fail atomically upon an unreadable

rm -f foo2

test_expect_success POSIXPERM 'git add --ignore-errors' '
test_expect_success POSIXPERM,SANITY 'git add --ignore-errors' '
git reset --hard &&
date >foo1 &&
date >foo2 &&
Expand All @@ -201,7 +201,7 @@ test_expect_success POSIXPERM 'git add --ignore-errors' '

rm -f foo2

test_expect_success POSIXPERM 'git add (add.ignore-errors)' '
test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors)' '
git config add.ignore-errors 1 &&
git reset --hard &&
date >foo1 &&
Expand All @@ -212,7 +212,7 @@ test_expect_success POSIXPERM 'git add (add.ignore-errors)' '
'
rm -f foo2

test_expect_success POSIXPERM 'git add (add.ignore-errors = false)' '
test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
git config add.ignore-errors 0 &&
git reset --hard &&
date >foo1 &&
Expand All @@ -223,7 +223,7 @@ test_expect_success POSIXPERM 'git add (add.ignore-errors = false)' '
'
rm -f foo2

test_expect_success POSIXPERM '--no-ignore-errors overrides config' '
test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
git config add.ignore-errors 1 &&
git reset --hard &&
date >foo1 &&
Expand Down
7 changes: 3 additions & 4 deletions t/t7300-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -388,16 +388,15 @@ test_expect_success 'core.excludesfile' '
'

test_expect_success 'removal failure' '
test_expect_success SANITY 'removal failure' '
mkdir foo &&
touch foo/bar &&
(exec <foo/bar &&
chmod 0 foo &&
test_must_fail git clean -f -d)
test_must_fail git clean -f -d &&
chmod 755 foo)
'
chmod 755 foo

test_expect_success 'nested git work tree' '
rm -fr foo bar &&
Expand Down
2 changes: 1 addition & 1 deletion t/t7508-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ test_expect_success 'commit --dry-run submodule summary (--amend)' '
test_cmp expect output
'

test_expect_success POSIXPERM 'status succeeds in a read-only repository' '
test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
(
chmod a-w .git &&
# make dir1/tracked stat-dirty
Expand Down
4 changes: 4 additions & 0 deletions t/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -897,3 +897,7 @@ test -z "$NO_PYTHON" && test_set_prereq PYTHON
# test whether the filesystem supports symbolic links
ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
rm -f y

# When the tests are run as root, permission tests will report that
# things are writable when they shouldn't be.
test -w / || test_set_prereq SANITY

0 comments on commit c91cfd1

Please sign in to comment.