1#!/bin/sh 2# Test "stty" with rows and columns. 3 4# Copyright (C) 1998-2023 Free Software Foundation, Inc. 5 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. 10 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. 15 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/>. 18 19# Setting this envvar to a very small value used to cause e.g., 'stty size' 20# to generate slightly different output on certain systems. 21COLUMNS=80 22export COLUMNS 23 24# Make sure we get English-language behavior. 25# See the report about a possibly-related Solaris problem by Alexandre Peshansky 26# <https://lists.gnu.org/r/bug-coreutils/2004-10/msg00035.html>. 27# Currently stty isn't localized, but it might be in the future. 28LC_ALL=C 29export LC_ALL 30 31. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 32print_ver_ stty 33 34require_controlling_input_terminal_ 35require_trap_signame_ 36 37trap '' TTOU # Ignore SIGTTOU 38 39# Versions of GNU stty from shellutils-1.9.2c and earlier failed 40# tests #2 and #4 when run on SunOS 4.1.3. 41 42tests=' 431 rows_40_columns_80 40_80 442 rows_1_columns_1 1_1 453 rows_40_columns_80 40_80 464 rows_1 1_80 475 columns_1 1_1 486 rows_40 40_1 497 rows_1 1_1 508 columns_80 1_80 519 rows_30 30_80 5210 rows_0x1E 30_80 5311 rows_036 30_80 54NA LAST NA 55' 56set $tests 57 58saved_size=$(stty size) && test -n "$saved_size" \ 59 || skip_ "can't get window size" 60 61# Linux virtual consoles issue an error if you 62# try to increase their size. So skip in that case. 63if test "x$saved_size" != "x0 0"; then 64 srow=$(echo $saved_size | cut -d ' ' -f1) 65 scol=$(echo $saved_size | cut -d ' ' -f2) 66 stty rows $(expr $srow + 1) cols $(expr $scol + 1) || 67 skip_ "can't increase window size" 68fi 69 70while :; do 71 test_name=$1 72 args=$2 73 expected_result="$(echo $3|tr _ ' ')" 74 test "$args" = empty && args='' 75 test "x$args" = xLAST && break 76 args=$(echo x$args|tr _ ' '|sed 's/^x//') 77 if test "$VERBOSE" = yes; then 78 # echo "testing \$(stty $args; stty size\) = $expected_result ..." 79 echo "test $test_name... " | tr -d '\n' 80 fi 81 stty $args || exit 1 82 test x"$(stty size 2> /dev/null)" = "x$expected_result" \ 83 && ok=ok || ok=FAIL fail=1 84 test "$VERBOSE" = yes && echo $ok 85 shift; shift; shift 86done 87 88set x $saved_size 89stty rows $2 columns $3 || exit 1 90 91Exit $fail 92