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

[PATCH v2] t7110: replace `test -f` with `test_path_is_*` helpers

From
Matteo Bagnolini <matteobagnolini2003@gmail.com>
Date
Jan 3, 2025, 13:00 UTC
Message-ID
<20250103130035.79376-1-matteobagnolini2003@gmail.com>
In-Reply-To
<Z3fM1bT2Z_0GoD4w@pks.im>
From: matteobagnolini <matteobagnolini2003@gmail.com>

`test -f` and `! test -f` do not provide clear error messages when they fail. To enhance debuggability, use `test_path_is_file` and `test_path_is_missing`, which instead provide more informative error messages.

Note that `! test -f` checks if a path is not a file, while `test_path_is_missing` verifies that a path does not exist. In this specific case the tests are meant to check the absence of the path, making `test_path_is_missing` a valid replacement.

Signed-off-by: Matteo Bagnolini <matteobagnolini2003@gmail.com>
---
Sorry for avoidable spelling mistakes.
Updated commit message according to review.
 t/t7110-reset-merge.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/t/t7110-reset-merge.sh b/t/t7110-reset-merge.sh
index 61669a2d21..9a335071af 100755
--- a/t/t7110-reset-merge.sh
+++ b/t/t7110-reset-merge.sh
@@ -270,13 +270,13 @@ test_expect_success '--merge is ok with added/deleted merge' '
 	git reset --hard third &&
 	rm -f file2 &&
 	test_must_fail git merge branch3 &&
-	! test -f file2 &&
-	test -f file3 &&
+	test_path_is_missing file2 &&
+	test_path_is_file file3 &&
 	git diff --exit-code file3 &&
 	git diff --exit-code branch3 file3 &&
 	git reset --merge HEAD &&
-	! test -f file3 &&
-	! test -f file2 &&
+	test_path_is_missing file3 &&
+	test_path_is_missing file2 &&
 	git diff --exit-code --cached
 '
 
@@ -284,8 +284,8 @@ test_expect_success '--keep fails with added/deleted merge' '
 	git reset --hard third &&
 	rm -f file2 &&
 	test_must_fail git merge branch3 &&
-	! test -f file2 &&
-	test -f file3 &&
+	test_path_is_missing file2 &&
+	test_path_is_file file3 &&
 	git diff --exit-code file3 &&
 	git diff --exit-code branch3 file3 &&
 	test_must_fail git reset --keep HEAD 2>err.log &&
-- 
2.39.2 (Apple Git-143)
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 8 in “t7110: Replace `test -f` and `! test -f` with `test_path_is_file` and `test_path_is_missing` for improved debuggability when failing.”
  1. t7110: Replace `test -f` and `! test -f` with `test_path_is_file` and `test_path_is_missing` for improved debuggability when failing.matteobagnolini, Jan 1, 2025
  2. Patrick SteinhardtJan 3, 2025
  3. t7110: replace `test -f` with `test_path_is_*` helpersMatteo Bagnolini, Jan 3, 2025
  4. Patrick SteinhardtJan 3, 2025
  5. Junio C HamanoJan 3, 2025
  6. Matteo BagnoliniJan 3, 2025
  7. Junio C HamanoJan 3, 2025
  8. Matteo BagnoliniJan 3, 2025

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.