git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Tests in Cygwin

From
Junio C Hamano <gitster@pobox.com>
Date
May 6, 2009, 20:42 UTC
Message-ID
<7vvdoet13g.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4A01E64C.7050703@SierraAtlantic.com>
Don Slutz <Don.Slutz@SierraAtlantic.com> 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
 	;;
Previous: Don SlutzNext: Johannes Sixt
Message 3 of 16 in “Tests in Cygwin”
  1. Hannu KoivistoApr 17, 2009
  2. Don SlutzMay 6, 2009
  3. Junio C HamanoMay 6, 2009
  4. Johannes SixtMay 7, 2009
  5. Don SlutzMay 7, 2009
  6. Don SlutzMay 7, 2009
  7. Junio C HamanoMay 8, 2009
  8. Johannes SixtMay 8, 2009
  9. Jeff KingMay 8, 2009
  10. Johannes SixtMay 8, 2009
  11. Junio C HamanoMay 8, 2009
  12. Alex RiesenMay 8, 2009
  13. Don SlutzMay 8, 2009
  14. Johannes SixtMay 8, 2009
  15. Alex RiesenMay 8, 2009
  16. Junio C HamanoMay 8, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.