t: use portable wrapper for readlink(1)

Not all systems have a readlink program available for use by the shell. This causes t3210 to fail on at least AIX. Let's provide a perl one-liner to do the same thing, and use it there. I also updated calls in t9802. Nobody reported failure there, but it's the same issue. Presumably nobody actually tests with p4 on AIX in the first place (if it is even available there). I left the use of readlink in the "--valgrind" setup in test-lib.sh, as valgrind isn't available on exotic platforms anyway (and I didn't want to increase dependencies between test-lib.sh and test-lib-functions.sh). There's one other curious case. Commit d2addc3b96 (t7800: readlink may not be available, 2016-05-31) fixed a similar case. We can't use our wrapper function there, though, as it's inside a sub-script triggered by Git. It uses a slightly different technique ("ls" piped to "sed"). I chose not to use that here as it gives confusing "ls -l" output if the file is unexpectedly not a symlink (which is OK for its limited use, but potentially confusing for general use within the test suite). The perl version emits the empty string. Reported-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 18, 2021 at 12:32 UTC 7c0afdf23c1cb331eab0068d70ad5c0c156f216a
3 files changed +9 -3
t/t3210-pack-refs.sh
+1 -1
@@ -253,7 +253,7 @@ test_expect_success SYMLINKS 'pack symlinked packed-refs' '
253 git for-each-ref >all-refs-packed &&
254 test_cmp all-refs-before all-refs-packed &&
255 test -h .git/packed-refs &&
256 - test "$(readlink .git/packed-refs)" = "my-deviant-packed-refs"
256 + test "$(test_readlink .git/packed-refs)" = "my-deviant-packed-refs"
257 '
258
259 test_done
t/t9802-git-p4-filetype.sh
+2 -2
@@ -263,7 +263,7 @@ test_expect_success SYMLINKS 'ensure p4 symlink parsed correctly' '
263 (
264 cd "$git" &&
265 test -L symlink &&
266 - test $(readlink symlink) = symlink-target
266 + test $(test_readlink symlink) = symlink-target
267 )
268 '
269
@@ -329,7 +329,7 @@ test_expect_success SYMLINKS 'empty symlink target' '
329 git p4 clone --dest="$git" //depot@all &&
330 (
331 cd "$git" &&
332 - test $(readlink empty-symlink) = target2
332 + test $(test_readlink empty-symlink) = target2
333 )
334 '
335
t/test-lib-functions.sh
+6
@@ -1692,3 +1692,9 @@ test_region () {
1692
1693 return 0
1694 }
1695 +
1696 +# Print the destination of symlink(s) provided as arguments. Basically
1697 +# the same as the readlink command, but it's not available everywhere.
1698 +test_readlink () {
1699 + perl -le 'print readlink($_) for @ARGV' "$@"
1700 +}