tests: ensure utils support writing to a closed pipe
[coreutils.git] / tests / misc / write-errors.sh
blob0ead519d6587957258be375c4deda2c46b1adafa
1 #!/bin/sh
2 # Make sure all of these programs promptly diagnose write errors.
4 # Copyright (C) 2023-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ timeout
22 if ! test -w /dev/full || ! test -c /dev/full; then
23 skip_ '/dev/full is required'
26 # Writers that may output data indefinitely
27 # First word in command line is checked against built programs
28 echo "\
29 cat /dev/zero
30 comm -z /dev/zero /dev/zero
31 cut -z -c1- /dev/zero
32 cut -z -f1- /dev/zero
33 dd if=/dev/zero
34 expand /dev/zero
35 factor --version; yes 1 | factor
36 # TODO: fmt /dev/zero
37 # TODO: fold -b /dev/zero
38 head -z -n-1 /dev/zero
39 join -a 1 -z /dev/zero /dev/null
40 # TODO: nl --version; yes | nl
41 # TODO: numfmt --version; yes 1 | numfmt
42 od -v /dev/zero
43 paste /dev/zero
44 # TODO: pr /dev/zero
45 seq inf
46 tail -n+1 -z /dev/zero
47 tee < /dev/zero
48 tr . . < /dev/zero
49 unexpand /dev/zero
50 uniq -z -D /dev/zero
51 yes
52 " |
53 sort -k 1b,1 > all_writers || framework_failure_
55 printf '%s\n' $built_programs |
56 sort -k 1b,1 > built_programs || framework_failure_
58 join all_writers built_programs > built_writers || framework_failure_
60 while read writer; do
61 timeout 10 $SHELL -c "$writer > /dev/full"
62 test $? = 124 && { fail=1; echo "$writer: failed to exit" >&2; }
64 rm -f pipe.err || framework_failure_
65 timeout 10 $SHELL -c "$writer 2>pipe.err | :"
66 { test $? = 0 && compare /dev/null pipe.err; } ||
67 { fail=1; cat pipe.err; echo "$writer: failed to write to closed pipe" >&2; }
68 done < built_writers
70 Exit $fail