diff options
Diffstat (limited to 'bin/1sh/tests/parameters')
-rw-r--r-- | bin/1sh/tests/parameters/Makefile | 29 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/Makefile.depend | 11 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/env1.0 | 11 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/exitstatus1.0 | 9 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/ifs1.0 | 10 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/mail1.0 | 15 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/mail2.0 | 15 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/optind1.0 | 3 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/optind2.0 | 3 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/positional1.0 | 13 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/positional2.0 | 65 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/positional3.0 | 4 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/positional4.0 | 4 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/positional5.0 | 14 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/positional6.0 | 7 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/positional7.0 | 8 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/positional8.0 | 31 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/positional9.0 | 18 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/pwd1.0 | 11 | ||||
-rw-r--r-- | bin/1sh/tests/parameters/pwd2.0 | 24 |
20 files changed, 305 insertions, 0 deletions
diff --git a/bin/1sh/tests/parameters/Makefile b/bin/1sh/tests/parameters/Makefile new file mode 100644 index 00000000..71ba0525 --- /dev/null +++ b/bin/1sh/tests/parameters/Makefile @@ -0,0 +1,29 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/Makefile 306843 2016-10-08 13:40:12Z jilles $ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +${PACKAGE}FILES+= env1.0 +${PACKAGE}FILES+= exitstatus1.0 +${PACKAGE}FILES+= ifs1.0 +${PACKAGE}FILES+= mail1.0 +${PACKAGE}FILES+= mail2.0 +${PACKAGE}FILES+= optind1.0 +${PACKAGE}FILES+= optind2.0 +${PACKAGE}FILES+= positional1.0 +${PACKAGE}FILES+= positional2.0 +${PACKAGE}FILES+= positional3.0 +${PACKAGE}FILES+= positional4.0 +${PACKAGE}FILES+= positional5.0 +${PACKAGE}FILES+= positional6.0 +${PACKAGE}FILES+= positional7.0 +${PACKAGE}FILES+= positional8.0 +${PACKAGE}FILES+= positional9.0 +${PACKAGE}FILES+= pwd1.0 +${PACKAGE}FILES+= pwd2.0 + +.include <bsd.test.mk> diff --git a/bin/1sh/tests/parameters/Makefile.depend b/bin/1sh/tests/parameters/Makefile.depend new file mode 100644 index 00000000..e37b229c --- /dev/null +++ b/bin/1sh/tests/parameters/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/Makefile.depend 296587 2016-03-09 22:46:01Z bdrewery $ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/bin/1sh/tests/parameters/env1.0 b/bin/1sh/tests/parameters/env1.0 new file mode 100644 index 00000000..cd1c7436 --- /dev/null +++ b/bin/1sh/tests/parameters/env1.0 @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/env1.0 222957 2011-06-10 22:42:00Z jilles $ + +export key='must contain this' +unset x +r=$(ENV="\${x?\$key}" ${SH} -i +m 2>&1 >/dev/null <<\EOF +exit 0 +EOF +) && case $r in +*"$key"*) true ;; +*) false ;; +esac diff --git a/bin/1sh/tests/parameters/exitstatus1.0 b/bin/1sh/tests/parameters/exitstatus1.0 new file mode 100644 index 00000000..584b7958 --- /dev/null +++ b/bin/1sh/tests/parameters/exitstatus1.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/exitstatus1.0 185232 2008-11-23 20:27:03Z stefanf $ +f() { + [ $? = $1 ] || exit 1 +} + +true +f 0 +false +f 1 diff --git a/bin/1sh/tests/parameters/ifs1.0 b/bin/1sh/tests/parameters/ifs1.0 new file mode 100644 index 00000000..3cd37cd9 --- /dev/null +++ b/bin/1sh/tests/parameters/ifs1.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/ifs1.0 306843 2016-10-08 13:40:12Z jilles $ + +env IFS=_ ${SH} -c ' +rc=2 +nosuchtool_function() { + rc=0 +} +v=nosuchtool_function +$v && exit "$rc" +' diff --git a/bin/1sh/tests/parameters/mail1.0 b/bin/1sh/tests/parameters/mail1.0 new file mode 100644 index 00000000..01baf8fd --- /dev/null +++ b/bin/1sh/tests/parameters/mail1.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/mail1.0 213738 2010-10-12 18:20:38Z obrien $ +# Test that a non-interactive shell does not access $MAIL. + +goodfile=/var/empty/sh-test-goodfile +mailfile=/var/empty/sh-test-mailfile +T=$(mktemp sh-test.XXXXXX) || exit +MAIL=$mailfile ktrace -i -f "$T" ${SH} -c "[ -s $goodfile ]" 2>/dev/null +if ! grep -q $goodfile "$T"; then + # ktrace problem + rc=0 +elif ! grep -q $mailfile "$T"; then + rc=0 +fi +rm "$T" +exit ${rc:-3} diff --git a/bin/1sh/tests/parameters/mail2.0 b/bin/1sh/tests/parameters/mail2.0 new file mode 100644 index 00000000..b6524daf --- /dev/null +++ b/bin/1sh/tests/parameters/mail2.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/mail2.0 213738 2010-10-12 18:20:38Z obrien $ +# Test that an interactive shell accesses $MAIL. + +goodfile=/var/empty/sh-test-goodfile +mailfile=/var/empty/sh-test-mailfile +T=$(mktemp sh-test.XXXXXX) || exit +ENV=$goodfile MAIL=$mailfile ktrace -i -f "$T" ${SH} +m -i </dev/null >/dev/null 2>&1 +if ! grep -q $goodfile "$T"; then + # ktrace problem + rc=0 +elif grep -q $mailfile "$T"; then + rc=0 +fi +rm "$T" +exit ${rc:-3} diff --git a/bin/1sh/tests/parameters/optind1.0 b/bin/1sh/tests/parameters/optind1.0 new file mode 100644 index 00000000..947e6aad --- /dev/null +++ b/bin/1sh/tests/parameters/optind1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/optind1.0 227773 2011-11-20 21:48:50Z jilles $ + +unset OPTIND && [ -z "$OPTIND" ] diff --git a/bin/1sh/tests/parameters/optind2.0 b/bin/1sh/tests/parameters/optind2.0 new file mode 100644 index 00000000..3c552346 --- /dev/null +++ b/bin/1sh/tests/parameters/optind2.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/optind2.0 259846 2013-12-24 22:38:24Z jilles $ + +[ "$(OPTIND=42 ${SH} -c 'printf %s "$OPTIND"')" = 1 ] diff --git a/bin/1sh/tests/parameters/positional1.0 b/bin/1sh/tests/parameters/positional1.0 new file mode 100644 index 00000000..71ee1a20 --- /dev/null +++ b/bin/1sh/tests/parameters/positional1.0 @@ -0,0 +1,13 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/positional1.0 222158 2011-05-21 14:52:26Z jilles $ + +set -- a b c d e f g h i j +[ "$1" = a ] || echo "error at line $LINENO" +[ "${1}" = a ] || echo "error at line $LINENO" +[ "${1-foo}" = a ] || echo "error at line $LINENO" +[ "${1+foo}" = foo ] || echo "error at line $LINENO" +[ "$1+foo" = a+foo ] || echo "error at line $LINENO" +[ "$10" = a0 ] || echo "error at line $LINENO" +[ "$100" = a00 ] || echo "error at line $LINENO" +[ "${10}" = j ] || echo "error at line $LINENO" +[ "${10-foo}" = j ] || echo "error at line $LINENO" +[ "${100-foo}" = foo ] || echo "error at line $LINENO" diff --git a/bin/1sh/tests/parameters/positional2.0 b/bin/1sh/tests/parameters/positional2.0 new file mode 100644 index 00000000..94f4ec13 --- /dev/null +++ b/bin/1sh/tests/parameters/positional2.0 @@ -0,0 +1,65 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/positional2.0 228873 2011-12-25 13:24:48Z jilles $ + +failures='' +ok='' + +testcase() { + code="$1" + expected="$2" + oIFS="$IFS" + eval "$code" + IFS='|' + result="$#|$*" + IFS="$oIFS" + if [ "x$result" = "x$expected" ]; then + ok=x$ok + else + failures=x$failures + echo "For $code, expected $expected actual $result" + fi +} + +testcase 'set -- a b; set -- p$@q' '2|pa|bq' +testcase 'set -- a b; set -- $@q' '2|a|bq' +testcase 'set -- a b; set -- p$@' '2|pa|b' +testcase 'set -- a b; set -- p$@q' '2|pa|bq' +testcase 'set -- a b; set -- $@q' '2|a|bq' +testcase 'set -- a b; set -- p$@' '2|pa|b' +testcase 'set -- a b; set -- p$*q' '2|pa|bq' +testcase 'set -- a b; set -- $*q' '2|a|bq' +testcase 'set -- a b; set -- p$*' '2|pa|b' +testcase 'set -- a b; set -- p$*q' '2|pa|bq' +testcase 'set -- a b; set -- $*q' '2|a|bq' +testcase 'set -- a b; set -- p$*' '2|pa|b' +testcase 'set -- a b; set -- "p$@q"' '2|pa|bq' +testcase 'set -- a b; set -- "$@q"' '2|a|bq' +testcase 'set -- a b; set -- "p$@"' '2|pa|b' +testcase 'set -- a b; set -- p"$@"q' '2|pa|bq' +testcase 'set -- a b; set -- "$@"q' '2|a|bq' +testcase 'set -- a b; set -- p"$@"' '2|pa|b' +testcase 'set -- "" a b; set -- "p$@q"' '3|p|a|bq' +testcase 'set -- "" a b; set -- "$@q"' '3||a|bq' +testcase 'set -- "" a b; set -- "p$@"' '3|p|a|b' +testcase 'set -- "" a b; set -- p"$@"q' '3|p|a|bq' +testcase 'set -- "" a b; set -- "$@"q' '3||a|bq' +testcase 'set -- "" a b; set -- p"$@"' '3|p|a|b' +testcase 'set -- a; set -- p$@q' '1|paq' +testcase 'set -- a; set -- $@q' '1|aq' +testcase 'set -- a; set -- p$@' '1|pa' +testcase 'set -- a; set -- p$@q' '1|paq' +testcase 'set -- a; set -- $@q' '1|aq' +testcase 'set -- a; set -- p$@' '1|pa' +testcase 'set -- a; set -- p$*q' '1|paq' +testcase 'set -- a; set -- $*q' '1|aq' +testcase 'set -- a; set -- p$*' '1|pa' +testcase 'set -- a; set -- p$*q' '1|paq' +testcase 'set -- a; set -- $*q' '1|aq' +testcase 'set -- a; set -- p$*' '1|pa' +testcase 'set -- a; set -- "p$@q"' '1|paq' +testcase 'set -- a; set -- "$@q"' '1|aq' +testcase 'set -- a; set -- "p$@"' '1|pa' +testcase 'set -- a; set -- p"$@"q' '1|paq' +testcase 'set -- a; set -- "$@"q' '1|aq' +testcase 'set -- a; set -- p"$@"' '1|pa' + +test "x$failures" = x diff --git a/bin/1sh/tests/parameters/positional3.0 b/bin/1sh/tests/parameters/positional3.0 new file mode 100644 index 00000000..397fa19c --- /dev/null +++ b/bin/1sh/tests/parameters/positional3.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/positional3.0 268436 2014-07-08 22:04:44Z jilles $ + +r=$(${SH} -c 'echo ${01:+yes}${010:+yes}' '' a '' '' '' '' '' '' '' '' b) +[ "$r" = yesyes ] diff --git a/bin/1sh/tests/parameters/positional4.0 b/bin/1sh/tests/parameters/positional4.0 new file mode 100644 index 00000000..b2a47dce --- /dev/null +++ b/bin/1sh/tests/parameters/positional4.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/positional4.0 268568 2014-07-12 10:27:30Z jilles $ + +set -- "x$0" 2 3 4 5 6 7 8 9 "y$0" +[ "${01}.${010}" = "$1.${10}" ] diff --git a/bin/1sh/tests/parameters/positional5.0 b/bin/1sh/tests/parameters/positional5.0 new file mode 100644 index 00000000..ab918d2f --- /dev/null +++ b/bin/1sh/tests/parameters/positional5.0 @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/positional5.0 268576 2014-07-12 21:54:11Z jilles $ + +i=1 +r=0 +while [ $i -lt $((0x100000000)) ]; do + t= + eval t=\${$i-x} + case $t in + x) ;; + *) echo "Problem with \${$i}" >&2; r=1 ;; + esac + i=$((i + 0x10000000)) +done +exit $r diff --git a/bin/1sh/tests/parameters/positional6.0 b/bin/1sh/tests/parameters/positional6.0 new file mode 100644 index 00000000..e0b46aa2 --- /dev/null +++ b/bin/1sh/tests/parameters/positional6.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/positional6.0 273802 2014-10-28 22:14:31Z jilles $ + +IFS=? +set p r +v=pqrs +r=${v#"$*"} +[ "$r" = pqrs ] diff --git a/bin/1sh/tests/parameters/positional7.0 b/bin/1sh/tests/parameters/positional7.0 new file mode 100644 index 00000000..60a92bf6 --- /dev/null +++ b/bin/1sh/tests/parameters/positional7.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/positional7.0 273802 2014-10-28 22:14:31Z jilles $ + +set -- / '' +IFS=* +set -- "$*" +IFS=: +args="$*" +[ "$#:$args" = "1:/*" ] diff --git a/bin/1sh/tests/parameters/positional8.0 b/bin/1sh/tests/parameters/positional8.0 new file mode 100644 index 00000000..78cfefb2 --- /dev/null +++ b/bin/1sh/tests/parameters/positional8.0 @@ -0,0 +1,31 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/positional8.0 291025 2015-11-18 21:09:03Z jilles $ + +failures='' +ok='' + +testcase() { + code="$1" + expected="$2" + oIFS="$IFS" + eval "$code" + IFS='|' + result="$#|$*" + IFS="$oIFS" + if [ "x$result" = "x$expected" ]; then + ok=x$ok + else + failures=x$failures + echo "For $code, expected $expected actual $result" + fi +} + +testcase 'shift $#; set -- ""$*' '1|' +testcase 'shift $#; set -- $*""' '1|' +testcase 'shift $#; set -- ""$@' '1|' +testcase 'shift $#; set -- $@""' '1|' +testcase 'shift $#; set -- """$*"' '1|' +testcase 'shift $#; set -- "$*"""' '1|' +testcase 'shift $#; set -- """$@"' '1|' +testcase 'shift $#; set -- "$@"""' '1|' + +test "x$failures" = x diff --git a/bin/1sh/tests/parameters/positional9.0 b/bin/1sh/tests/parameters/positional9.0 new file mode 100644 index 00000000..3d1e667d --- /dev/null +++ b/bin/1sh/tests/parameters/positional9.0 @@ -0,0 +1,18 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/positional9.0 291903 2015-12-06 14:09:31Z jilles $ +# Although POSIX leaves the result of expanding ${#@} and ${#*} unspecified, +# make sure it is at least numeric. + +set -- bb cc ddd +set -f +lengths=${#*}${#@}"${#*}${#@}"$(echo ${#*}${#@}"${#*}${#@}") +IFS= +lengths=$lengths${#*}${#@}"${#*}${#@}"$(echo ${#*}${#@}"${#*}${#@}") +case $lengths in +*[!0-9]*) + printf 'bad: %s\n' "$lengths" + exit 3 ;; +????????????????*) ;; +*) + printf 'too short: %s\n' "$lengths" + exit 3 ;; +esac diff --git a/bin/1sh/tests/parameters/pwd1.0 b/bin/1sh/tests/parameters/pwd1.0 new file mode 100644 index 00000000..c88511af --- /dev/null +++ b/bin/1sh/tests/parameters/pwd1.0 @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/pwd1.0 213738 2010-10-12 18:20:38Z obrien $ +# Check that bogus PWD values are not accepted from the environment. + +cd / || exit 3 +failures=0 +[ "$(PWD=foo ${SH} -c 'pwd')" = / ] || : $((failures += 1)) +[ "$(PWD=/var/empty ${SH} -c 'pwd')" = / ] || : $((failures += 1)) +[ "$(PWD=/var/empty/foo ${SH} -c 'pwd')" = / ] || : $((failures += 1)) +[ "$(PWD=/bin/ls ${SH} -c 'pwd')" = / ] || : $((failures += 1)) + +exit $((failures != 0)) diff --git a/bin/1sh/tests/parameters/pwd2.0 b/bin/1sh/tests/parameters/pwd2.0 new file mode 100644 index 00000000..b03f9ace --- /dev/null +++ b/bin/1sh/tests/parameters/pwd2.0 @@ -0,0 +1,24 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parameters/pwd2.0 213738 2010-10-12 18:20:38Z obrien $ +# Check that PWD is exported and accepted from the environment. +set -e + +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) +trap 'rm -rf $T' 0 +cd -P $T +TP=$(pwd) +mkdir test1 +ln -s test1 link +cd link +[ "$PWD" = "$TP/link" ] +[ "$(pwd)" = "$TP/link" ] +[ "$(pwd -P)" = "$TP/test1" ] +[ "$(${SH} -c pwd)" = "$TP/link" ] +[ "$(${SH} -c pwd\ -P)" = "$TP/test1" ] +cd .. +[ "$(pwd)" = "$TP" ] +cd -P link +[ "$PWD" = "$TP/test1" ] +[ "$(pwd)" = "$TP/test1" ] +[ "$(pwd -P)" = "$TP/test1" ] +[ "$(${SH} -c pwd)" = "$TP/test1" ] +[ "$(${SH} -c pwd\ -P)" = "$TP/test1" ] |