From 5fd83771641d15c418f747bd343ba6738d3875f7 Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Sun, 9 May 2021 14:20:58 -0400 Subject: Import macOS userland adv_cmds-176 basic_cmds-55 bootstrap_cmds-116.100.1 developer_cmds-66 diskdev_cmds-667.40.1 doc_cmds-53.60.1 file_cmds-321.40.3 mail_cmds-35 misc_cmds-34 network_cmds-606.40.1 patch_cmds-17 remote_cmds-63 shell_cmds-216.60.1 system_cmds-880.60.2 text_cmds-106 --- shell_cmds/sh/tests/parameters/Makefile | 29 ++++++++++++ shell_cmds/sh/tests/parameters/Makefile.depend | 11 +++++ shell_cmds/sh/tests/parameters/env1.0 | 11 +++++ shell_cmds/sh/tests/parameters/exitstatus1.0 | 9 ++++ shell_cmds/sh/tests/parameters/ifs1.0 | 10 ++++ shell_cmds/sh/tests/parameters/mail1.0 | 15 ++++++ shell_cmds/sh/tests/parameters/mail2.0 | 15 ++++++ shell_cmds/sh/tests/parameters/optind1.0 | 3 ++ shell_cmds/sh/tests/parameters/optind2.0 | 3 ++ shell_cmds/sh/tests/parameters/positional1.0 | 13 ++++++ shell_cmds/sh/tests/parameters/positional2.0 | 65 ++++++++++++++++++++++++++ shell_cmds/sh/tests/parameters/positional3.0 | 4 ++ shell_cmds/sh/tests/parameters/positional4.0 | 4 ++ shell_cmds/sh/tests/parameters/positional5.0 | 14 ++++++ shell_cmds/sh/tests/parameters/positional6.0 | 7 +++ shell_cmds/sh/tests/parameters/positional7.0 | 8 ++++ shell_cmds/sh/tests/parameters/positional8.0 | 31 ++++++++++++ shell_cmds/sh/tests/parameters/positional9.0 | 18 +++++++ shell_cmds/sh/tests/parameters/pwd1.0 | 11 +++++ shell_cmds/sh/tests/parameters/pwd2.0 | 24 ++++++++++ 20 files changed, 305 insertions(+) create mode 100644 shell_cmds/sh/tests/parameters/Makefile create mode 100644 shell_cmds/sh/tests/parameters/Makefile.depend create mode 100644 shell_cmds/sh/tests/parameters/env1.0 create mode 100644 shell_cmds/sh/tests/parameters/exitstatus1.0 create mode 100644 shell_cmds/sh/tests/parameters/ifs1.0 create mode 100644 shell_cmds/sh/tests/parameters/mail1.0 create mode 100644 shell_cmds/sh/tests/parameters/mail2.0 create mode 100644 shell_cmds/sh/tests/parameters/optind1.0 create mode 100644 shell_cmds/sh/tests/parameters/optind2.0 create mode 100644 shell_cmds/sh/tests/parameters/positional1.0 create mode 100644 shell_cmds/sh/tests/parameters/positional2.0 create mode 100644 shell_cmds/sh/tests/parameters/positional3.0 create mode 100644 shell_cmds/sh/tests/parameters/positional4.0 create mode 100644 shell_cmds/sh/tests/parameters/positional5.0 create mode 100644 shell_cmds/sh/tests/parameters/positional6.0 create mode 100644 shell_cmds/sh/tests/parameters/positional7.0 create mode 100644 shell_cmds/sh/tests/parameters/positional8.0 create mode 100644 shell_cmds/sh/tests/parameters/positional9.0 create mode 100644 shell_cmds/sh/tests/parameters/pwd1.0 create mode 100644 shell_cmds/sh/tests/parameters/pwd2.0 (limited to 'shell_cmds/sh/tests/parameters') diff --git a/shell_cmds/sh/tests/parameters/Makefile b/shell_cmds/sh/tests/parameters/Makefile new file mode 100644 index 0000000..30708db --- /dev/null +++ b/shell_cmds/sh/tests/parameters/Makefile @@ -0,0 +1,29 @@ +# $FreeBSD: head/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 diff --git a/shell_cmds/sh/tests/parameters/Makefile.depend b/shell_cmds/sh/tests/parameters/Makefile.depend new file mode 100644 index 0000000..41114a3 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: head/bin/sh/tests/parameters/Makefile.depend 296587 2016-03-09 22:46:01Z bdrewery $ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/shell_cmds/sh/tests/parameters/env1.0 b/shell_cmds/sh/tests/parameters/env1.0 new file mode 100644 index 0000000..0842856 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/env1.0 @@ -0,0 +1,11 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/exitstatus1.0 b/shell_cmds/sh/tests/parameters/exitstatus1.0 new file mode 100644 index 0000000..709600e --- /dev/null +++ b/shell_cmds/sh/tests/parameters/exitstatus1.0 @@ -0,0 +1,9 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/ifs1.0 b/shell_cmds/sh/tests/parameters/ifs1.0 new file mode 100644 index 0000000..e88d7a4 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/ifs1.0 @@ -0,0 +1,10 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/mail1.0 b/shell_cmds/sh/tests/parameters/mail1.0 new file mode 100644 index 0000000..af69211 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/mail1.0 @@ -0,0 +1,15 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/mail2.0 b/shell_cmds/sh/tests/parameters/mail2.0 new file mode 100644 index 0000000..74dc416 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/mail2.0 @@ -0,0 +1,15 @@ +# $FreeBSD: head/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 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/shell_cmds/sh/tests/parameters/optind1.0 b/shell_cmds/sh/tests/parameters/optind1.0 new file mode 100644 index 0000000..30fc9d8 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/optind1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: head/bin/sh/tests/parameters/optind1.0 227773 2011-11-20 21:48:50Z jilles $ + +unset OPTIND && [ -z "$OPTIND" ] diff --git a/shell_cmds/sh/tests/parameters/optind2.0 b/shell_cmds/sh/tests/parameters/optind2.0 new file mode 100644 index 0000000..0837a17 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/optind2.0 @@ -0,0 +1,3 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/positional1.0 b/shell_cmds/sh/tests/parameters/positional1.0 new file mode 100644 index 0000000..ef95be3 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/positional1.0 @@ -0,0 +1,13 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/positional2.0 b/shell_cmds/sh/tests/parameters/positional2.0 new file mode 100644 index 0000000..ea29250 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/positional2.0 @@ -0,0 +1,65 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/positional3.0 b/shell_cmds/sh/tests/parameters/positional3.0 new file mode 100644 index 0000000..d164ed9 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/positional3.0 @@ -0,0 +1,4 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/positional4.0 b/shell_cmds/sh/tests/parameters/positional4.0 new file mode 100644 index 0000000..48c2f01 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/positional4.0 @@ -0,0 +1,4 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/positional5.0 b/shell_cmds/sh/tests/parameters/positional5.0 new file mode 100644 index 0000000..80ef805 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/positional5.0 @@ -0,0 +1,14 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/positional6.0 b/shell_cmds/sh/tests/parameters/positional6.0 new file mode 100644 index 0000000..c1d5e4c --- /dev/null +++ b/shell_cmds/sh/tests/parameters/positional6.0 @@ -0,0 +1,7 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/positional7.0 b/shell_cmds/sh/tests/parameters/positional7.0 new file mode 100644 index 0000000..df36b6f --- /dev/null +++ b/shell_cmds/sh/tests/parameters/positional7.0 @@ -0,0 +1,8 @@ +# $FreeBSD: head/bin/sh/tests/parameters/positional7.0 273802 2014-10-28 22:14:31Z jilles $ + +set -- / '' +IFS=* +set -- "$*" +IFS=: +args="$*" +[ "$#:$args" = "1:/*" ] diff --git a/shell_cmds/sh/tests/parameters/positional8.0 b/shell_cmds/sh/tests/parameters/positional8.0 new file mode 100644 index 0000000..69717ce --- /dev/null +++ b/shell_cmds/sh/tests/parameters/positional8.0 @@ -0,0 +1,31 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/positional9.0 b/shell_cmds/sh/tests/parameters/positional9.0 new file mode 100644 index 0000000..c353e85 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/positional9.0 @@ -0,0 +1,18 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/pwd1.0 b/shell_cmds/sh/tests/parameters/pwd1.0 new file mode 100644 index 0000000..8393ef6 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/pwd1.0 @@ -0,0 +1,11 @@ +# $FreeBSD: head/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/shell_cmds/sh/tests/parameters/pwd2.0 b/shell_cmds/sh/tests/parameters/pwd2.0 new file mode 100644 index 0000000..d0cecf5 --- /dev/null +++ b/shell_cmds/sh/tests/parameters/pwd2.0 @@ -0,0 +1,24 @@ +# $FreeBSD: head/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" ] -- cgit v1.2.3-56-ge451