Don Slutz <Don.Slutz@xxxxxxxxxxxxxxxxxx> writes: > A lot of these failures are do to running as root (member of > Administrators).... Perhaps we can do this to reduce the noise level. --- t/README | 26 +++++++++++++++++++++++--- t/t1004-read-tree-m-u-wf.sh | 2 +- t/t7300-clean.sh | 2 +- t/test-lib.sh | 22 +++++++++++++++------- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/t/README b/t/README index d8f6c7d..a532c32 100644 --- a/t/README +++ b/t/README @@ -194,19 +194,28 @@ Test harness library There are a handful helper functions defined in the test harness library for your script to use. - - test_expect_success <message> <script> + - test_expect_success [<prereq>] <message> <script> - This takes two strings as parameter, and evaluates the + This takes two or three strings as parameters, and evaluates the <script>. If it yields success, test is considered successful. <message> should state what it is testing. + An optional parameter <prereq> is a space separated list of prerequisite + tokens. The test will be skipped if the test environment lacks any of + the prerequiste feature listed (see below for commonly used + prerequisites). + Example: test_expect_success \ 'git-write-tree should be able to write an empty tree.' \ 'tree=$(git-write-tree)' - - test_expect_failure <message> <script> + test_expect_success SANITY '/ should not be writable' ' + ! test -w / + ' + + - test_expect_failure [<prereq>] <message> <script> This is NOT the opposite of test_expect_success, but is used to mark a test that demonstrates a known breakage. Unlike @@ -247,6 +256,17 @@ library for your script to use. Merges the given rev using the given message. Like test_commit, creates a tag and calls test_tick before committing. +Prerequisites +------------- + + POSIXPERM The filesystem supports POSIX style permission bits + BSLASHPSPEC ??? + EXECKEEPSPID The process retains the same pid across exec(2) + + SANITY Test is not run by root user, and an attempt to an + unwritable file is expected to fail correctly. + + Tips for Writing Tests ---------------------- diff --git a/t/t1004-read-tree-m-u-wf.sh b/t/t1004-read-tree-m-u-wf.sh index f19b4a2..eb60f80 100755 --- a/t/t1004-read-tree-m-u-wf.sh +++ b/t/t1004-read-tree-m-u-wf.sh @@ -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 && diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 929d5d4..7a5f680 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -369,7 +369,7 @@ test_expect_success 'core.excludesfile' ' ' -test_expect_success 'removal failure' ' +test_expect_success SANITY 'removal failure' ' mkdir foo && touch foo/bar && diff --git a/t/test-lib.sh b/t/test-lib.sh index dad1437..1922e0b 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -264,12 +264,16 @@ test_set_prereq () { satisfied=" " test_have_prereq () { - case $satisfied in - *" $1 "*) - : yes, have it ;; - *) - ! : nope ;; - esac + for prerequisite + do + case $satisfied in + *" $prerequisite "*) + : yes, have it ;; + *) + return 1 ;; + esac + done + : } # You are not expected to call test_ok_ and test_failure_ directly, use @@ -670,6 +674,10 @@ do esac done +# When tests are run as root (which is silly), permission +# tests will report things are writable when they should not be. +test -w / || test_set_prereq SANITY + # Fix some commands on Windows case $(uname -s) in *MINGW*) @@ -692,7 +700,7 @@ case $(uname -s) in # exec does not inherit the PID ;; *) - test_set_prereq POSIXPERM + test_have_prereq SANITY && test_set_prereq POSIXPERM test_set_prereq BSLASHPSPEC test_set_prereq EXECKEEPSPID ;; -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html