Subject: [PATCH 2/2] test-lib.sh: Dynamic test for the prerequisite SANITY

From: Torsten Bögershausen <[email-masked]>
Date: Tue, 27 Jan 2015 16:39:01 +0100

The SANITY precondition was not set when running as root,
but this is not 100% reliable for CYGWIN:

A file may be allowed to be deleted when the containing
directory does not have write permissions.

See
https://technet.microsoft.com/en-us/library/bb463216.aspx
"...In UNIX, the write permission bit on a directory permits both
the creation and removal of new files or sub-directories in the directory.
On Windows, the Write_Data access right controls the creation of new
sub-files and the Delete_Child access right controls the deletion. ...."

We may argue that the translation of the POSIX write permission bit
into "Windows access rights" can be improved in CYGWIN.

A dynamic test handles all cases: when the sequence
$ mkdir SANETESTD &&
$ chmod +w SANETESTD &&
$ >SANETESTD/x &&
$ ! rm SANETESTD/x
succeeds the prerequisite SANITY is true.

Helped-by: Junio C Hamano <[email-masked]>
Signed-off-by: Torsten Bögershausen <[email-masked]>
---
 t/test-lib.sh | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 93f7cad..887e986 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1038,8 +1038,23 @@ test_lazy_prereq NOT_ROOT '
 
 # When the tests are run as root, permission tests will report that
 # things are writable when they shouldn't be.
+# Special check for CYGWIN (or Windows in general):
+# A file can be deleted, even if the containing directory does'nt
+# have write permissions
 test_lazy_prereq SANITY '
-	test_have_prereq POSIXPERM,NOT_ROOT
+	mkdir SANETESTD &&
+	chmod +w SANETESTD &&
+	>SANETESTD/x &&
+	chmod -w SANETESTD ||
+	error "bug in test sript: cannot prepare SANETESTD"
+
+	! rm SANETESTD/x
+	status=$?
+
+	chmod +w SANETESTD &&
+	rm -rf SANETESTD ||
+	error "bug in test sript: cannot clean SANETESTD"
+	return $status
 '
 
 GIT_UNZIP=${GIT_UNZIP:-unzip}
-- 
2.2.0.rc1.26.g3e3a70d