yes: avoid redundant diagnostics on write error
[coreutils.git] / tests / misc / yes.sh
bloba3027432bd5abd6fbeafe0bf6b40cc30035d26b2
1 #!/bin/sh
2 # Validate yes buffer handling
4 # Copyright (C) 2015-2016 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 <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ yes
22 # Check various single item sizes, with the most important
23 # size being BUFSIZ used for the local buffer to yes(1).
24 # Note a \n is added, so actual sizes required internally
25 # are 1 more than the size used here.
26 for size in 1 1999 4095 4096 8191 8192 16383 16384; do
27 printf "%${size}s\n" '' > out.1
28 yes "$(printf %${size}s '')" | head -n2 | uniq > out.2
29 compare out.1 out.2 || fail=1
30 done
32 # Check the many small items case,
33 # both fitting and overflowing the internal buffer.
34 # First check that 4000 arguments supported.
35 if test 4000 -eq $(sh -c 'echo $#' 0 $(seq 4000)); then
36 for i in 100 4000; do
37 seq $i | paste -s -d ' ' | sed p > out.1
38 yes $(seq $i) | head -n2 > out.2
39 compare out.1 out.2 || fail=1
40 done
43 # Check a single appropriate diagnostic is output on write error
44 if test -w /dev/full && test -c /dev/full; then
45 # The single output diagnostic expected,
46 # (without the possibly varying :strerror(ENOSPC) suffix).
47 printf '%s\n' "yes: standard output" > exp
49 for size in 1 16384; do
50 returns_ 1 yes "$(printf %${size}s '')" >/dev/full 2>errt
51 sed 's/\(yes:.*\):.*/\1/' errt > err
52 compare exp err || fail=1
53 done
56 Exit $fail