From 13604c8f689d2df1030071bab4bf0b31a30fdc85 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 21 Apr 2026 08:10:07 -0700 Subject: [PATCH] tests: tolerate SELinux setfscreatecon warning on Android/Termux * init.cfg (remove_selinux_warning_): New function. * testsuite/in-place-hyphen.sh: Use it before comparing stderr. * testsuite/in-place-suffix-backup.sh: Likewise. * testsuite/panic-tests.sh: Likewise. * testsuite/temp-file-cleanup.sh: Likewise. Reported by Bruno Haible in https://lists.gnu.org/r/sed-devel/2026-04/msg00019.html --- init.cfg | 9 +++++++++ testsuite/in-place-hyphen.sh | 1 + testsuite/in-place-suffix-backup.sh | 1 + testsuite/panic-tests.sh | 1 + testsuite/temp-file-cleanup.sh | 1 + 5 files changed, 13 insertions(+) diff --git a/init.cfg b/init.cfg index de4e66a..9c8bc7d 100644 --- a/init.cfg +++ b/init.cfg @@ -187,3 +187,12 @@ or use the shortcut target of the toplevel Makefile, ' fi } + +# Remove SELinux setfscreatecon warnings from FILE(s). +# On Android/Termux, SELinux is enabled but setfscreatecon is denied, +# producing harmless warnings on stderr during in-place editing. +remove_selinux_warning_() +{ + sed -i '/warning: failed to set default file creation context/d' "$@" \ + || framework_failure_ +} diff --git a/testsuite/in-place-hyphen.sh b/testsuite/in-place-hyphen.sh index 1829176..65d4078 100755 --- a/testsuite/in-place-hyphen.sh +++ b/testsuite/in-place-hyphen.sh @@ -24,6 +24,7 @@ echo aXc > exp-out || framework_failure_ sed -i 's/b/X/' - > out 2> err || fail=1 compare exp-out ./- || fail=1 +remove_selinux_warning_ err compare /dev/null err || fail=1 Exit $fail diff --git a/testsuite/in-place-suffix-backup.sh b/testsuite/in-place-suffix-backup.sh index 206f520..6305e2f 100644 --- a/testsuite/in-place-suffix-backup.sh +++ b/testsuite/in-place-suffix-backup.sh @@ -52,6 +52,7 @@ test -e d=d || fail=1 # TODO: improve error message; # document why exit code is 4. returns_ 4 sed -i'***' = ./e 2>err-rename || fail=1 +remove_selinux_warning_ err-rename compare_ exp-err-rename err-rename || fail=1 # backup filename resolving to the same as the input filename, diff --git a/testsuite/panic-tests.sh b/testsuite/panic-tests.sh index 7c68612..59df7db 100644 --- a/testsuite/panic-tests.sh +++ b/testsuite/panic-tests.sh @@ -40,6 +40,7 @@ EOF # TODO: why exit-code 4 (currently hard-coded) returns_ 4 sed -i = a/a 2>err-temp || fail=1 +remove_selinux_warning_ err-temp # trim the filename/errno message (using sed itself...) sed -i 's/file.*$/file/' err-temp || framework_failure_ compare_ exp-err-temp err-temp || fail=1 diff --git a/testsuite/temp-file-cleanup.sh b/testsuite/temp-file-cleanup.sh index e6a0323..44f7b34 100755 --- a/testsuite/temp-file-cleanup.sh +++ b/testsuite/temp-file-cleanup.sh @@ -28,6 +28,7 @@ printf 'sed: -e expression #1, char 0: no previous regular expression\n' \ returns_ 1 sed -i s//b/ in > out 2> err || fail=1 compare /dev/null out || fail=1 +remove_selinux_warning_ err compare exp err || fail=1 # Ensure that no other file has been created in this directory.