tests: move input-tty into a test-lib.sh function
[platform/upstream/coreutils.git] / tests / misc / stty-row-col
1 #! /bin/sh
2 # Test "stty" with rows and columns.
3
4 # Copyright (C) 1998-2001, 2003-2008 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 <http://www.gnu.org/licenses/>.
18
19
20 # This script takes no arguments.
21
22 if test "$VERBOSE" = yes; then
23   set -x
24   stty --version
25 fi
26
27 # Setting this envvar to a very small value used to cause e.g., `stty size'
28 # to generate slightly different output on certain systems.
29 COLUMNS=80
30 export COLUMNS
31
32 # Make sure we get English-language behavior.
33 # See the report about a possibly-related Solaris problem by Alexandre Peshansky
34 # <http://lists.gnu.org/archive/html/bug-coreutils/2004-10/msg00035.html>.
35 # Currently stty isn't localized, but it might be in the future.
36 LC_ALL=C
37 export LC_ALL
38
39 . $srcdir/test-lib.sh
40 require_controlling_input_terminal_
41
42 # Versions of GNU stty from shellutils-1.9.2c and earlier failed
43 # tests #2 and #4 when run on SunOS 4.1.3.
44
45 tests='
46 1 rows_40_columns_80 40_80
47 2 rows_1_columns_1 1_1
48 3 rows_40_columns_80 40_80
49 4 rows_1 1_80
50 5 columns_1 1_1
51 6 rows_40 40_1
52 7 rows_1 1_1
53 8 columns_80 1_80
54 9 rows_30 30_80
55 NA LAST NA
56 '
57 set $tests
58
59 saved_size=`stty size` && test -n "$saved_size" \
60   || skip_test_ "can't get window size"
61
62 fail=0
63 while :; do
64   test_name=$1
65   args=$2
66   expected_result="`echo $3|tr _ ' '`"
67   test "$args" = empty && args=''
68   test "x$args" = xLAST && break
69   args=`echo x$args|tr _ ' '|sed 's/^x//'`
70   if test "$VERBOSE" = yes; then
71     # echo "testing \`stty $args; stty size\` = $expected_result ..."
72     echo "test $test_name... " | tr -d '\n'
73   fi
74   stty $args || exit 1
75   test x"`stty size 2> /dev/null`" = "x$expected_result" \
76     && ok=ok || ok=FAIL fail=1
77   test "$VERBOSE" = yes && echo $ok
78   shift; shift; shift
79 done
80
81 set x $saved_size
82 stty rows $2 columns $3 || exit 1
83
84 (exit $fail); exit $fail