Git development
 help / color / mirror / Atom feed
* [PATCH] t9811: replace 'test -f' and '! test -f' with 'test_path_*'
@ 2026-07-02 14:07 Marcelo Machado Lage
  2026-07-03  8:19 ` Patrick Steinhardt
  0 siblings, 1 reply; 4+ messages in thread
From: Marcelo Machado Lage @ 2026-07-02 14:07 UTC (permalink / raw)
  To: git; +Cc: Marcelo Machado Lage, Vinicius Lira de Freitas, Junio C Hamano

Replace the basic shell commands 'test -f', with more modern test
helpers 'test_path_is_file' and 'test_path_is_missing'.

Co-authored-by: Vinicius Lira de Freitas <vinilira@usp.br>
Signed-off-by: Vinicius Lira de Freitas <vinilira@usp.br>
Signed-off-by: Marcelo Machado Lage <marcelomlage@usp.br>
---
 t/t9811-git-p4-label-import.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/t/t9811-git-p4-label-import.sh b/t/t9811-git-p4-label-import.sh
index 7614dfbd95..93d6b4c479 100755
--- a/t/t9811-git-p4-label-import.sh
+++ b/t/t9811-git-p4-label-import.sh
@@ -62,9 +62,9 @@ test_expect_success 'basic p4 labels' '
 
 		cd main &&
 		git checkout TAG_F1_ONLY &&
-		! test -f f2 &&
+		test_path_is_missing f2 &&
 		git checkout TAG_WITH\$_SHELL_CHAR &&
-		test -f f1 && test -f f2 && test -f file_with_\$metachar &&
+		test_path_is_file f1 && test_path_is_file f2 && test_path_is_file file_with_\$metachar &&
 
 		git show TAG_LONG_LABEL | grep -q "A Label second line"
 	)
@@ -102,11 +102,11 @@ test_expect_success 'two labels on the same changelist' '
 
 		git checkout TAG_F1_1 &&
 		ls &&
-		test -f f1 &&
+		test_path_is_file f1 &&
 
 		git checkout TAG_F1_2 &&
 		ls &&
-		test -f f1
+		test_path_is_file f1
 	)
 '
 
@@ -135,9 +135,9 @@ test_expect_success 'export git tags to p4' '
 		p4 labels ... | grep LIGHTWEIGHT_TAG &&
 		p4 label -o GIT_TAG_1 | grep "tag created in git:xyzzy" &&
 		p4 sync ...@GIT_TAG_1 &&
-		! test -f main/f10 &&
+		test_path_is_missing main/f10 &&
 		p4 sync ...@GIT_TAG_2 &&
-		test -f main/f10
+		test_path_is_file main/f10
 	)
 '
 
@@ -168,9 +168,9 @@ test_expect_success 'export git tags to p4 with deletion' '
 		cd "$cli" &&
 		p4 sync ... &&
 		p4 sync ...@GIT_TAG_ON_DELETED &&
-		test -f main/deleted_file &&
+		test_path_is_file main/deleted_file &&
 		p4 sync ...@GIT_TAG_AFTER_DELETION &&
-		! test -f main/deleted_file &&
+		test_path_is_missing main/deleted_file &&
 		echo "checking label contents" &&
 		p4 label -o GIT_TAG_ON_DELETED | grep "tag on deleted file"
 	)

base-commit: e9019fcafe0040228b8631c30f97ae1adb61bcdc
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] t9811: replace 'test -f' and '! test -f' with 'test_path_*'
  2026-07-02 14:07 [PATCH] t9811: replace 'test -f' and '! test -f' with 'test_path_*' Marcelo Machado Lage
@ 2026-07-03  8:19 ` Patrick Steinhardt
  2026-07-03 20:48   ` Junio C Hamano
  2026-07-06 15:00   ` Marcelo Machado Lage
  0 siblings, 2 replies; 4+ messages in thread
