Skip to content

Commit c91cfd1

Browse files
avargitster
authored andcommitted
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>
1 parent be53dee commit c91cfd1

File tree

9 files changed

+24
-32
lines changed

9 files changed

+24
-32
lines changed

t/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ use these, and "test_set_prereq" for how to define your own.
523523
The filesystem we're on supports symbolic links. E.g. a FAT
524524
filesystem doesn't support these. See 704a3143 for details.
525525

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+
526531
Tips for Writing Tests
527532
----------------------
528533

t/t0001-init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ test_expect_success 'init notices EEXIST (2)' '
301301
)
302302
'
303303

304-
test_expect_success POSIXPERM 'init notices EPERM' '
304+
test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
305305
rm -fr newdir &&
306306
(
307307
mkdir newdir &&

t/t0004-unwritable.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test_expect_success setup '
1515
1616
'
1717

18-
test_expect_success POSIXPERM 'write-tree should notice unwritable repository' '
18+
test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable repository' '
1919
2020
(
2121
chmod a-w .git/objects .git/objects/?? &&
@@ -27,7 +27,7 @@ test_expect_success POSIXPERM 'write-tree should notice unwritable repository' '
2727
2828
'
2929

30-
test_expect_success POSIXPERM 'commit should notice unwritable repository' '
30+
test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' '
3131
3232
(
3333
chmod a-w .git/objects .git/objects/?? &&
@@ -39,7 +39,7 @@ test_expect_success POSIXPERM 'commit should notice unwritable repository' '
3939
4040
'
4141

42-
test_expect_success POSIXPERM 'update-index should notice unwritable repository' '
42+
test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repository' '
4343
4444
(
4545
echo 6O >file &&
@@ -52,7 +52,7 @@ test_expect_success POSIXPERM 'update-index should notice unwritable repository'
5252
5353
'
5454

55-
test_expect_success POSIXPERM 'add should notice unwritable repository' '
55+
test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' '
5656
5757
(
5858
echo b >file &&

t/t1004-read-tree-m-u-wf.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ test_expect_success SYMLINKS 'funny symlink in work tree' '
177177
178178
'
179179

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' '
181181
182182
rm -fr a b &&
183183
git reset --hard &&

t/t3600-rm.sh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ embedded' &&
2828
git commit -m 'add files with tabs and newlines'
2929
"
3030

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-
4731
test_expect_success \
4832
'Pre-check that foo exists and is in index before git rm foo' \
4933
'[ -f foo ] && git ls-files --error-unmatch foo'

t/t3700-add.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ test_expect_success 'git add --refresh' '
179179
test -z "`git diff-index HEAD -- foo`"
180180
'
181181

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' '
183183
git reset --hard &&
184184
date >foo1 &&
185185
date >foo2 &&
@@ -190,7 +190,7 @@ test_expect_success POSIXPERM 'git add should fail atomically upon an unreadable
190190

191191
rm -f foo2
192192

193-
test_expect_success POSIXPERM 'git add --ignore-errors' '
193+
test_expect_success POSIXPERM,SANITY 'git add --ignore-errors' '
194194
git reset --hard &&
195195
date >foo1 &&
196196
date >foo2 &&
@@ -201,7 +201,7 @@ test_expect_success POSIXPERM 'git add --ignore-errors' '
201201

202202
rm -f foo2
203203

204-
test_expect_success POSIXPERM 'git add (add.ignore-errors)' '
204+
test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors)' '
205205
git config add.ignore-errors 1 &&
206206
git reset --hard &&
207207
date >foo1 &&
@@ -212,7 +212,7 @@ test_expect_success POSIXPERM 'git add (add.ignore-errors)' '
212212
'
213213
rm -f foo2
214214

215-
test_expect_success POSIXPERM 'git add (add.ignore-errors = false)' '
215+
test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
216216
git config add.ignore-errors 0 &&
217217
git reset --hard &&
218218
date >foo1 &&
@@ -223,7 +223,7 @@ test_expect_success POSIXPERM 'git add (add.ignore-errors = false)' '
223223
'
224224
rm -f foo2
225225

226-
test_expect_success POSIXPERM '--no-ignore-errors overrides config' '
226+
test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
227227
git config add.ignore-errors 1 &&
228228
git reset --hard &&
229229
date >foo1 &&

t/t7300-clean.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,15 @@ test_expect_success 'core.excludesfile' '
388388
389389
'
390390

391-
test_expect_success 'removal failure' '
391+
test_expect_success SANITY 'removal failure' '
392392
393393
mkdir foo &&
394394
touch foo/bar &&
395395
(exec <foo/bar &&
396396
chmod 0 foo &&
397-
test_must_fail git clean -f -d)
398-
397+
test_must_fail git clean -f -d &&
398+
chmod 755 foo)
399399
'
400-
chmod 755 foo
401400

402401
test_expect_success 'nested git work tree' '
403402
rm -fr foo bar &&

t/t7508-status.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ test_expect_success 'commit --dry-run submodule summary (--amend)' '
793793
test_cmp expect output
794794
'
795795

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' '
797797
(
798798
chmod a-w .git &&
799799
# make dir1/tracked stat-dirty

t/test-lib.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,3 +897,7 @@ test -z "$NO_PYTHON" && test_set_prereq PYTHON
897897
# test whether the filesystem supports symbolic links
898898
ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
899899
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

0 commit comments

Comments
 (0)