test: switch to POSIX compliance symlink check
PATCH 1/1 test: switch to POSIX compliance symlink check
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
--- 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(-)
t/t9131-git-svn-empty-symlink.sh +2 -2
@@ -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
t/t9132-git-svn-broken-symlink.sh +2 -2
@@ -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)") '
t/t9802-git-p4-filetype.sh +1 -1
@@ -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 ) '
t/t9830-git-p4-symlink-dir.sh +1 -1
@@ -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 )
Signature · 1 line
2.24.1.485.gad05a3d8e5
Quoted 3 lines · Doan Tran Cong Danh
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
Quoted 3 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
Quoted 9 lines · Carlo Arenas
Quoted 3 lines · Doan Tran Cong Danh
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.
Quoted 20 lines
Quoted 4 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.plor something like that IMHOCarlo
Signature · 1 line
Danh