tests: add a test for the just-fixed bug
* testsuite/read-error-stale-errno.sh: New file. * testsuite/local.mk (T): Add it.
This commit is contained in:
1 parent
a1067211a7
commit
b99731ec2c
2 files changed
+65
No files matched your search
@@ -85,6 +85,7 @@ T = \
|
||||
testsuite/posix-mode-s.sh \
|
||||
testsuite/posix-mode-N.sh \
|
||||
testsuite/range-overlap.sh \
|
||||
testsuite/read-error-stale-errno.sh \
|
||||
testsuite/recursive-escape-c.sh \
|
||||
testsuite/regex-errors.sh \
|
||||
testsuite/regex-max-int.sh \
|
||||
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/bin/sh
|
||||
# Verify ck_getdelim no longer reports a misleading strerror(errno)
|
||||
# when ferror is already set from a prior I/O operation.
|
||||
|
||||
# Copyright (C) 2026 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
. "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
|
||||
print_ver_ sed
|
||||
|
||||
# Use a FIFO with non-blocking I/O. After sed reads one line,
|
||||
# the next read(2) fails with EAGAIN (not EOF, since a writer is
|
||||
# still attached), setting ferror on the stream.
|
||||
#
|
||||
# With sed -s, test_eof's getc triggers EAGAIN, setting ferror;
|
||||
# ck_getdelim is then called with ferror already set.
|
||||
#
|
||||
# Before the fix: "sed: read error on stdin: Resource temporarily unavailable"
|
||||
# After the fix: "sed: read error on stdin"
|
||||
|
||||
mkfifo fifo || framework_failure_
|
||||
|
||||
# A writer that keeps the FIFO's write-end open.
|
||||
{ printf 'hello\n'; exec sleep 99; } > fifo &
|
||||
writer_pid=$!
|
||||
|
||||
# "dd iflag=nonblock count=0" sets O_NONBLOCK on the file description
|
||||
# underlying stdin (a no-op read that just changes the flag).
|
||||
# That flag is then inherited by sed.
|
||||
# Skip if dd doesn't support iflag=nonblock.
|
||||
(
|
||||
exec < fifo
|
||||
dd iflag=nonblock count=0 2>/dev/null || exit 77
|
||||
sed -s -n '$p'
|
||||
) 2>err
|
||||
rc=$?
|
||||
|
||||
kill $writer_pid 2>/dev/null
|
||||
wait
|
||||
|
||||
test $rc -eq 77 && skip_ "dd does not support iflag=nonblock"
|
||||
|
||||
# sed should have panicked (exit 4) due to the read error.
|
||||
test $rc -eq 4 || fail=1
|
||||
|
||||
# The error message must mention "read error" ...
|
||||
grep 'read error' err > /dev/null || fail=1
|
||||
|
||||
# ... but must NOT include a ": strerror" suffix, which would be misleading
|
||||
# (before the fix, this was e.g., ": Resource temporarily unavailable").
|
||||
grep 'read error.*: ' err && fail=1
|
||||
|
||||
Exit $fail
|
||||
Reference in new issue
Block a user