From: Patrick Steinhardt @ 2026-07-03  8:19 UTC (permalink / raw)
  To: Marcelo Machado Lage; +Cc: git, Vinicius Lira de Freitas, Junio C Hamano

On Thu, Jul 02, 2026 at 11:07:04AM -0300, Marcelo Machado Lage wrote:
> Replace the basic shell commands 'test -f', with more modern test
> helpers 'test_path_is_file' and 'test_path_is_missing'.

Nit: it might make sense to briefly mention why we do this exercise.
Like, what does `test_path_is_file` et al give us over `test -f`?

> diff --git a/t/t9811-git-p4-label-import.sh b/t/t9811-git-p4-label-import.sh
> index 7614dfbd95..93d6b4c479 100755
> --- a/t/t9811-git-p4-label-import.sh
> +++ b/t/t9811-git-p4-label-import.sh
> @@ -62,9 +62,9 @@ test_expect_success 'basic p4 labels' '
>  
>  		cd main &&
>  		git checkout TAG_F1_ONLY &&
> -		! test -f f2 &&
> +		test_path_is_missing f2 &&
>  		git checkout TAG_WITH\$_SHELL_CHAR &&
> -		test -f f1 && test -f f2 && test -f file_with_\$metachar &&
> +		test_path_is_file f1 && test_path_is_file f2 && test_path_is_file file_with_\$metachar &&

While at it we could split this line into three lines -- it's getting
overly long, and we typically don't chain multiple commands on one line
nowadays.

> @@ -135,9 +135,9 @@ test_expect_success 'export git tags to p4' '
>  		p4 labels ... | grep LIGHTWEIGHT_TAG &&
>  		p4 label -o GIT_TAG_1 | grep "tag created in git:xyzzy" &&
>  		p4 sync ...@GIT_TAG_1 &&
> -		! test -f main/f10 &&
> +		test_path_is_missing main/f10 &&

This is a stronger guarantee compared to before, as we only checked
whether the path is not a file. Now we verify that it doesn't exist at
all, which would be equivalent to `test -e`. That's a strict improvement
though, but may be worth pointing out in the commit message so that the
reviewer is not surprised.

> @@ -168,9 +168,9 @@ test_expect_success 'export git tags to p4 with deletion' '
>  		cd "$cli" &&
>  		p4 sync ... &&
>  		p4 sync ...@GIT_TAG_ON_DELETED &&
> -		test -f main/deleted_file &&
> +		test_path_is_file main/deleted_file &&
>  		p4 sync ...@GIT_TAG_AFTER_DELETION &&
> -		! test -f main/deleted_file &&
> +		test_path_is_missing main/deleted_file &&

Same here.

Other than that the patch looks good to me, thanks!

Patrick

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] t9811: replace 'test -f' and '! test -f' with 'test_path_*'
  2026-07-03  8:19 ` Patrick Steinhardt
@ 2026-07-03 20:48   ` Junio C Hamano
  2026-07-06 15:00   ` Marcelo Machado Lage
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2026-07-03 20:48 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: Marcelo Machado Lage, git, Vinicius Lira de Freitas

Patrick Steinhardt <ps@pks.im> writes:

>> -		test -f f1 && test -f f2 && test -f file_with_\$metachar &&
>> +		test_path_is_file f1 && test_path_is_file f2 && test_path_is_file file_with_\$metachar &&
>
> While at it we could split this line into three lines -- it's getting
> overly long, and we typically don't chain multiple commands on one line
> nowadays.

Excellent.

>> -		! test -f main/f10 &&
>> +		test_path_is_missing main/f10 &&
>
> This is a stronger guarantee compared to before, as we only checked
> whether the path is not a file. Now we verify that it doesn't exist at
> all, which would be equivalent to `test -e`. That's a strict improvement
> though, but may be worth pointing out in the commit message so that the
> reviewer is not surprised.

Good.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] t9811: replace 'test -f' and '! test -f' with 'test_path_*'
  2026-07-03  8:19 ` Patrick Steinhardt
  2026-07-03 20:48   ` Junio C Hamano
@ 2026-07-06 15:00   ` Marcelo Machado Lage
  1 sibling, 0 replies; 4+ messages in thread
