threads / patch / 52502

patchtest: switch to POSIX compliance symlink check

Subject: [PATCH] test: switch to POSIX compliance symlink check

## tl;dr

3 messages between Dec 21, 2019 and Dec 22, 2019. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Doan Tran Cong Danh· Dec 21, 2019, 16:40 UTC · lore

POSIX doesn't specify `-L' flag for test(1), POSIX specify `-h' for checking symlink instead.

While most shells and test(1) implementation provides both `-L' and `-h' for checking symlink, OpenBSD and NetBSD says we shouldn't rely on its existence. [1]

Replace all usages of `test -L' with `test -h'.
[1]: https://man.openbsd.org/test.1
Signed-off-by: Doan Tran Cong Danh <congdanhqx@gmail.com>
---
 t/t9131-git-svn-empty-symlink.sh  | 4 ++--
 t/t9132-git-svn-broken-symlink.sh | 4 ++--
 t/t9802-git-p4-filetype.sh        | 2 +-
 t/t9830-git-p4-symlink-dir.sh     | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
Show changes to 4 files +6 −6

t/t9131-git-svn-empty-symlink.sh, t/t9132-git-svn-broken-symlink.sh, t/t9802-git-p4-filetype.sh, t/t9830-git-p4-symlink-dir.sh

diff --git a/t/t9131-git-svn-empty-symlink.sh b/t/t9131-git-svn-empty-symlink.sh
index 3bf4255aa3..6812028258 100755
--- a/t/t9131-git-svn-empty-symlink.sh
+++ b/t/t9131-git-svn-empty-symlink.sh
@@ -97,14 +97,14 @@ test_expect_success 'disable broken symlink workaround' \
 test_expect_success '"bar" is an empty file' 'test_must_be_empty y/bar'
 test_expect_success 'get "bar" => symlink fix from svn' \
 		'(cd y && git svn rebase)'
-test_expect_success '"bar" does not become a symlink' '! test -L y/bar'
+test_expect_success '"bar" does not become a symlink' '! test -h y/bar'
 
 # svn.brokenSymlinkWorkaround is unset
 test_expect_success 'clone using git svn' 'git svn clone -r1 "$svnrepo" z'
 test_expect_success '"bar" is an empty file' 'test_must_be_empty z/bar'
 test_expect_success 'get "bar" => symlink fix from svn' \
 		'(cd z && git svn rebase)'
-test_expect_success '"bar" does not become a symlink' '! test -L z/bar'
+test_expect_success '"bar" does not become a symlink' '! test -h z/bar'
 
 
 test_done
diff --git a/t/t9132-git-svn-broken-symlink.sh b/t/t9132-git-svn-broken-symlink.sh
index aeceffaf7b..2b15b97cdf 100755
--- a/t/t9132-git-svn-broken-symlink.sh
+++ b/t/t9132-git-svn-broken-symlink.sh
@@ -86,7 +86,7 @@ EOF
 test_expect_success 'clone using git svn' 'git svn clone -r1 "$svnrepo" x'
 
 test_expect_success SYMLINKS '"bar" is a symlink that points to "asdf"' '
-	test -L x/bar &&
+	test -h x/bar &&
 	(cd x && test xasdf = x"$(git cat-file blob HEAD:bar)")
 '
 
@@ -95,7 +95,7 @@ test_expect_success 'get "bar" => symlink fix from svn' '
 '
 
 test_expect_success SYMLINKS '"bar" remains a proper symlink' '
-	test -L x/bar &&
+	test -h x/bar &&
 	(cd x && test xdoink = x"$(git cat-file blob HEAD:bar)")
 '
 
diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh
index 94edebe272..197752b45a 100755
--- a/t/t9802-git-p4-filetype.sh
+++ b/t/t9802-git-p4-filetype.sh
@@ -262,7 +262,7 @@ test_expect_success SYMLINKS 'ensure p4 symlink parsed correctly' '
 	git p4 clone --dest="$git" //depot@all &&
 	(
 		cd "$git" &&
-		test -L symlink &&
+		test -h symlink &&
 		test $(readlink symlink) = symlink-target
 	)
 '
diff --git a/t/t9830-git-p4-symlink-dir.sh b/t/t9830-git-p4-symlink-dir.sh
index 3fb6960c18..4b4cc015fc 100755
--- a/t/t9830-git-p4-symlink-dir.sh
+++ b/t/t9830-git-p4-symlink-dir.sh
@@ -30,7 +30,7 @@ test_expect_success 'symlinked directory' '
 	(
 		cd "$cli" &&
 		p4 sync &&
-		test -L some/sub/directory/subdir2 &&
+		test -h some/sub/directory/subdir2 &&
 		test_path_is_file some/sub/directory/subdir2/file.t
 	)
 
-- 
2.24.1.485.gad05a3d8e5
Carlo Arenas· Dec 21, 2019, 20:45 UTC · re: Doan Tran Cong Danh · lore

Re: [PATCH] test: switch to POSIX compliance symlink check

On Sat, Dec 21, 2019 at 8:50 AM Doan Tran Cong Danh <congdanhqx@gmail.com> wrote:

>
> POSIX doesn't specify `-L' flag for test(1), POSIX specify `-h' for
> checking symlink instead.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
seems to indicate both are valid and equivalent
> While most shells and test(1) implementation provides both `-L' and
> `-h' for checking symlink,
> OpenBSD and NetBSD says we shouldn't rely on its existence. [1]
and macOS (from FreeBSD[1]) says the exact opposite :
     -h file     True if file exists and is a symbolic link.  This operator
                   is retained for compatibility with previous versions of
                   this program.  Do not rely on its existence; use -L
                   instead.

agree it would be a good idea to use only one for consistency though, but it might be in that case a good idea to add it as a "recommendation" by adding this rule in t/check-non-portable-shell.pl or something like that IMHO

Carlo
[1] https://www.freebsd.org/cgi/man.cgi?test
Danh Doan· Dec 22, 2019, 02:07 UTC · re: Carlo Arenas · lore

Re: [PATCH] test: switch to POSIX compliance symlink check

On 2019-12-21 12:45:43-0800, Carlo Arenas <carenas@gmail.com> wrote:
Show 9 quoted lines
> On Sat, Dec 21, 2019 at 8:50 AM Doan Tran Cong Danh
> <congdanhqx@gmail.com> wrote:
> >
> > POSIX doesn't specify `-L' flag for test(1), POSIX specify `-h' for
> > checking symlink instead.
> 
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
> 
> seems to indicate both are valid and equivalent

It's seems like I've misread my manpages. Somehow, I couldn't find the mention of `-L' when I tried it last time. Please ignore this patch.

Show 20 quoted lines
> 
> > While most shells and test(1) implementation provides both `-L' and
> > `-h' for checking symlink,
> > OpenBSD and NetBSD says we shouldn't rely on its existence. [1]
> 
> and macOS (from FreeBSD[1]) says the exact opposite :
> 
>      -h file     True if file exists and is a symbolic link.  This operator
>                    is retained for compatibility with previous versions of
>                    this program.  Do not rely on its existence; use -L
>                    instead.
> 
> agree it would be a good idea to use only one for consistency though,
> but it might be in that case a good idea to add it as a
> "recommendation" by adding this rule in t/check-non-portable-shell.pl
> or something like that IMHO
> 
> Carlo
> 
> [1] https://www.freebsd.org/cgi/man.cgi?test
-- 
Danh

← back to recent threads