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

[PATCH] t0004: replace test -e with test_path_exists

From
PRASHANT S BISHT <prashantjee2025@gmail.com>
Date
Mar 9, 2026, 17:36 UTC
Message-ID
<20260309173635.29683-1-prashantjee2025@gmail.com>

Replace old-style path existence checks with the modern test_path_exists helper function that provides clearer diagnostic messages on failure. When test -e fails, the output gives no indication of what went wrong.

These instances were found using:
  git grep "test -[efd]" t/ | grep -v "if test"
as suggested in the microproject ideas.
---
 t/t0004-unwritable.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/t/t0004-unwritable.sh b/t/t0004-unwritable.sh
index 3bdafbae0f..2a9fc781b6 100755
--- a/t/t0004-unwritable.sh
+++ b/t/t0004-unwritable.sh
@@ -21,7 +21,7 @@ test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable reposi
 	test_must_fail git write-tree 2>out.write-tree
 '
 
-test_lazy_prereq WRITE_TREE_OUT 'test -e "$TRASH_DIRECTORY"/out.write-tree'
+test_lazy_prereq WRITE_TREE_OUT 'test_path_exists "$TRASH_DIRECTORY/out.write-tree"'
 test_expect_success WRITE_TREE_OUT 'write-tree output on unwritable repository' '
 	cat >expect <<-\EOF &&
 	error: insufficient permission for adding an object to repository database .git/objects
@@ -36,7 +36,7 @@ test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository
 	test_must_fail git commit -m second 2>out.commit
 '
 
-test_lazy_prereq COMMIT_OUT 'test -e "$TRASH_DIRECTORY"/out.commit'
+test_lazy_prereq COMMIT_OUT 'test_path_exists "$TRASH_DIRECTORY/out.commit"'
 test_expect_success COMMIT_OUT 'commit output on unwritable repository' '
 	cat >expect <<-\EOF &&
 	error: insufficient permission for adding an object to repository database .git/objects
@@ -52,7 +52,7 @@ test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repo
 	test_must_fail git update-index file 2>out.update-index
 '
 
-test_lazy_prereq UPDATE_INDEX_OUT 'test -e "$TRASH_DIRECTORY"/out.update-index'
+test_lazy_prereq UPDATE_INDEX_OUT 'test_path_exists "$TRASH_DIRECTORY/out.update-index"'
 test_expect_success UPDATE_INDEX_OUT 'update-index output on unwritable repository' '
 	cat >expect <<-\EOF &&
 	error: insufficient permission for adding an object to repository database .git/objects
@@ -69,7 +69,7 @@ test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' '
 	test_must_fail git add file 2>out.add
 '
 
-test_lazy_prereq ADD_OUT 'test -e "$TRASH_DIRECTORY"/out.add'
+test_lazy_prereq ADD_OUT 'test_path_exists "$TRASH_DIRECTORY/out.add"'
 test_expect_success ADD_OUT 'add output on unwritable repository' '
 	cat >expect <<-\EOF &&
 	error: insufficient permission for adding an object to repository database .git/objects
-- 
2.50.1 (Apple Git-155)
Next: Junio C Hamano
Message 1 of 5 in “t0004: replace test -e with test_path_exists”
  1. t0004: replace test -e with test_path_existsPRASHANT S BISHT, Mar 9, 2026
  2. Junio C HamanoMar 9, 2026
  3. Jeff KingMar 9, 2026
  4. Junio C HamanoMar 9, 2026
  5. t4200: convert test -[df] checks to test_path_* helpersPRASHANT S BISHT, Mar 16, 2026

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.