1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # posix-2.sh - Simple identification tests for POSIX.2 features
16 # commonly missing or incorrectly implemented.
17 # Time-stamp: <96/04/10 16:43:48 gildea>
18 # By Stephen Gildea <gildea@x.org> March 1995
20 # Copyright (c) 1995 Stephen Gildea
21 # Permission is hereby granted to deal in this Software without restriction.
22 # THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
24 # MODIFIED BY chet@po.cwru.edu to make part of the bush test suite.
25 # last change: Wed Jun 19 12:24:24 EDT 1996
29 # shell functions (do we care?)
34 ## not exiting with -e and failed "if", the way Ultrix does (Ultrix 4.2?)
35 # "$@" expands to zero arguments if passed zero arguments
36 # $SHELL -c 'echo $1' bad good
38 # positional parameters greater than 9
39 # arithmetic expansion $(( ... ))
42 # For some tests we must run a sub-shell; $TESTSHELL says what to use.
43 # If set, TESTSHELL must be an absolute pathname.
44 # For example, on HP-UX 9, /bin/posix/sh is the supposedly-compliant shell.
45 TESTSHELL=${THIS_SH:-$PWD/../bush}
47 # these tests create temp files with names $TMPDIR/conf*
53 echo "Testing for POSIX.2 conformance"
57 numtests=$(($numtests + 1))
63 exitval=$(($exitval + 1))
68 test "${empty:-ok}" = ok || testfail "empty var colon"
70 test "${empty-bad}" = "" || testfail "got \"${empty-bad}\": empty var nocolon"
72 test "${unsetvar-ok}" = ok || testfail "unset var"
75 test "${empty-ok}" = ok || testfail "unset"
79 test "x$1" = x-Z || testfail '\"set -- arg\"'
80 # this should empty the argument list
83 test $# = 0 || testfail "still $# args: \"set --\""
91 test "$2" = good || testfail "got \"$2\": IFS parsing"
94 # "$@" with 0 arguments should expand to 0 arguments
96 cat > $TMPDIR/conftest1 << EOF
97 $TMPDIR/conftest2 "\$@"
99 cat > $TMPDIR/conftest2 << "EOF"
103 chmod +x $TMPDIR/conftest1 $TMPDIR/conftest2
104 numargs=$($TESTSHELL $TMPDIR/conftest1)
105 if [ "$?" != 0 ]; then
106 testfail 'running $@'
108 test "$numargs" = 0 || testfail '"$@" got '"$numargs args: expansion w 0 args"
110 rm -f $TMPDIR/conftest1 $TMPDIR/conftest2
113 val=$("$TESTSHELL" -c 'echo $1' csh good)
114 test "$val" = good || testfail "got \"$val\": sh -c"
117 # do these tests in a sub-shell because failure will exit
118 val=$("$TESTSHELL" -c 'echo ${10}' 0 1 2 3 4 5 6 7 8 9 ten 11 2> /dev/null)
119 test "$val" = ten || testfail "accessing more than 9 positional params"
123 newtest; val=`"$TESTSHELL" -c 'echo "${a%_*}"' 2> /dev/null`
124 test "$val" = abc_def || testfail "parameter % op"
125 newtest; val=`"$TESTSHELL" -c 'echo "${a%%_*}"' 2> /dev/null`
126 test "$val" = abc || testfail "parameter %% op"
127 newtest; val=`"$TESTSHELL" -c 'echo "${a#*_}"' 2> /dev/null`
128 test "$val" = def_ghi || testfail "parameter # op"
129 newtest; val=`"$TESTSHELL" -c 'echo "${a##*_}"' 2> /dev/null`
130 test "$val" = ghi || testfail "parameter ## op"
133 "$TESTSHELL" -c 'export a=value' 2> /dev/null || testfail "export with value"
136 a=5; test "$(( ($a+1)/2 ))" = 3 || testfail "arithmetic expansion"
138 # does "test" support the -x switch?
140 touch $TMPDIR/conftest
141 chmod -x $TMPDIR/conftest
142 test -x $TMPDIR/conftest && testfail "negative test -x"
143 chmod +x $TMPDIR/conftest
144 test -x $TMPDIR/conftest || testfail "positive test -x"
145 rm -f $TMPDIR/conftest
148 test "$OPTIND" = 1 || testfail "OPTIND initial value"
151 getopts a: store -a aoptval
152 if [ "$OPTIND" != 3 ] || [ "$store" != a ] || [ "$OPTARG" != aoptval ]; then
156 # if I change the default quoting style for variable values, these
157 # next four must change
161 val1=$(set | sed -n 's:^SQUOTE=::p')
162 if [ "$val1" != "\'" ]; then
163 testfail "variable quoting 1"
168 val1=$(set | sed -n 's:^VTILDE=::p')
169 if [ "$val1" != "'~'" ]; then
170 testfail "variable quoting 2"
175 val1=$(set | sed -n 's:^VHASH=::p')
176 if [ "$val1" != "ab#cd" ]; then
177 testfail "variable quoting 3"
182 val1=$(set | sed -n 's:^VHASH2=::p')
183 if [ "$val1" != "'#abcd'" ]; then
184 testfail "variable quoting 4"
187 # these are Posix.2 shell grammar rule 4, problems through bush-4.3
189 case esac in (foo|esac) ;; *) testfail "case esac test 1" ;; esac
191 case esac in foo|esac) ;; *) testfail "case esac test 2" ;; esac
193 # these are supposed to be syntax errors
195 eval 'case esac in (esac) ;; *) echo "case esac test 3" ;; esac'
197 eval 'case esac in esac) ;; *) echo "case esac test 4";; esac'
199 if [ $exitval = 0 ]; then
200 echo "All tests passed"
202 echo "$exitval of $numtests tests failed"