t1300: use test helpers instead of shell primitives
PATCH 1/1 t1300: use test helpers instead of shell primitives
From: Pushkar Singh <[email protected]>
Replace plain "test -f" checks with "test_path_is_file" and symbolic link checks with "test_path_is_symlink". The test framework helpers provide clearer diagnostics and better consistency across the test suite.
--- t/t1300-config.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
t/t1300-config.sh +4 -4
@@ -1232,12 +1232,12 @@ test_expect_success SYMLINKS 'symlinked configuration' ' test_when_finished "rm myconfig" && ln -s notyet myconfig && git config --file=myconfig test.frotz nitfol && - test -h myconfig && - test -f notyet && + test_path_is_symlink myconfig && + test_path_is_file notyet && test "z$(git config --file=notyet test.frotz)" = znitfol && git config --file=myconfig test.xyzzy rezrov && - test -h myconfig && - test -f notyet && + test_path_is_symlink myconfig && + test_path_is_file notyet && cat >expect <<-\EOF && nitfol rezrov
Signature · 1 line
2.43.0
Quoted 3 lines · [email protected] writes:
From: Pushkar Singh <[email protected]>
Replace plain "test -f" checks with "
test_path_is_file" and symbolic
So 'test -f' checks for regular files
Quoted 1 line
link checks with "
test_path_is_symlink". The test framework helpers
and 'test -h' check for symlinks. Would be nice to also mention the latter.
Quoted 13 lines
provide clearer diagnostics and better consistency across the test suite.
Signed-off-by Pushkar Singh <[email protected]>--- t/t1300-config.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)t/t1300-config.sh +0
-0
t/t1300-config.sh test_expect_success SYMLINKS 'symlinked configuration' ' · line 1232
Quoted 1 line
t/t1300-config.sh +0
-0@@ -1232,12 +1232,12 @@ test_expect_success SYMLINKS 'symlinked configuration' ' test_when_finished "rm myconfig" &&
Tangent: Not your patch's responsibility, but we should also remove 'notyet' :)
Quoted 16 lines
t/t1300-config.sh +4
-5ln -s notyet myconfig && git config --file=myconfig test.frotz nitfol && - test -h myconfig && - test -f notyet && + test_path_is_symlink myconfig && + test_path_is_file notyet && test "z$(git config --file=notyet test.frotz)" = znitfol && git config --file=myconfig test.xyzzy rezrov && - test -h myconfig && - test -f notyet && + test_path_is_symlink myconfig && + test_path_is_file notyet && cat >expect <<-\EOF && nitfol rezrov --
Quoted 1 line
2.43.0
The patch looks good. We have two files, one being a regular file and another being a symlink to that regular file and we simple need to ensure that they exist.
Hi Karthik,
Thank you for the review!
You’re right, I should have clarified that test -f checks for a regular file and test -h checks for a symbolic link. I’ll update the commit message accordingly and send a v2.
Thanks again!
Pushkar
Quoted 53 lines · Karthik Nayak
Quoted 3 lines · [email protected] writes:
From: Pushkar Singh <[email protected]>
Replace plain "test -f" checks with "
test_path_is_file" and symbolicSo 'test -f' checks for regular files
Quoted 1 line
link checks with "
test_path_is_symlink". The test framework helpersand 'test -h' check for symlinks. Would be nice to also mention the latter.
Quoted 13 lines
provide clearer diagnostics and better consistency across the test suite.
Signed-off-by Pushkar Singh <[email protected]>--- t/t1300-config.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)t/t1300-config.sh +0
-0t/t1300-config.sh test_expect_success SYMLINKS 'symlinked configuration' ' · line 1232
Quoted 1 line
t/t1300-config.sh +0
-0@@ -1232,12 +1232,12 @@ test_expect_success SYMLINKS 'symlinked configuration' ' test_when_finished "rm myconfig" &&Tangent: Not your patch's responsibility, but we should also remove 'notyet' :)
Quoted 16 lines
t/t1300-config.sh +4
-5ln -s notyet myconfig && git config --file=myconfig test.frotz nitfol && - test -h myconfig && - test -f notyet && + test_path_is_symlink myconfig && + test_path_is_file notyet && test "z$(git config --file=notyet test.frotz)" = znitfol && git config --file=myconfig test.xyzzy rezrov && - test -h myconfig && - test -f notyet && + test_path_is_symlink myconfig && + test_path_is_file notyet && cat >expect <<-\EOF && nitfol rezrov --Quoted 1 line
2.43.0
The patch looks good. We have two files, one being a regular file and another being a symlink to that regular file and we simple need to ensure that they exist.
Quoted 6 lines · [email protected] writes:
From: Pushkar Singh <[email protected]>
Replace plain "test -f" checks with "
test_path_is_file" and symbolic link checks with "test_path_is_symlink". The test framework helpers provide clearer diagnostics and better consistency across the test suite.
The "test" is often implemented as a built-in utility in a shell, but not necessarily so. Either way, it is not correct to call it "shell primitive", as unlike "if", "for", it is not.
PATCH v3 1/1 t1300: use test helpers instead of test builtins
In reply to [email protected]This version updates the commit message to avoid calling test a shell primitive, as suggested.
--- t/t1300-config.sh | 8 ++++---- t/t2021-checkout-overwrite.sh | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
t/t1300-config.sh +4 -4
@@ -1232,12 +1232,12 @@ test_expect_success SYMLINKS 'symlinked configuration' ' test_when_finished "rm myconfig" && ln -s notyet myconfig && git config --file=myconfig test.frotz nitfol && - test -h myconfig && - test -f notyet && + test_path_is_symlink myconfig && + test_path_is_file notyet && test "z$(git config --file=notyet test.frotz)" = znitfol && git config --file=myconfig test.xyzzy rezrov && - test -h myconfig && - test -f notyet && + test_path_is_symlink myconfig && + test_path_is_file notyet && cat >expect <<-\EOF && nitfol rezrov
t/t2021-checkout-overwrite.sh +2 -2
@@ -27,7 +27,7 @@ test_expect_success 'checkout commit with dir must not remove untracked a/b' ' git rm --cached a/b && git commit -m "un-track the file" && test_must_fail git checkout start && - test -f a/b + test_path_is_file a/b ' test_expect_success 'create a commit where dir a/b changed to symlink' '
@@ -49,7 +49,7 @@ test_expect_success 'checkout commit with dir must not remove untracked a/b' ' test_expect_success SYMLINKS 'the symlink remained' ' - test -h a/b + test_path_is_symlink a/b ' test_expect_success 'cleanup after previous symlink tests' '
Signature · 1 line
2.43.0
PATCH v3 1/1 t1300: use test helpers instead of test builtins
Quoted 5 lines
This version updates the commit message to avoid calling
testa shell primitive, as suggested.Signed-off-by Pushkar Singh <[email protected]>---
Hello Pushkar,
I think the right approach to send an updated version after modifying your commit message is to modify your commit message to INCLUDE the recommendation, not change the commit message to the recommendation alone.
Then under these three dashes after the 'Signed-off-by:', (---), which is here, where I am currently replying to you, you state what you changed in the new version compared to the previous version.
e.g
Changes in v3:
- Modified commit message to ...
- Modified subject to use builtin instead of primitive
Thanks
Abraham.
Re: [PATCH v3] t1300: use test helpers instead of test builtins
Hi Abraham,
Thanks for pointing that out.
Understood. I should keep the commit message itself focused on the change, and describe what was updated between versions under the --- section.
I will send a v4 with the commit message adjusted accordingly and include a "Changes in v4" note below the separator.
Thanks for the clarification.
Pushkar
Quoted 25 lines · Abraham Samuel Adekunle
Quoted 6 lines
This version updates the commit message to avoid calling
testa shell primitive, as suggested.Signed-off-by Pushkar Singh <[email protected]>---
Hello Pushkar,
I think the right approach to send an updated version after modifying your commit message is to modify your commit message to INCLUDE the recommendation, not change the commit message to the recommendation alone.
Then under these three dashes after the 'Signed-off-by:', (---), which is here, where I am currently replying to you, you state what you changed in the new version compared to the previous version.e.g
Changes in v3:
- Modified commit message to ...
- Modified subject to use builtin instead of primitiveThanks
Abraham.
Re: [PATCH v3] t1300: use test helpers instead of test builtins
Quoted 4 lines · Pushkar Singh
Hi Abraham,
Thanks for pointing that out.
Quoted 9 lines
Understood. I should keep the commit message itself focused on the change, and describe what was updated between versions under the
---section.I will send a v4 with the commit message adjusted accordingly and include a "Changes in v4" note below the separator.
Thanks for the clarification.
Pushkar
I also find using b4 [1] to be very beneficial to handle this. Where b4 provides patch versioning and you can simply worry about your commits :)
[1]: https://b4.docs.kernel.org/en/latest/
Quoted 27 lines
Quoted 25 lines · Abraham Samuel Adekunle
Quoted 6 lines
This version updates the commit message to avoid calling
testa shell primitive, as suggested.Signed-off-by Pushkar Singh <[email protected]>---
Hello Pushkar,
I think the right approach to send an updated version after modifying your commit message is to modify your commit message to INCLUDE the recommendation, not change the commit message to the recommendation alone.
Then under these three dashes after the 'Signed-off-by:', (---), which is here, where I am currently replying to you, you state what you changed in the new version compared to the previous version.e.g
Changes in v3:
- Modified commit message to ...
- Modified subject to use builtin instead of primitiveThanks
Abraham.
Re: [PATCH v3] t1300: use test helpers instead of test builtins
Quoted 13 lines · Karthik Nayak
Quoted 10 lines · Pushkar Singh
Hi Abraham,
Thanks for pointing that out.
Understood. I should keep the commit message itself focused on the change, and describe what was updated between versions under the
---section.I will send a v4 with the commit message adjusted accordingly and include a "Changes in v4" note below the separator.
Quoted 9 lines
Quoted 3 lines
Thanks for the clarification.
PushkarI also find using b4 [1] to be very beneficial to handle this. Where b4 provides patch versioning and you can simply worry about your commits :)
Oh thank you very much Karthik.
I will surely look into this.
Abraham.
PATCH v4 1/1 t1300: use test helpers instead of test builtins
In reply to Pushkar SinghReplace test -f and test -h checks with test_path_is_file and test_path_is_symlink. Using the test framework helpers provides clearer diagnostics and keeps tests consistent across the suite.
---
Changes in v4:
- Update commit message to avoid calling test a shell primitive
- No code changes
t/t1300-config.sh | 8 ++++---- t/t2021-checkout-overwrite.sh | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
t/t1300-config.sh +4 -4
@@ -1232,12 +1232,12 @@ test_expect_success SYMLINKS 'symlinked configuration' ' test_when_finished "rm myconfig" && ln -s notyet myconfig && git config --file=myconfig test.frotz nitfol && - test -h myconfig && - test -f notyet && + test_path_is_symlink myconfig && + test_path_is_file notyet && test "z$(git config --file=notyet test.frotz)" = znitfol && git config --file=myconfig test.xyzzy rezrov && - test -h myconfig && - test -f notyet && + test_path_is_symlink myconfig && + test_path_is_file notyet && cat >expect <<-\EOF && nitfol rezrov
t/t2021-checkout-overwrite.sh +2 -2
@@ -27,7 +27,7 @@ test_expect_success 'checkout commit with dir must not remove untracked a/b' ' git rm --cached a/b && git commit -m "un-track the file" && test_must_fail git checkout start && - test -f a/b + test_path_is_file a/b ' test_expect_success 'create a commit where dir a/b changed to symlink' '
@@ -49,7 +49,7 @@ test_expect_success 'checkout commit with dir must not remove untracked a/b' ' test_expect_success SYMLINKS 'the symlink remained' ' - test -h a/b + test_path_is_symlink a/b ' test_expect_success 'cleanup after previous symlink tests' '
Signature · 1 line
2.43.0
Re: [PATCH v4] t1300: use test helpers instead of test builtins
Quoted 5 lines · Pushkar Singh
Replace test -f and test -h checks with
test_path_is_fileandtest_path_is_symlink. Using the test framework helpers provides clearer diagnostics and keeps tests consistent across the suite.Signed-off-by Pushkar Singh <[email protected]>
This version looks good to me. Thanks.
[snip]