mirror of
https://github.com/coreutils/coreutils.git
synced 2026-10-28 09:44:34 +08:00
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.
This commit is contained in:
1 parent
499a55e03d
commit
e28a872b3a
1 file changed
+14
-8
@@ -17,7 +17,7 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
. "${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
|
||||
|
||||
Reference in new issue
Block a user