From e28a872b3ae157cfbdb08bdf7dd6ba271a5d9b9c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?=
Date: Sat, 24 Oct 2026 14:23:35 +0100
Subject: [PATCH] tests: avoid false failure with dash
* tests/cp/link-no-deref.sh: Use printf rather than echo, as echo
unconditionally interprets backslashes in dash. Also use %q in
printf to decouple from the shell escaping implementation.
Also refactor strace usage to its own function, and avoid
a false failure in case strace didn't intercept the chown.
---
tests/cp/link-no-deref.sh | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/tests/cp/link-no-deref.sh b/tests/cp/link-no-deref.sh
index c21764355..ddb943c98 100755
--- a/tests/cp/link-no-deref.sh
+++ b/tests/cp/link-no-deref.sh
@@ -17,7 +17,7 @@
# along with this program. If not, see .
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
-print_ver_ cp
+print_ver_ cp printf
getlimits_
uses_strace_
@@ -28,17 +28,23 @@ ln -s no-such-file dangling-slink || framework_failure_
# with link being applied to the dangling symlink.
cp --link --no-dereference dangling-slink d2 || fail=1
+fail_chown() {
+ chowns=chown,lchown,fchownat
+ eval "file=\${$#}"
+ strace --quiet=all -o fc.strace -P "$file" -e inject=$chowns:error=ENOSYS "$@"
+}
+
NL='
'
-chowns=chown,lchown,fchownat
-if strace --quiet=all -o /dev/null -P foo \
- -e inject=$chowns:error=EPERM true 2>/dev/null; then
- echo "cp: failed to preserve ownership for ''\$'\\n': $ENOSYS" >exp \
- || framework_failure_
+if fail_chown true foo; then
+ env printf 'cp: %s %q: %s\n' \
+ 'failed to preserve ownership for' "$NL" "$ENOSYS" >exp &&
touch file && ln -s file slink || framework_failure_
- returns_ 1 strace --quiet=all -o /dev/null -P "$NL" \
- -e inject=$chowns:error=ENOSYS cp -P --preserve=ownership slink "$NL" \
+
+ returns_ 1 fail_chown cp -P --preserve=ownership slink "$NL" \
>out 2>err || fail=1
+
+ grep 'chown.*INJECTED' fc.strace || { cat fc.strace; framework_failure_; }
compare exp err || fail=1
compare /dev/null out || fail=1
fi