tests: avoid triggering obsolete tail option processing
[coreutils.git] / tests / stty / stty.sh
blobcd28e8bf30fb457f93b1d8ad2ff4ffc85d6ae74e
1 #!/bin/sh
2 # Make sure stty can parse most of its options.
4 # Copyright (C) 1998-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 # Make sure there's a tty on stdin.
20 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
21 print_ver_ stty
23 require_controlling_input_terminal_
24 require_trap_signame_
25 require_strace_ ioctl
27 trap '' TTOU # Ignore SIGTTOU
29 # Get the reversible settings from stty.c.
30 stty_reversible_init_
32 saved_state=.saved-state
33 stty --save > $saved_state || fail=1
34 stty $(cat $saved_state) || fail=1
36 # This would segfault prior to sh-utils-2.0j.
37 stty erase - || fail=1
39 # Ensure "immediate" and "wait" mode supported, with and without settings
40 for mode in '-drain' 'drain'; do
41 for opt in 'echo' ''; do
42 stty "$mode" $opt || fail=1
43 done
44 done
46 # These would improperly ignore invalid options through coreutils 5.2.1.
47 returns_ 1 stty -F 2>/dev/null || fail=1
48 returns_ 1 stty -raw -F no/such/file 2>/dev/null || fail=1
49 returns_ 1 stty -raw -a 2>/dev/null || fail=1
51 # Build a list of all boolean options stty accepts on this system.
52 # Don't depend on terminal width. Put each option on its own line,
53 # remove all non-boolean ones, then remove any leading hyphens.
54 sed_del='/^speed/d;/^rows/d;/^columns/d;/ = /d'
55 options=$(stty -a | tr -s ';' '\n' | sed "s/^ //;$sed_del;s/-//g")
57 # Take them one at a time, with and without the leading '-'.
58 for opt in $options; do
59 # 'stty parenb' and 'stty -parenb' fail with this message
60 # stty: standard input: unable to perform all requested operations
61 # on Linux 2.2.0-pre4 kernels. Also since around Linux 2.6.30
62 # other serial control settings give the same error. So skip them.
63 # Also on ppc*|sparc* glibc platforms 'icanon' gives the same error.
64 # See: https://bugs.gnu.org/7228#14
65 case $opt in
66 parenb|parodd|cmspar) continue;;
67 cstopb|crtscts|cdtrdsr|icanon) continue;;
68 esac
70 # This is listed as supported on FreeBSD
71 # but the ioctl returns ENOTTY.
72 test $opt = extproc && continue
74 stty $opt || fail=1
76 # Likewise, 'stty -cread' would fail, so skip that, too.
77 test $opt = cread && continue
78 if stty_reversible_query_ "$opt" ; then
79 stty -$opt || { fail=1; echo -$opt; }
81 done
83 stty $(cat $saved_state)
85 # Ensure we validate options before accessing the device
86 strace -o log1 -e ioctl stty --version || fail=1
87 n_ioctl1=$(wc -l < log1) || framework_failure_
88 returns_ 1 strace -o log2 -e ioctl stty -blahblah || fail=1
89 n_ioctl2=$(wc -l < log2) || framework_failure_
90 test "$n_ioctl1" = "$n_ioctl2" || fail=1
92 # Ensure we wrap output appropriately
93 for W in $(seq 80 90); do
94 output_width=$(COLUMNS="$W" stty -a | wc -L)
95 test "$output_width" -le "$W" || fail=1
96 done
98 Exit $fail