Skip to contentSkip to conversation

t7110: Replace `test -f` and `! test -f` with `test_path_is_file` and `test_path_is_missing` for improved debuggability when failing.

PATCH In review matteobagnolini 3 participants 8 messages Jan 1, 2025 – Jan 3, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 t7110: Replace `test -f` and `! test -f` with `test_path_is_file` and `test_path_is_missing` for improved debuggability when failing.

test -f and ! test -f do not provide clear error messages when they fail. To enanche debuggability, use test_path_is_file and test_path_is_missing, which instead provides 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.

---
 t/t7110-reset-merge.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
t/t7110-reset-merge.sh +6 -6
index 61669a2d21..9a335071af 100755
@@ -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 &&
Signature · 1 line
2.39.2 (Apple Git-143)
#1 lore raw

On Wed, Jan 01, 2025 at 11:59:14PM +0100, matteobagnolini wrote:

The commit subject is overly long. We typically try to restrict them to at most 72 characters. Furthermore, the part after the subsystem should start with a lower-case letter. Suggestion:

    t7110: replace `test -f` with `test_path_is_*` helpers
Quoted 2 lines

test -f and ! test -f do not provide clear error messages when they fail. To enanche debuggability, use test_path_is_file and test_path_is_missing,

s/enanche/enhance

Quoted 1 line

which instead provides more informative error messages.

s/provides/provide

It looks like you intended to start a new paragraph here. These should typically be separated by an empty line.

Quoted 4 lines

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.

Makes sense.

Quoted 1 line

We typically prefer proper legal names in the SOB.

Quoted 23 lines
t/t7110-reset-merge.sh +4 -4
index 61669a2d21..9a335071af 100755
@@ -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
 '
 

t/t7110-reset-merge.sh test_expect_success '--keep fails with added/deleted merge' ' · line 291

Quoted 10 lines
t/t7110-reset-merge.sh +2 -2
@@ -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 &&

The changes themselves look obviously good to me, thanks!

Patrick

#2 lore raw

PATCH v2 1/1 t7110: replace `test -f` with `test_path_is_*` helpers

From: matteobagnolini <[email protected]>

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.

---
Sorry for avoidable spelling mistakes.
Updated commit message according to review.

 t/t7110-reset-merge.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
t/t7110-reset-merge.sh +6 -6
index 61669a2d21..9a335071af 100755
@@ -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 &&
Signature · 1 line
2.39.2 (Apple Git-143)
#3 lore raw

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

Quoted 10 lines · Matteo Bagnolini

From: matteobagnolini <[email protected]>

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.

Thanks, this version looks good to me.

Patrick

#4 lore raw

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

Quoted 2 lines · Patrick Steinhardt
Quoted 1 line · Matteo Bagnolini

From: matteobagnolini <[email protected]>

This must match the author ident on the Signed-off-by: line.

Quoted 4 lines
Quoted 4 lines

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.

Quoted 8 lines
Quoted 4 lines

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.

Thanks, this version looks good to me.

Patrick

Thanks for writing, and thanks for reviewing.

#5 lore raw

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

Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Patrick Steinhardt
Quoted 1 line · Matteo Bagnolini

From: matteobagnolini <[email protected]>

This must match the author ident on the Signed-off-by: line.

So should I send another patch with this correction?
Sorry for questioning, but as you might have noticed, this is my first time contributing and I'm slowly trying to learn the process.

Matteo

#6 lore raw

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

Quoted 4 lines · Matteo Bagnolini
Quoted 2 lines · Junio C Hamano

Patrick Steinhardt <[email protected]> writes:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines · Matteo Bagnolini
Quoted 1 line

From: matteobagnolini <[email protected]>

This must match the author ident on the Signed-off-by: line.

So should I send another patch with this correction?
Sorry for questioning, but as you might have noticed, this is my first time contributing and I'm slowly trying to learn the process.

Thanks for asking; if there are no other things that need fixing, I can fix up while queuing.

#7 lore raw

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

Quoted 2 lines · Junio C Hamano

Thanks for asking; if there are no other things that need fixing, I can fix up while queuing.

Yes, everything else should be OK. Thank you.

Matteo