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

[PATCH] t0070: Use precondition CANNOTWRITE

From
Torsten Bögershausen <tboegi@web.de>
Date
Jun 8, 2013, 06:51 UTC
Message-ID
<201306080851.17044.tboegi@web.de>

POSIX like file systems allows to create a file when the user has write permissions to the directory.

Filesystems like VFAT or NTFS allow to create files regardless of the write permissions of the directory.

Therefore "mktemp to unwritable directory" in t0700 will always fail on Windows using NTFS. This TC has been disabled for MINGW, and needs to be disabled for CYGWIN.

Use the precondition CANNOTWRITE which is probing the file system and works for MINGW, CYGWIN and even for Linux using VFAT.

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
 t/t0070-fundamental.sh | 19 ++++++++++++-------
 t/test-lib.sh          | 12 ++++++++++++
 2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh
index da2c504..a907445 100755
--- a/t/t0070-fundamental.sh
+++ b/t/t0070-fundamental.sh
@@ -17,13 +17,18 @@ test_expect_success 'mktemp to nonexistent directory prints filename' '
 	grep "doesnotexist/test" err
 '
 
-test_expect_success POSIXPERM 'mktemp to unwritable directory prints filename' '
-	mkdir cannotwrite &&
-	chmod -w cannotwrite &&
-	test_when_finished "chmod +w cannotwrite" &&
-	test_must_fail test-mktemp cannotwrite/testXXXXXX 2>err &&
-	grep "cannotwrite/test" err
-'
+if test_have_prereq CANNOTWRITE
+then
+	test_expect_success 'mktemp to unwritable directory prints filename' '
+		mkdir cannotwrite &&
+		chmod -w cannotwrite &&
+		test_when_finished "chmod +w cannotwrite" &&
+		test_must_fail test-mktemp cannotwrite/testXXXXXX 2>err &&
+		grep "cannotwrite/test" err
+	'
+else
+	say "Skipping mktemp to unwritable directory prints filename"
+fi
 
 test_expect_success 'check for a bug in the regex routines' '
 	# if this test fails, re-build git with NO_REGEX=1
diff --git a/t/test-lib.sh b/t/test-lib.sh
index ca6bdef..1342630 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -770,6 +770,18 @@ test_lazy_prereq AUTOIDENT '
 	git var GIT_AUTHOR_IDENT
 '
 
+test_lazy_prereq CANNOTWRITE '
+	chmod -w .
+	>e || :
+	chmod +w .
+	case "$(echo *)" in
+	e)
+		false ;;
+	*)
+		true ;;
+	esac
+'
+
 # 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
-- 
1.8.2.411.g65a544e
Next: Johannes Sixt
Message 1 of 2 in “t0070: Use precondition CANNOTWRITE”
  1. t0070: Use precondition CANNOTWRITETorsten Bögershausen, Jun 8, 2013
  2. Johannes SixtJun 8, 2013

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.