From c03be87336bac638797eefe00242ba8094635b5e Mon Sep 17 00:00:00 2001 From: jilles Date: Sun, 16 Jan 2011 23:41:40 +0000 Subject: [PATCH] MFC r215547,r216763,r216819,r216871,r217172: sh testcases. git-svn-id: svn://svn.freebsd.org/base/stable/8@217489 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- tools/regression/bin/sh/builtins/exit1.0 | 6 +++ tools/regression/bin/sh/builtins/exit2.8 | 7 +++ tools/regression/bin/sh/builtins/wait3.0 | 21 ++++++++ tools/regression/bin/sh/expansion/cmdsubst6.0 | 53 +++++++++++++++++++ tools/regression/bin/sh/expansion/cmdsubst8.0 | 17 ++++++ tools/regression/bin/sh/expansion/cmdsubst9.0 | 11 ++++ 6 files changed, 115 insertions(+) create mode 100644 tools/regression/bin/sh/builtins/exit1.0 create mode 100644 tools/regression/bin/sh/builtins/exit2.8 create mode 100644 tools/regression/bin/sh/builtins/wait3.0 create mode 100644 tools/regression/bin/sh/expansion/cmdsubst6.0 create mode 100644 tools/regression/bin/sh/expansion/cmdsubst8.0 create mode 100644 tools/regression/bin/sh/expansion/cmdsubst9.0 diff --git a/tools/regression/bin/sh/builtins/exit1.0 b/tools/regression/bin/sh/builtins/exit1.0 new file mode 100644 index 000000000..496d44876 --- /dev/null +++ b/tools/regression/bin/sh/builtins/exit1.0 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +# exit with an argument should overwrite the exit status in an EXIT trap. + +trap 'true; exit $?' 0 +false diff --git a/tools/regression/bin/sh/builtins/exit2.8 b/tools/regression/bin/sh/builtins/exit2.8 new file mode 100644 index 000000000..124c32e01 --- /dev/null +++ b/tools/regression/bin/sh/builtins/exit2.8 @@ -0,0 +1,7 @@ +# $FreeBSD$ + +# exit without arguments is the same as exit $? outside a trap. + +trap 'true; true' 0 +(exit 8) +exit diff --git a/tools/regression/bin/sh/builtins/wait3.0 b/tools/regression/bin/sh/builtins/wait3.0 new file mode 100644 index 000000000..d4eb25017 --- /dev/null +++ b/tools/regression/bin/sh/builtins/wait3.0 @@ -0,0 +1,21 @@ +# $FreeBSD$ + +failures= +failure() { + echo "Error at line $1" >&2 + failures=x$failures +} + +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) +trap 'rm -rf $T' 0 +cd $T || exit 3 +mkfifo fifo1 +for i in 1 2 3 4 5 6 7 8 9 10; do + exit $i 4fifo1 +wait || failure $LINENO +(echo >&3) 2>/dev/null && failure $LINENO +wait || failure $LINENO + +test -z "$failures" diff --git a/tools/regression/bin/sh/expansion/cmdsubst6.0 b/tools/regression/bin/sh/expansion/cmdsubst6.0 new file mode 100644 index 000000000..6586f330d --- /dev/null +++ b/tools/regression/bin/sh/expansion/cmdsubst6.0 @@ -0,0 +1,53 @@ +# $FreeBSD$ +# This tests if the cmdsubst optimization is still used if possible. + +failures='' +ok='' + +testcase() { + code="$1" + + unset v + eval "pid=\$(dummy=$code echo \$(\$SH -c echo\ \\\$PPID))" + + if [ "$pid" = "$$" ]; then + ok=x$ok + else + failures=x$failures + echo "Failure for $code" + fi +} + +unset v +w=1 +testcase '$w' +testcase '1${w+1}' +testcase '1${w-1}' +testcase '1${v+1}' +testcase '1${v-1}' +testcase '1${w:+1}' +testcase '1${w:-1}' +testcase '1${v:+1}' +testcase '1${v:-1}' +testcase '${w?}' +testcase '${w:?}' +testcase '${w#x}' +testcase '${w##x}' +testcase '${w%x}' +testcase '${w%%x}' + +testcase '$((w))' +testcase '$(((w+4)*2/3))' +testcase '$((w==1))' +testcase '$((w>=0 && w<=5 && w!=2))' +testcase '$((${#w}))' +testcase '$((${#IFS}))' +testcase '$((${#w}>=1))' +testcase '$(($$))' +testcase '$(($#))' +testcase '$(($?))' + +testcase '$(: $((w=4)))' +testcase '$(: ${v=2})' + +test "x$failures" = x diff --git a/tools/regression/bin/sh/expansion/cmdsubst8.0 b/tools/regression/bin/sh/expansion/cmdsubst8.0 new file mode 100644 index 000000000..52adaea33 --- /dev/null +++ b/tools/regression/bin/sh/expansion/cmdsubst8.0 @@ -0,0 +1,17 @@ +# $FreeBSD$ +# Not required by POSIX (although referenced in a non-normative section), +# but possibly useful. + +: hi there & +p=$! +q=$(jobs -l $p) + +# Change tabs to spaces. +set -f +set -- $q +r="$*" + +case $r in +*" $p "*) ;; +*) echo Pid missing; exit 3 ;; +esac diff --git a/tools/regression/bin/sh/expansion/cmdsubst9.0 b/tools/regression/bin/sh/expansion/cmdsubst9.0 new file mode 100644 index 000000000..0b1f81f35 --- /dev/null +++ b/tools/regression/bin/sh/expansion/cmdsubst9.0 @@ -0,0 +1,11 @@ +# $FreeBSD$ + +set -e + +cd / +dummy=$(cd /bin) +[ "$(pwd)" = / ] + +v=1 +dummy=$(eval v=2) +[ "$v" = 1 ] -- 2.45.0