cksum: ensure appropriate "binary" mode with --untagged
[coreutils.git] / tests / head / head-write-error.sh
blobe8b154ffdc78947031622a456cbb5200c85cad88
1 #!/bin/sh
2 # Ensure we diagnose and not continue writing to
3 # the output if we get a write error.
5 # Copyright (C) 2014-2024 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
21 print_ver_ head
23 if ! test -w /dev/full || ! test -c /dev/full; then
24 skip_ '/dev/full is required'
27 # We can't use /dev/zero as that's bypassed in the --lines case
28 # due to lseek() indicating it has a size of zero.
29 yes | head -c10M > bigseek || framework_failure_
31 # This is the single output diagnostic expected,
32 # (without the possibly varying :strerror(ENOSPC) suffix).
33 printf '%s\n' "head: error writing 'standard output'" > exp
35 # Memory is bounded in these cases
36 for item in lines bytes; do
37 for N in 0 1; do
38 # pipe case
39 yes | returns_ 1 timeout 10s head --$item=-$N > /dev/full 2> errt || fail=1
40 sed 's/\(head:.*\):.*/\1/' errt > err
41 compare exp err || fail=1
43 # seekable case
44 returns_ 1 timeout 10s head --$item=-$N bigseek > /dev/full 2> errt \
45 || fail=1
46 sed 's/\(head:.*\):.*/\1/' errt > err
47 compare exp err || fail=1
48 done
49 done
51 Exit $fail