From: Marcelo Machado Lage @ 2026-07-06 15:00 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: git, Vinicius Lira de Freitas, Junio C Hamano

Em sex., 3 de jul. de 2026 às 05:20, Patrick Steinhardt <ps@pks.im> escreveu:
>
> On Thu, Jul 02, 2026 at 11:07:04AM -0300, Marcelo Machado Lage wrote:
> > Replace the basic shell commands 'test -f', with more modern test
> > helpers 'test_path_is_file' and 'test_path_is_missing'.
>
> Nit: it might make sense to briefly mention why we do this exercise.
> Like, what does `test_path_is_file` et al give us over `test -f`?

We'll add this in v2.

>
> > diff --git a/t/t9811-git-p4-label-import.sh b/t/t9811-git-p4-label-import.sh
> > index 7614dfbd95..93d6b4c479 100755
> > --- a/t/t9811-git-p4-label-import.sh
> > +++ b/t/t9811-git-p4-label-import.sh
> > @@ -62,9 +62,9 @@ test_expect_success 'basic p4 labels' '
> >
> >               cd main &&
> >               git checkout TAG_F1_ONLY &&
> > -             ! test -f f2 &&
> > +             test_path_is_missing f2 &&
> >               git checkout TAG_WITH\$_SHELL_CHAR &&
> > -             test -f f1 && test -f f2 && test -f file_with_\$metachar &&
> > +             test_path_is_file f1 && test_path_is_file f2 && test_path_is_file file_with_\$metachar &&
>
> While at it we could split this line into three lines -- it's getting
> overly long, and we typically don't chain multiple commands on one line
> nowadays.

We'll do this for v2 as well and make it into a patch series to
separate test interface modernization from formatting changes.

While on this, there are some other places in the file where multiple
commands in a && chain appear in a single line, e.g. in line 244:
> p4 edit f2 && date >f2 && p4 submit -d "change" f2 &&
Should we split these into multiple lines as well, even though they
are under the 80 characters limit?

>
> > @@ -135,9 +135,9 @@ test_expect_success 'export git tags to p4' '
> >               p4 labels ... | grep LIGHTWEIGHT_TAG &&
> >               p4 label -o GIT_TAG_1 | grep "tag created in git:xyzzy" &&
> >               p4 sync ...@GIT_TAG_1 &&
> > -             ! test -f main/f10 &&
> > +             test_path_is_missing main/f10 &&
>
> This is a stronger guarantee compared to before, as we only checked
> whether the path is not a file. Now we verify that it doesn't exist at
> all, which would be equivalent to `test -e`. That's a strict improvement
> though, but may be worth pointing out in the commit message so that the
> reviewer is not surprised.

We overlooked this improvement at first, but we'll add a proper note
about it in v2.

>
> > @@ -168,9 +168,9 @@ test_expect_success 'export git tags to p4 with deletion' '
> >               cd "$cli" &&
> >               p4 sync ... &&
> >               p4 sync ...@GIT_TAG_ON_DELETED &&
> > -             test -f main/deleted_file &&
> > +             test_path_is_file main/deleted_file &&
> >               p4 sync ...@GIT_TAG_AFTER_DELETION &&
> > -             ! test -f main/deleted_file &&
> > +             test_path_is_missing main/deleted_file &&
>
> Same here.
>
> Other than that the patch looks good to me, thanks!

Thanks for the detailed feedback, Patrick!

Best,
Marcelo

>
> Patrick

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-06 15:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-02 14:07 [PATCH] t9811: replace 'test -f' and '! test -f' with 'test_path_*' Marcelo Machado Lage
2026-07-03  8:19 ` Patrick Steinhardt
2026-07-03 20:48   ` Junio C Hamano
2026-07-06 15:00   ` Marcelo Machado Lage

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox