]>
git.ipfire.org Git - thirdparty/bash.git/blob - tests/posix2.tests
21613790c27e788ca46153e3456ee91f654da39c
2 # posix-2.sh - Simple identification tests for POSIX.2 features
3 # commonly missing or incorrectly implemented.
4 # Time-stamp: <96/04/10 16:43:48 gildea>
5 # By Stephen Gildea <gildea@x.org> March 1995
7 # Copyright (c) 1995 Stephen Gildea
8 # Permission is hereby granted to deal in this Software without restriction.
9 # THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
11 # MODIFIED BY chet@po.cwru.edu to make part of the bash test suite.
12 # last change: Wed Jun 19 12:24:24 EDT 1996
16 # shell functions (do we care?)
21 ## not exiting with -e and failed "if", the way Ultrix does (Ultrix 4.2?)
22 # "$@" expands to zero arguments if passed zero arguments
23 # $SHELL -c 'echo $1' bad good
25 # positional parameters greater than 9
26 # arithmetic expansion $(( ... ))
29 # For some tests we must run a sub-shell; $TESTSHELL says what to use.
30 # If set, TESTSHELL must be an absolute pathname.
31 # For example, on HP-UX 9, /bin/posix/sh is the supposedly-compliant shell.
32 TESTSHELL
=${THIS_SH:-$PWD/../bash}
34 # these tests create temp files with names $TMPDIR/conf*
40 echo "Testing for POSIX.2 conformance"
44 numtests
=$
(($numtests + 1))
50 exitval
=$
(($exitval + 1))
55 test "${empty:-ok}" = ok || testfail
"empty var colon"
57 test "${empty-bad}" = "" || testfail
"got \"${empty-bad}\": empty var nocolon"
59 test "${unsetvar-ok}" = ok || testfail
"unset var"
62 test "${empty-ok}" = ok || testfail
"unset"
66 test "x$1" = x-Z || testfail
'\"set -- arg\"'
67 # this should empty the argument list
70 test $# = 0 || testfail
"still $# args: \"set --\""
78 test "$2" = good || testfail
"got \"$2\": IFS parsing"
81 # "$@" with 0 arguments should expand to 0 arguments
83 cat > $TMPDIR/conftest1
<< EOF
84 $TMPDIR/conftest2 "\$@"
86 cat > $TMPDIR/conftest2
<< "EOF"
90 chmod +x
$TMPDIR/conftest1
$TMPDIR/conftest2
91 numargs
=$
($TESTSHELL $TMPDIR/conftest1
)
92 if [ "$?" != 0 ]; then
95 test "$numargs" = 0 || testfail
'"$@" got '"$numargs args: expansion w 0 args"
97 rm -f $TMPDIR/conftest1
$TMPDIR/conftest2
100 val
=$
("$TESTSHELL" -c 'echo $1' csh good
)
101 test "$val" = good || testfail
"got \"$val\": sh -c"
104 # do these tests in a sub-shell because failure will exit
105 val
=$
("$TESTSHELL" -c 'echo ${10}' 0 1 2 3 4 5 6 7 8 9 ten
11 2> /dev
/null
)
106 test "$val" = ten || testfail
"accessing more than 9 positional params"
110 newtest
; val
=`"$TESTSHELL" -c 'echo "${a%_*}"' 2> /dev/null`
111 test "$val" = abc_def || testfail
"parameter % op"
112 newtest
; val
=`"$TESTSHELL" -c 'echo "${a%%_*}"' 2> /dev/null`
113 test "$val" = abc || testfail
"parameter %% op"
114 newtest
; val
=`"$TESTSHELL" -c 'echo "${a#*_}"' 2> /dev/null`
115 test "$val" = def_ghi || testfail
"parameter # op"
116 newtest
; val
=`"$TESTSHELL" -c 'echo "${a##*_}"' 2> /dev/null`
117 test "$val" = ghi || testfail
"parameter ## op"
120 "$TESTSHELL" -c 'export a=value' 2> /dev
/null || testfail
"export with value"
123 a
=5; test "$(( ($a+1)/2 ))" = 3 || testfail
"arithmetic expansion"
125 # does "test" support the -x switch?
127 touch $TMPDIR/conftest
128 chmod -x $TMPDIR/conftest
129 test -x $TMPDIR/conftest
&& testfail
"negative test -x"
130 chmod +x
$TMPDIR/conftest
131 test -x $TMPDIR/conftest || testfail
"positive test -x"
132 rm -f $TMPDIR/conftest
135 test "$OPTIND" = 1 || testfail
"OPTIND initial value"
138 getopts a
: store
-a aoptval
139 if [ "$OPTIND" != 3 ] ||
[ "$store" != a
] ||
[ "$OPTARG" != aoptval
]; then
143 # if I change the default quoting style for variable values, these
144 # next four must change
148 val1
=$
(set |
sed -n 's:^SQUOTE=::p')
149 if [ "$val1" != "\$'\\''" ]; then
150 testfail
"variable quoting 1"
155 val1
=$
(set |
sed -n 's:^VTILDE=::p')
156 if [ "$val1" != "\$'~'" ]; then
157 testfail
"variable quoting 2"
162 val1
=$
(set |
sed -n 's:^VHASH=::p')
163 if [ "$val1" != "ab#cd" ]; then
164 testfail
"variable quoting 3"
169 val1
=$
(set |
sed -n 's:^VHASH2=::p')
170 if [ "$val1" != "\$'#abcd'" ]; then
171 testfail
"variable quoting 4"
174 if [ $exitval = 0 ]; then
175 echo "All tests passed"
177 echo "$exitval of $numtests tests failed"