On 17/09/2025 14:31, Pádraig Brady wrote:
This was noticed with:

   trap '' PIPE &&  # Ignore SIGPIPE
   make check TESTS=tests/fold/fold-characters.sh SUBDIRS=.

* tests/fold/fold-characters.sh: Don't check for no error message,
as in the case SIGPIPE is ignored, then a "write error" message
will appear on stderr.  Also protect the fold invocation with a
timeout(1) so that fold implementations that don't exit promptly
upon write error don't hang the test suite (Like we would have
done before commit v9.7-311-gc95c7ee76). Note the closed pipe
is implemented within the timeout (SHELL) command, as doing
`source | timeout | :` would hide the error exit upon timeout.
Note we could have wrapped the invocation with eithier with
`env --default-signal=PIPE`, but that's overkill here.
---
  tests/fold/fold-characters.sh | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/fold/fold-characters.sh b/tests/fold/fold-characters.sh
index c29b4bdd6..850663885 100755
--- a/tests/fold/fold-characters.sh
+++ b/tests/fold/fold-characters.sh
@@ -93,8 +93,8 @@ test $(env printf '\xC3' | fold | wc -c) = 1 || fail=1
# Ensure bounded memory operation
  vm=$(get_min_ulimit_v_ fold /dev/null) && {
-  yes | tr -d '\n' | (ulimit -v $(($vm+8000)) && fold 2>err) | head || fail=1
-  compare /dev/null err || fail=1
+  yes | tr -d '\n' | timeout -v 10 $SHELL -c \
+   "(ulimit -v $(($vm+8000)) && fold) | :" || fail=1
  }
Exit $fail

Acutally that's not quite right as it won't fail
if fold uses too much mem, as the | : hides the error.
So let's simplify all this and just use the existing framework in 
write-errors.sh
now that fold uses bounded memory and diagnoses write errors.
I.e.

diff --git a/tests/fold/fold-characters.sh b/tests/fold/fold-characters.sh
index 850663885..8be54061b 100755
--- a/tests/fold/fold-characters.sh
+++ b/tests/fold/fold-characters.sh
@@ -91,10 +91,4 @@ test $({ bad_unicode | fold; bad_unicode; } | uniq | wc -l) 
= 1 || fail=1
 # Check bad character at EOF
 test $(env printf '\xC3' | fold | wc -c) = 1 || fail=1

-# Ensure bounded memory operation
-vm=$(get_min_ulimit_v_ fold /dev/null) && {
-  yes | tr -d '\n' | timeout -v 10 $SHELL -c \
-   "(ulimit -v $(($vm+8000)) && fold) | :" || fail=1
-}
-
 Exit $fail
diff --git a/tests/misc/write-errors.sh b/tests/misc/write-errors.sh
index 5bc381f5f..34bed5dfc 100755
--- a/tests/misc/write-errors.sh
+++ b/tests/misc/write-errors.sh
@@ -37,6 +37,7 @@ factor --version; yes 1 | factor
 fold /dev/zero
 fold -b /dev/zero
 fold -c /dev/zero
+fold --version; yes | tr -d '\\n' | fold
 head -z -n-1 /dev/zero
 join -a 1 -z /dev/zero /dev/null
 # TODO: nl --version; yes | nl


Reply via email to