Imported from ../bash-2.01.tar.gz.
[platform/upstream/bash.git] / tests / test-tests
index 1fb0dc8..9b81359 100644 (file)
@@ -1,3 +1,13 @@
+if (( $UID == 0 )); then
+       echo "test-tests: the test suite should not be run as root" >&2
+fi
+
+b()
+{
+       [ "$@" ]
+       echo $?
+}
+
 t()
 {
        test "$@"
@@ -23,6 +33,10 @@ echo 't -d run-all'
 t -d run-all
 echo 't -d /etc'
 t -d /etc
+echo 't -d ""'
+t -d ""
+echo 'b -d ""'
+b -d ""
 
 echo 't -e noexist'
 t -e noexist
@@ -40,6 +54,7 @@ echo 't -g run-all'
 t -g run-all
 
 touch /tmp/test.setgid
+chgrp ${GROUPS[0]} /tmp/test.setgid
 chmod ug+x /tmp/test.setgid
 chmod g+s /tmp/test.setgid
 echo 't -g /tmp/test.setgid'
@@ -60,11 +75,16 @@ t -p run-all
 echo 't -r noexist'
 t -r noexist
 
-touch /tmp/test.noread
-chmod a-r /tmp/test.noread
-echo 't -r /tmp/test.noread'
-t -r /tmp/test.noread
-rm -f /tmp/test.noread
+if (( $UID != 0 )); then
+       touch /tmp/test.noread
+       chmod a-r /tmp/test.noread
+       echo 't -r /tmp/test.noread'
+       t -r /tmp/test.noread
+       rm -f /tmp/test.noread
+else
+       echo 't -r /tmp/test.noread'
+       echo 1
+fi
 
 echo 't -r run-all'
 t -r run-all
@@ -97,11 +117,16 @@ rm -f /tmp/test.setuid
 echo 't -w noexist'
 t -w noexist
 
-touch /tmp/test.nowrite
-chmod a-w /tmp/test.nowrite
-echo 't -w /tmp/test.nowrite'
-t -w /tmp/test.nowrite
-rm -f /tmp/test.nowrite
+if (( $UID != 0 )); then
+       touch /tmp/test.nowrite
+       chmod a-w /tmp/test.nowrite
+       echo 't -w /tmp/test.nowrite'
+       t -w /tmp/test.nowrite
+       rm -f /tmp/test.nowrite
+else
+       echo 't -w /tmp/test.nowrite'
+       echo 1
+fi
 
 echo 't -w /dev/null'
 t -w /dev/null
@@ -163,6 +188,8 @@ echo 't 200 -eq 200'
 t 200 -eq 200
 echo 't 34 -eq 222'
 t 34 -eq 222
+echo 't -32 -eq 32'
+t -32 -eq 32
 
 echo 't 200 -ne 200'
 t 200 -ne 200
@@ -221,8 +248,11 @@ echo 't -w /dev/fd/1'
 t -w /dev/fd/1
 echo 't -w /dev/fd/2'
 t -w /dev/fd/2
+
 echo 't'
 t
+echo 'b'
+b
 
 echo 't 12 -eq 34'
 t 12 -eq 34
@@ -277,3 +307,86 @@ echo 't ( -E )'
 t \( -E \)
 echo 't ( "" )'
 t \( "" \)
+
+z=42
+
+echo 't ! -z "$z"'
+t ! -z "$z"
+
+echo 't ! -n "$z"'
+t ! -n "$z"
+
+zero=
+echo 't "$zero"'
+t "$zero"
+echo 't ! "$zero"'
+t ! "$zero"
+echo 'b "$zero"'
+b "$zero"
+echo 'b ! "$zero"'
+b ! "$zero"
+
+touch /tmp/test.group
+chgrp ${GROUPS[0]} /tmp/test.group
+echo 't -G /tmp/test.group'
+t -G /tmp/test.group
+rm /tmp/test.group
+
+case "${THIS_SH}" in
+/*)    SHNAME=${THIS_SH} ;;
+*)     SHNAME=${PWD}/${THIS_SH} ;;
+esac
+
+if ln -s ${SHNAME} /tmp/test.symlink 2>/dev/null; then
+       chgrp ${GROUPS[0]} /tmp/test.symlink
+       echo 't -h /tmp/test.symlink'
+       t -h /tmp/test.symlink
+       # some systems don't let you remove this
+       rm -f /tmp/test.symlink 2>/dev/null
+else
+       echo 't -h /tmp/test.symlink'
+       echo 0
+fi
+
+# arithmetic constant errors
+echo "t 4+3 -eq 7"
+t 4+3 -eq 7
+echo "b 4-5 -eq 7"
+b 4+3 -eq 7
+
+echo "t 9 -eq 4+5"
+t 9 -eq 4+5
+echo "b 9 -eq 4+5"
+b 9 -eq 4+5
+
+A=7
+echo "t A -eq 7"
+t A -eq 7
+echo "b A -eq 7"
+b A -eq 7
+
+B=9
+echo "t 9 -eq B"
+t 9 -eq B
+echo "b 9 -eq B"
+b 9 -eq B
+
+# badly formed expressions
+echo 't ( 1 = 2'
+t \( 1 = 2
+echo 'b ( 1 = 2'
+b \( 1 = 2
+
+# more errors
+t a b
+t a b c
+t -A v
+# too many arguments -- argument expected is also reasonable
+t 4 -eq 4 -a 2 -ne 5 -a 4 -ne
+# too many arguments
+t 4 -eq 4 -a 3 4
+
+[
+echo $?
+
+t \( \)