diff options
Diffstat (limited to '')
534 files changed, 8016 insertions, 0 deletions
diff --git a/bin/1sh/tests/Makefile b/bin/1sh/tests/Makefile new file mode 100644 index 00000000..454536a4 --- /dev/null +++ b/bin/1sh/tests/Makefile @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/Makefile 322438 2017-08-12 19:17:48Z jilles $ + +.include <bsd.own.mk> + +TESTS_SUBDIRS+= builtins +TESTS_SUBDIRS+= errors +TESTS_SUBDIRS+= execution +TESTS_SUBDIRS+= expansion +TESTS_SUBDIRS+= invocation +TESTS_SUBDIRS+= parameters +TESTS_SUBDIRS+= parser +TESTS_SUBDIRS+= set-e + +.include <bsd.test.mk> diff --git a/bin/1sh/tests/Makefile.depend b/bin/1sh/tests/Makefile.depend new file mode 100644 index 00000000..c127cc67 --- /dev/null +++ b/bin/1sh/tests/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/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/builtins/Makefile b/bin/1sh/tests/builtins/Makefile new file mode 100644 index 00000000..f3427cf4 --- /dev/null +++ b/bin/1sh/tests/builtins/Makefile @@ -0,0 +1,187 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/Makefile 336320 2018-07-15 21:55:17Z jilles $ + +PACKAGE= tests + +.include <src.opts.mk> + +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +${PACKAGE}FILES+= alias.0 alias.0.stdout +${PACKAGE}FILES+= alias.1 alias.1.stderr +${PACKAGE}FILES+= alias3.0 alias3.0.stdout +${PACKAGE}FILES+= alias4.0 +${PACKAGE}FILES+= break1.0 +${PACKAGE}FILES+= break2.0 break2.0.stdout +${PACKAGE}FILES+= break3.0 +${PACKAGE}FILES+= break4.4 +${PACKAGE}FILES+= break5.4 +${PACKAGE}FILES+= break6.0 +${PACKAGE}FILES+= builtin1.0 +${PACKAGE}FILES+= case1.0 +${PACKAGE}FILES+= case2.0 +${PACKAGE}FILES+= case3.0 +${PACKAGE}FILES+= case4.0 +${PACKAGE}FILES+= case5.0 +${PACKAGE}FILES+= case6.0 +${PACKAGE}FILES+= case7.0 +${PACKAGE}FILES+= case8.0 +${PACKAGE}FILES+= case9.0 +${PACKAGE}FILES+= case10.0 +${PACKAGE}FILES+= case11.0 +${PACKAGE}FILES+= case12.0 +${PACKAGE}FILES+= case13.0 +${PACKAGE}FILES+= case14.0 +${PACKAGE}FILES+= case15.0 +${PACKAGE}FILES+= case16.0 +${PACKAGE}FILES+= case17.0 +${PACKAGE}FILES+= case18.0 +${PACKAGE}FILES+= case19.0 +${PACKAGE}FILES+= case20.0 +${PACKAGE}FILES+= case21.0 +${PACKAGE}FILES+= case22.0 +${PACKAGE}FILES+= case23.0 +${PACKAGE}FILES+= cd1.0 +${PACKAGE}FILES+= cd2.0 +${PACKAGE}FILES+= cd3.0 +${PACKAGE}FILES+= cd4.0 +${PACKAGE}FILES+= cd5.0 +${PACKAGE}FILES+= cd6.0 +${PACKAGE}FILES+= cd7.0 +${PACKAGE}FILES+= cd8.0 +${PACKAGE}FILES+= cd9.0 cd9.0.stdout +${PACKAGE}FILES+= cd10.0 +${PACKAGE}FILES+= cd11.0 +${PACKAGE}FILES+= command1.0 +${PACKAGE}FILES+= command2.0 +${PACKAGE}FILES+= command3.0 +${PACKAGE}FILES+= command3.0.stdout +${PACKAGE}FILES+= command4.0 +${PACKAGE}FILES+= command5.0 +${PACKAGE}FILES+= command5.0.stdout +${PACKAGE}FILES+= command6.0 +${PACKAGE}FILES+= command6.0.stdout +${PACKAGE}FILES+= command7.0 +${PACKAGE}FILES+= command8.0 +${PACKAGE}FILES+= command9.0 +${PACKAGE}FILES+= command10.0 +${PACKAGE}FILES+= command11.0 +${PACKAGE}FILES+= command12.0 +${PACKAGE}FILES+= dot1.0 +${PACKAGE}FILES+= dot2.0 +${PACKAGE}FILES+= dot3.0 +${PACKAGE}FILES+= dot4.0 +${PACKAGE}FILES+= echo1.0 +${PACKAGE}FILES+= echo2.0 +${PACKAGE}FILES+= echo3.0 +${PACKAGE}FILES+= eval1.0 +${PACKAGE}FILES+= eval2.0 +${PACKAGE}FILES+= eval3.0 +${PACKAGE}FILES+= eval4.0 +${PACKAGE}FILES+= eval5.0 +${PACKAGE}FILES+= eval6.0 +${PACKAGE}FILES+= eval7.0 +${PACKAGE}FILES+= eval8.7 +${PACKAGE}FILES+= exec1.0 +${PACKAGE}FILES+= exec2.0 +${PACKAGE}FILES+= exit1.0 +${PACKAGE}FILES+= exit2.8 +${PACKAGE}FILES+= exit3.0 +${PACKAGE}FILES+= export1.0 +${PACKAGE}FILES+= fc1.0 +${PACKAGE}FILES+= fc2.0 +${PACKAGE}FILES+= for1.0 +${PACKAGE}FILES+= for2.0 +${PACKAGE}FILES+= for3.0 +${PACKAGE}FILES+= getopts1.0 getopts1.0.stdout +${PACKAGE}FILES+= getopts2.0 getopts2.0.stdout +${PACKAGE}FILES+= getopts3.0 +${PACKAGE}FILES+= getopts4.0 +${PACKAGE}FILES+= getopts5.0 +${PACKAGE}FILES+= getopts6.0 +${PACKAGE}FILES+= getopts7.0 +${PACKAGE}FILES+= getopts8.0 getopts8.0.stdout +${PACKAGE}FILES+= getopts9.0 getopts9.0.stdout +${PACKAGE}FILES+= getopts10.0 +${PACKAGE}FILES+= hash1.0 hash1.0.stdout +${PACKAGE}FILES+= hash2.0 hash2.0.stdout +${PACKAGE}FILES+= hash3.0 hash3.0.stdout +${PACKAGE}FILES+= hash4.0 +${PACKAGE}FILES+= jobid1.0 +${PACKAGE}FILES+= jobid2.0 +${PACKAGE}FILES+= kill1.0 kill2.0 +${PACKAGE}FILES+= lineno.0 lineno.0.stdout +${PACKAGE}FILES+= lineno2.0 +${PACKAGE}FILES+= lineno3.0 lineno3.0.stdout +${PACKAGE}FILES+= local1.0 +${PACKAGE}FILES+= local2.0 +${PACKAGE}FILES+= local3.0 +${PACKAGE}FILES+= local4.0 +${PACKAGE}FILES+= local5.0 +${PACKAGE}FILES+= local6.0 +${PACKAGE}FILES+= local7.0 +.if ${MK_NLS} != "no" +${PACKAGE}FILES+= locale1.0 +.endif +${PACKAGE}FILES+= locale2.0 +${PACKAGE}FILES+= printf1.0 +${PACKAGE}FILES+= printf2.0 +${PACKAGE}FILES+= printf3.0 +${PACKAGE}FILES+= printf4.0 +${PACKAGE}FILES+= read1.0 read1.0.stdout +${PACKAGE}FILES+= read2.0 +${PACKAGE}FILES+= read3.0 read3.0.stdout +${PACKAGE}FILES+= read4.0 read4.0.stdout +${PACKAGE}FILES+= read5.0 +${PACKAGE}FILES+= read6.0 +${PACKAGE}FILES+= read7.0 +${PACKAGE}FILES+= read8.0 +${PACKAGE}FILES+= read9.0 +${PACKAGE}FILES+= return1.0 +${PACKAGE}FILES+= return2.1 +${PACKAGE}FILES+= return3.1 +${PACKAGE}FILES+= return4.0 +${PACKAGE}FILES+= return5.0 +${PACKAGE}FILES+= return6.4 +${PACKAGE}FILES+= return7.4 +${PACKAGE}FILES+= return8.0 +${PACKAGE}FILES+= set1.0 +${PACKAGE}FILES+= set2.0 +${PACKAGE}FILES+= set3.0 +${PACKAGE}FILES+= trap1.0 +${PACKAGE}FILES+= trap10.0 +${PACKAGE}FILES+= trap11.0 +${PACKAGE}FILES+= trap12.0 +${PACKAGE}FILES+= trap13.0 +${PACKAGE}FILES+= trap14.0 +${PACKAGE}FILES+= trap15.0 +${PACKAGE}FILES+= trap16.0 +${PACKAGE}FILES+= trap17.0 +${PACKAGE}FILES+= trap2.0 +${PACKAGE}FILES+= trap3.0 +${PACKAGE}FILES+= trap4.0 +${PACKAGE}FILES+= trap5.0 +${PACKAGE}FILES+= trap6.0 +${PACKAGE}FILES+= trap7.0 +${PACKAGE}FILES+= trap8.0 +${PACKAGE}FILES+= trap9.0 +${PACKAGE}FILES+= type1.0 type1.0.stderr +${PACKAGE}FILES+= type2.0 +${PACKAGE}FILES+= type3.0 +${PACKAGE}FILES+= unalias.0 +${PACKAGE}FILES+= var-assign.0 +${PACKAGE}FILES+= var-assign2.0 +${PACKAGE}FILES+= wait1.0 +${PACKAGE}FILES+= wait2.0 +${PACKAGE}FILES+= wait3.0 +${PACKAGE}FILES+= wait4.0 +${PACKAGE}FILES+= wait5.0 +${PACKAGE}FILES+= wait6.0 +${PACKAGE}FILES+= wait7.0 +${PACKAGE}FILES+= wait8.0 +${PACKAGE}FILES+= wait9.127 +${PACKAGE}FILES+= wait10.0 + +.include <bsd.test.mk> diff --git a/bin/1sh/tests/builtins/Makefile.depend b/bin/1sh/tests/builtins/Makefile.depend new file mode 100644 index 00000000..60d10fe4 --- /dev/null +++ b/bin/1sh/tests/builtins/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/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/builtins/alias.0 b/bin/1sh/tests/builtins/alias.0 new file mode 100644 index 00000000..4337f897 --- /dev/null +++ b/bin/1sh/tests/builtins/alias.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/alias.0 190285 2009-03-22 21:12:00Z stefanf $ +set -e + +unalias -a +alias foo=bar +alias bar= +alias quux="1 2 3" +alias +alias foo diff --git a/bin/1sh/tests/builtins/alias.0.stdout b/bin/1sh/tests/builtins/alias.0.stdout new file mode 100644 index 00000000..52efaf0b --- /dev/null +++ b/bin/1sh/tests/builtins/alias.0.stdout @@ -0,0 +1,4 @@ +bar='' +foo=bar +quux='1 2 3' +foo=bar diff --git a/bin/1sh/tests/builtins/alias.1 b/bin/1sh/tests/builtins/alias.1 new file mode 100644 index 00000000..76615ade --- /dev/null +++ b/bin/1sh/tests/builtins/alias.1 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/alias.1 149781 2005-09-04 11:59:59Z stefanf $ +unalias -a +alias foo diff --git a/bin/1sh/tests/builtins/alias.1.stderr b/bin/1sh/tests/builtins/alias.1.stderr new file mode 100644 index 00000000..c9f4011b --- /dev/null +++ b/bin/1sh/tests/builtins/alias.1.stderr @@ -0,0 +1 @@ +alias: foo: not found diff --git a/bin/1sh/tests/builtins/alias3.0 b/bin/1sh/tests/builtins/alias3.0 new file mode 100644 index 00000000..cb0c2f78 --- /dev/null +++ b/bin/1sh/tests/builtins/alias3.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/alias3.0 242767 2012-11-08 13:36:19Z jilles $ +set -e + +unalias -a +alias foo=bar +alias bar= +alias quux="1 2 3" +alias foo=bar +alias bar= +alias quux="1 2 3" +alias +alias foo diff --git a/bin/1sh/tests/builtins/alias3.0.stdout b/bin/1sh/tests/builtins/alias3.0.stdout new file mode 100644 index 00000000..52efaf0b --- /dev/null +++ b/bin/1sh/tests/builtins/alias3.0.stdout @@ -0,0 +1,4 @@ +bar='' +foo=bar +quux='1 2 3' +foo=bar diff --git a/bin/1sh/tests/builtins/alias4.0 b/bin/1sh/tests/builtins/alias4.0 new file mode 100644 index 00000000..adc5724a --- /dev/null +++ b/bin/1sh/tests/builtins/alias4.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/alias4.0 254849 2013-08-25 11:42:53Z jilles $ + +unalias -a +alias -- diff --git a/bin/1sh/tests/builtins/break1.0 b/bin/1sh/tests/builtins/break1.0 new file mode 100644 index 00000000..ae59928e --- /dev/null +++ b/bin/1sh/tests/builtins/break1.0 @@ -0,0 +1,16 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/break1.0 211349 2010-08-15 21:06:53Z jilles $ + +if [ "$1" != nested ]; then + while :; do + set -- nested + . "$0" + echo bad2 + exit 2 + done + exit 0 +fi +# To trigger the bug, the following commands must be at the top level, +# with newlines in between. +break +echo bad1 +exit 1 diff --git a/bin/1sh/tests/builtins/break2.0 b/bin/1sh/tests/builtins/break2.0 new file mode 100644 index 00000000..521d504f --- /dev/null +++ b/bin/1sh/tests/builtins/break2.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/break2.0 211467 2010-08-18 20:26:50Z jilles $ + +# It is not immediately obvious that this should work, and someone probably +# relies on it. + +while :; do + trap 'break' USR1 + kill -USR1 $$ + echo bad + exit 1 +done +echo good diff --git a/bin/1sh/tests/builtins/break2.0.stdout b/bin/1sh/tests/builtins/break2.0.stdout new file mode 100644 index 00000000..12799ccb --- /dev/null +++ b/bin/1sh/tests/builtins/break2.0.stdout @@ -0,0 +1 @@ +good diff --git a/bin/1sh/tests/builtins/break3.0 b/bin/1sh/tests/builtins/break3.0 new file mode 100644 index 00000000..08105f9d --- /dev/null +++ b/bin/1sh/tests/builtins/break3.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/break3.0 211612 2010-08-22 11:07:46Z jilles $ + +# We accept this and people might rely on it. +# However, various other shells do not accept it. + +f() { + break + echo bad1 +} + +while :; do + f + echo bad2 + exit 2 +done diff --git a/bin/1sh/tests/builtins/break4.4 b/bin/1sh/tests/builtins/break4.4 new file mode 100644 index 00000000..e804e45d --- /dev/null +++ b/bin/1sh/tests/builtins/break4.4 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/break4.4 251180 2013-05-31 14:45:25Z jilles $ + +# Although this is not specified by POSIX, some configure scripts (gawk 4.1.0) +# appear to depend on it. + +break +exit 4 diff --git a/bin/1sh/tests/builtins/break5.4 b/bin/1sh/tests/builtins/break5.4 new file mode 100644 index 00000000..f4d25df6 --- /dev/null +++ b/bin/1sh/tests/builtins/break5.4 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/break5.4 251180 2013-05-31 14:45:25Z jilles $ + +# Although this is not specified by POSIX, some configure scripts (gawk 4.1.0) +# appear to depend on it. +# In some uncommitted code, the subshell environment corrupted the outer +# shell environment's state. + +(for i in a b c; do + exit 3 +done) +break +exit 4 diff --git a/bin/1sh/tests/builtins/break6.0 b/bin/1sh/tests/builtins/break6.0 new file mode 100644 index 00000000..f7fbc728 --- /dev/null +++ b/bin/1sh/tests/builtins/break6.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/break6.0 268927 2014-07-20 20:29:09Z jilles $ +# Per POSIX, this need only work if LONG_MAX > 4294967295. + +while :; do + break 4294967296 + echo bad + exit 3 +done diff --git a/bin/1sh/tests/builtins/builtin1.0 b/bin/1sh/tests/builtins/builtin1.0 new file mode 100644 index 00000000..8c997721 --- /dev/null +++ b/bin/1sh/tests/builtins/builtin1.0 @@ -0,0 +1,31 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/builtin1.0 201431 2010-01-03 15:01:38Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +builtin : || echo "Bad return code at $LINENO" +builtin true || echo "Bad return code at $LINENO" +builtin ls 2>/dev/null && echo "Bad return code at $LINENO" +check '"$(builtin pwd)" = "$(pwd)"' +check '-z "$(builtin :)"' +check '-z "$(builtin true)"' +check '-z "$( (builtin nosuchtool) 2>/dev/null)"' +check '-z "$(builtin nosuchtool 2>/dev/null)"' +check '-z "$(builtin nosuchtool 2>/dev/null; :)"' +check '-z "$( (builtin ls) 2>/dev/null)"' +check '-z "$(builtin ls 2>/dev/null)"' +check '-z "$(builtin ls 2>/dev/null; :)"' +check '-n "$( (builtin nosuchtool) 2>&1)"' +check '-n "$(builtin nosuchtool 2>&1)"' +check '-n "$(builtin nosuchtool 2>&1; :)"' +check '-n "$( (builtin ls) 2>&1)"' +check '-n "$(builtin ls 2>&1)"' +check '-n "$(builtin ls 2>&1; :)"' + +exit $((failures > 0)) diff --git a/bin/1sh/tests/builtins/case1.0 b/bin/1sh/tests/builtins/case1.0 new file mode 100644 index 00000000..fb03d18d --- /dev/null +++ b/bin/1sh/tests/builtins/case1.0 @@ -0,0 +1,13 @@ +#$FreeBSD: releng/12.1/bin/sh/tests/builtins/case1.0 172440 2007-10-04 16:14:48Z stefanf $ +f() +{ + false + case $1 in + foo) true ;; + bar) false ;; + esac +} + +f foo || exit 1 +f bar && exit 1 +f quux || exit 1 diff --git a/bin/1sh/tests/builtins/case10.0 b/bin/1sh/tests/builtins/case10.0 new file mode 100644 index 00000000..ded33163 --- /dev/null +++ b/bin/1sh/tests/builtins/case10.0 @@ -0,0 +1,16 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case10.0 223546 2011-06-25 20:37:43Z jilles $ + +case ! in +[\!!]) ;; +*) echo Failed at $LINENO ;; +esac + +case ! in +['!'!]) ;; +*) echo Failed at $LINENO ;; +esac + +case ! in +["!"!]) ;; +*) echo Failed at $LINENO ;; +esac diff --git a/bin/1sh/tests/builtins/case11.0 b/bin/1sh/tests/builtins/case11.0 new file mode 100644 index 00000000..c8b0624e --- /dev/null +++ b/bin/1sh/tests/builtins/case11.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case11.0 228007 2011-11-26 22:28:25Z jilles $ + +false +case x in +*) +esac diff --git a/bin/1sh/tests/builtins/case12.0 b/bin/1sh/tests/builtins/case12.0 new file mode 100644 index 00000000..0eebd805 --- /dev/null +++ b/bin/1sh/tests/builtins/case12.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case12.0 228007 2011-11-26 22:28:25Z jilles $ + +false +case x in +y) +esac diff --git a/bin/1sh/tests/builtins/case13.0 b/bin/1sh/tests/builtins/case13.0 new file mode 100644 index 00000000..c8aa9c1e --- /dev/null +++ b/bin/1sh/tests/builtins/case13.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case13.0 228943 2011-12-28 23:51:17Z jilles $ + +case ^ in +[\^^]) ;; +*) echo Failed at $LINENO ;; +esac + +case s in +[\^^]) echo Failed at $LINENO ;; +[s\]]) ;; +*) echo Failed at $LINENO ;; +esac diff --git a/bin/1sh/tests/builtins/case14.0 b/bin/1sh/tests/builtins/case14.0 new file mode 100644 index 00000000..6ac6f78e --- /dev/null +++ b/bin/1sh/tests/builtins/case14.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case14.0 230154 2012-01-15 20:04:05Z jilles $ + +case `false` in +no) exit 3 ;; +esac diff --git a/bin/1sh/tests/builtins/case15.0 b/bin/1sh/tests/builtins/case15.0 new file mode 100644 index 00000000..71f6f55c --- /dev/null +++ b/bin/1sh/tests/builtins/case15.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case15.0 230154 2012-01-15 20:04:05Z jilles $ + +case x in +`false`) exit 3 ;; +esac diff --git a/bin/1sh/tests/builtins/case16.0 b/bin/1sh/tests/builtins/case16.0 new file mode 100644 index 00000000..2a1e2fdf --- /dev/null +++ b/bin/1sh/tests/builtins/case16.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case16.0 230154 2012-01-15 20:04:05Z jilles $ + +f() { return 42; } +f +case x in +x) [ $? = 42 ] ;; +esac diff --git a/bin/1sh/tests/builtins/case17.0 b/bin/1sh/tests/builtins/case17.0 new file mode 100644 index 00000000..d27717ba --- /dev/null +++ b/bin/1sh/tests/builtins/case17.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case17.0 230161 2012-01-15 21:39:38Z jilles $ + +! case x in x) false ;& y) esac diff --git a/bin/1sh/tests/builtins/case18.0 b/bin/1sh/tests/builtins/case18.0 new file mode 100644 index 00000000..3a33646e --- /dev/null +++ b/bin/1sh/tests/builtins/case18.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case18.0 230161 2012-01-15 21:39:38Z jilles $ + +case x$(false) in +x) ;& +y) [ $? != 0 ] ;; +z) false ;; +esac diff --git a/bin/1sh/tests/builtins/case19.0 b/bin/1sh/tests/builtins/case19.0 new file mode 100644 index 00000000..fda14ac4 --- /dev/null +++ b/bin/1sh/tests/builtins/case19.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case19.0 230161 2012-01-15 21:39:38Z jilles $ + +[ "`case x in +x) false ;& +y) ;& +z) echo $? ;; +esac`" != 0 ] diff --git a/bin/1sh/tests/builtins/case2.0 b/bin/1sh/tests/builtins/case2.0 new file mode 100644 index 00000000..473943a1 --- /dev/null +++ b/bin/1sh/tests/builtins/case2.0 @@ -0,0 +1,106 @@ +# Generated by ./test-fnmatch -s 1, do not edit. +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case2.0 207821 2010-05-09 16:15:40Z jilles $ +failures= +failed() { printf '%s\n' "Failed: $1 '$2' '$3'"; failures=x$failures; } +testmatch() { eval "case \$2 in ''$1) ;; *) failed testmatch \"\$@\";; esac"; } +testnomatch() { eval "case \$2 in ''$1) failed testnomatch \"\$@\";; esac"; } +testmatch '' '' +testmatch 'a' 'a' +testnomatch 'a' 'b' +testnomatch 'a' 'A' +testmatch '*' 'a' +testmatch '*' 'aa' +testmatch '*a' 'a' +testnomatch '*a' 'b' +testnomatch '*a*' 'b' +testmatch '*a*b*' 'ab' +testmatch '*a*b*' 'qaqbq' +testmatch '*a*bb*' 'qaqbqbbq' +testmatch '*a*bc*' 'qaqbqbcq' +testmatch '*a*bb*' 'qaqbqbb' +testmatch '*a*bc*' 'qaqbqbc' +testmatch '*a*bb' 'qaqbqbb' +testmatch '*a*bc' 'qaqbqbc' +testnomatch '*a*bb' 'qaqbqbbq' +testnomatch '*a*bc' 'qaqbqbcq' +testnomatch '*a*a*a*a*a*a*a*a*a*a*' 'aaaaaaaaa' +testmatch '*a*a*a*a*a*a*a*a*a*a*' 'aaaaaaaaaa' +testmatch '*a*a*a*a*a*a*a*a*a*a*' 'aaaaaaaaaaa' +testnomatch '.*.*.*.*.*.*.*.*.*.*' '.........' +testmatch '.*.*.*.*.*.*.*.*.*.*' '..........' +testmatch '.*.*.*.*.*.*.*.*.*.*' '...........' +testnomatch '*?*?*?*?*?*?*?*?*?*?*' '123456789' +testnomatch '??????????*' '123456789' +testnomatch '*??????????' '123456789' +testmatch '*?*?*?*?*?*?*?*?*?*?*' '1234567890' +testmatch '??????????*' '1234567890' +testmatch '*??????????' '1234567890' +testmatch '*?*?*?*?*?*?*?*?*?*?*' '12345678901' +testmatch '??????????*' '12345678901' +testmatch '*??????????' '12345678901' +testmatch '[x]' 'x' +testmatch '[*]' '*' +testmatch '[?]' '?' +testmatch '[' '[' +testmatch '[[]' '[' +testnomatch '[[]' 'x' +testnomatch '[*]' '' +testnomatch '[*]' 'x' +testnomatch '[?]' 'x' +testmatch '*[*]*' 'foo*foo' +testnomatch '*[*]*' 'foo' +testmatch '[0-9]' '0' +testmatch '[0-9]' '5' +testmatch '[0-9]' '9' +testnomatch '[0-9]' '/' +testnomatch '[0-9]' ':' +testnomatch '[0-9]' '*' +testnomatch '[!0-9]' '0' +testnomatch '[!0-9]' '5' +testnomatch '[!0-9]' '9' +testmatch '[!0-9]' '/' +testmatch '[!0-9]' ':' +testmatch '[!0-9]' '*' +testmatch '*[0-9]' 'a0' +testmatch '*[0-9]' 'a5' +testmatch '*[0-9]' 'a9' +testnomatch '*[0-9]' 'a/' +testnomatch '*[0-9]' 'a:' +testnomatch '*[0-9]' 'a*' +testnomatch '*[!0-9]' 'a0' +testnomatch '*[!0-9]' 'a5' +testnomatch '*[!0-9]' 'a9' +testmatch '*[!0-9]' 'a/' +testmatch '*[!0-9]' 'a:' +testmatch '*[!0-9]' 'a*' +testmatch '*[0-9]' 'a00' +testmatch '*[0-9]' 'a55' +testmatch '*[0-9]' 'a99' +testmatch '*[0-9]' 'a0a0' +testmatch '*[0-9]' 'a5a5' +testmatch '*[0-9]' 'a9a9' +testmatch '\*' '*' +testmatch '\?' '?' +testmatch '\[x]' '[x]' +testmatch '\[' '[' +testmatch '\\' '\' +testmatch '*\**' 'foo*foo' +testnomatch '*\**' 'foo' +testmatch '*\\*' 'foo\foo' +testnomatch '*\\*' 'foo' +testmatch '\(' '(' +testmatch '\a' 'a' +testnomatch '\*' 'a' +testnomatch '\?' 'a' +testnomatch '\*' '\*' +testnomatch '\?' '\?' +testnomatch '\[x]' '\[x]' +testnomatch '\[x]' '\x' +testnomatch '\[' '\[' +testnomatch '\(' '\(' +testnomatch '\a' '\a' +testmatch '.*' '.' +testmatch '.*' '..' +testmatch '.*' '.a' +testmatch 'a*' 'a.' +[ -z "$failures" ] diff --git a/bin/1sh/tests/builtins/case20.0 b/bin/1sh/tests/builtins/case20.0 new file mode 100644 index 00000000..bbcf5605 --- /dev/null +++ b/bin/1sh/tests/builtins/case20.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case20.0 287148 2015-08-25 21:55:15Z jilles $ + +# Shells do not agree about what this pattern should match, but it is +# certain that it must not crash and the missing close bracket must not +# be simply ignored. + +case B in +[[:alpha:]) echo bad ;; +esac diff --git a/bin/1sh/tests/builtins/case21.0 b/bin/1sh/tests/builtins/case21.0 new file mode 100644 index 00000000..3158fb65 --- /dev/null +++ b/bin/1sh/tests/builtins/case21.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case21.0 318258 2017-05-13 20:28:32Z jilles $ + +case 5 in +[0$((-9))]) ;; +*) echo bad1 ;; +esac + +case - in +[0$((-9))]) echo bad2 ;; +esac diff --git a/bin/1sh/tests/builtins/case22.0 b/bin/1sh/tests/builtins/case22.0 new file mode 100644 index 00000000..740d2b4e --- /dev/null +++ b/bin/1sh/tests/builtins/case22.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case22.0 318269 2017-05-14 13:14:19Z jilles $ + +case 5 in +[0"$((-9))"]) echo bad1 ;; +esac + +case - in +[0"$((-9))"]) ;; +*) echo bad2 ;; +esac diff --git a/bin/1sh/tests/builtins/case23.0 b/bin/1sh/tests/builtins/case23.0 new file mode 100644 index 00000000..b9b2136e --- /dev/null +++ b/bin/1sh/tests/builtins/case23.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case23.0 333092 2018-04-29 17:46:08Z jilles $ + +case [ in +[[:alpha:]]) echo bad +esac diff --git a/bin/1sh/tests/builtins/case3.0 b/bin/1sh/tests/builtins/case3.0 new file mode 100644 index 00000000..c6b067ac --- /dev/null +++ b/bin/1sh/tests/builtins/case3.0 @@ -0,0 +1,95 @@ +# Generated by ./test-fnmatch -s 2, do not edit. +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case3.0 207821 2010-05-09 16:15:40Z jilles $ +failures= +failed() { printf '%s\n' "Failed: $1 '$2' '$3'"; failures=x$failures; } +# We do not treat a backslash specially in this case, +# but this is not the case in all shells. +netestmatch() { case $2 in $1) ;; *) failed netestmatch "$@";; esac; } +netestnomatch() { case $2 in $1) failed netestnomatch "$@";; esac; } +netestmatch '' '' +netestmatch 'a' 'a' +netestnomatch 'a' 'b' +netestnomatch 'a' 'A' +netestmatch '*' 'a' +netestmatch '*' 'aa' +netestmatch '*a' 'a' +netestnomatch '*a' 'b' +netestnomatch '*a*' 'b' +netestmatch '*a*b*' 'ab' +netestmatch '*a*b*' 'qaqbq' +netestmatch '*a*bb*' 'qaqbqbbq' +netestmatch '*a*bc*' 'qaqbqbcq' +netestmatch '*a*bb*' 'qaqbqbb' +netestmatch '*a*bc*' 'qaqbqbc' +netestmatch '*a*bb' 'qaqbqbb' +netestmatch '*a*bc' 'qaqbqbc' +netestnomatch '*a*bb' 'qaqbqbbq' +netestnomatch '*a*bc' 'qaqbqbcq' +netestnomatch '*a*a*a*a*a*a*a*a*a*a*' 'aaaaaaaaa' +netestmatch '*a*a*a*a*a*a*a*a*a*a*' 'aaaaaaaaaa' +netestmatch '*a*a*a*a*a*a*a*a*a*a*' 'aaaaaaaaaaa' +netestnomatch '.*.*.*.*.*.*.*.*.*.*' '.........' +netestmatch '.*.*.*.*.*.*.*.*.*.*' '..........' +netestmatch '.*.*.*.*.*.*.*.*.*.*' '...........' +netestnomatch '*?*?*?*?*?*?*?*?*?*?*' '123456789' +netestnomatch '??????????*' '123456789' +netestnomatch '*??????????' '123456789' +netestmatch '*?*?*?*?*?*?*?*?*?*?*' '1234567890' +netestmatch '??????????*' '1234567890' +netestmatch '*??????????' '1234567890' +netestmatch '*?*?*?*?*?*?*?*?*?*?*' '12345678901' +netestmatch '??????????*' '12345678901' +netestmatch '*??????????' '12345678901' +netestmatch '[x]' 'x' +netestmatch '[*]' '*' +netestmatch '[?]' '?' +netestmatch '[' '[' +netestmatch '[[]' '[' +netestnomatch '[[]' 'x' +netestnomatch '[*]' '' +netestnomatch '[*]' 'x' +netestnomatch '[?]' 'x' +netestmatch '*[*]*' 'foo*foo' +netestnomatch '*[*]*' 'foo' +netestmatch '[0-9]' '0' +netestmatch '[0-9]' '5' +netestmatch '[0-9]' '9' +netestnomatch '[0-9]' '/' +netestnomatch '[0-9]' ':' +netestnomatch '[0-9]' '*' +netestnomatch '[!0-9]' '0' +netestnomatch '[!0-9]' '5' +netestnomatch '[!0-9]' '9' +netestmatch '[!0-9]' '/' +netestmatch '[!0-9]' ':' +netestmatch '[!0-9]' '*' +netestmatch '*[0-9]' 'a0' +netestmatch '*[0-9]' 'a5' +netestmatch '*[0-9]' 'a9' +netestnomatch '*[0-9]' 'a/' +netestnomatch '*[0-9]' 'a:' +netestnomatch '*[0-9]' 'a*' +netestnomatch '*[!0-9]' 'a0' +netestnomatch '*[!0-9]' 'a5' +netestnomatch '*[!0-9]' 'a9' +netestmatch '*[!0-9]' 'a/' +netestmatch '*[!0-9]' 'a:' +netestmatch '*[!0-9]' 'a*' +netestmatch '*[0-9]' 'a00' +netestmatch '*[0-9]' 'a55' +netestmatch '*[0-9]' 'a99' +netestmatch '*[0-9]' 'a0a0' +netestmatch '*[0-9]' 'a5a5' +netestmatch '*[0-9]' 'a9a9' +netestmatch '\*' '\*' +netestmatch '\?' '\?' +netestmatch '\' '\' +netestnomatch '\\' '\' +netestmatch '\\' '\\' +netestmatch '*\*' 'foo\foo' +netestnomatch '*\*' 'foo' +netestmatch '.*' '.' +netestmatch '.*' '..' +netestmatch '.*' '.a' +netestmatch 'a*' 'a.' +[ -z "$failures" ] diff --git a/bin/1sh/tests/builtins/case4.0 b/bin/1sh/tests/builtins/case4.0 new file mode 100644 index 00000000..adea7d08 --- /dev/null +++ b/bin/1sh/tests/builtins/case4.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case4.0 220654 2011-04-15 15:14:58Z jilles $ + +set -- "*" +case x in +"$1") echo failed ;; +esac diff --git a/bin/1sh/tests/builtins/case5.0 b/bin/1sh/tests/builtins/case5.0 new file mode 100644 index 00000000..79eab7f4 --- /dev/null +++ b/bin/1sh/tests/builtins/case5.0 @@ -0,0 +1,57 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case5.0 221646 2011-05-08 11:32:20Z jilles $ + +unset LC_ALL +LC_CTYPE=en_US.UTF-8 +export LC_CTYPE + +c1=e +# a umlaut +c2=$(printf '\303\244') +# euro sign +c3=$(printf '\342\202\254') +# some sort of 't' outside BMP +c4=$(printf '\360\235\225\245') + +ok=0 +case $c1$c2$c3$c4 in +*) ok=1 ;; +esac +if [ $ok = 0 ]; then + echo wrong at $LINENO + exit 3 +fi + +case $c1$c2$c3$c4 in +$c1$c2$c3$c4) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2$c3$c4 in +"$c1$c2$c3$c4") ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2$c3$c4 in +????) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1.$c2.$c3.$c4 in +?.?.?.?) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2$c3$c4 in +[!a][!b][!c][!d]) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2$c3$c4 in +[$c1][$c2][$c3][$c4]) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2$c3$c4 in +["$c1"]["$c2"]["$c3"]["$c4"]) ;; +*) echo wrong at $LINENO ;; +esac diff --git a/bin/1sh/tests/builtins/case6.0 b/bin/1sh/tests/builtins/case6.0 new file mode 100644 index 00000000..4cc04a05 --- /dev/null +++ b/bin/1sh/tests/builtins/case6.0 @@ -0,0 +1,52 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case6.0 223007 2011-06-12 12:27:17Z jilles $ + +unset LC_ALL +LC_CTYPE=de_DE.ISO8859-1 +export LC_CTYPE + +c1=e +# o umlaut +c2=$(printf '\366') +# non-break space +c3=$(printf '\240') +c4=$(printf '\240') +# $c2$c3$c4 form one utf-8 character + +ok=0 +case $c1$c2$c3$c4 in +*) ok=1 ;; +esac +if [ $ok = 0 ]; then + echo wrong at $LINENO + exit 3 +fi + +case $c1$c2$c3$c4 in +$c1$c2$c3$c4) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2$c3$c4 in +"$c1$c2$c3$c4") ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2$c3$c4 in +????) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2$c3$c4 in +[!$c2][!b][!c][!d]) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2$c3$c4 in +[$c1][$c2][$c3][$c4]) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2$c3$c4 in +["$c1"]["$c2"]["$c3"]["$c4"]) ;; +*) echo wrong at $LINENO ;; +esac diff --git a/bin/1sh/tests/builtins/case7.0 b/bin/1sh/tests/builtins/case7.0 new file mode 100644 index 00000000..09d8689a --- /dev/null +++ b/bin/1sh/tests/builtins/case7.0 @@ -0,0 +1,24 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case7.0 302829 2016-07-14 09:34:42Z ache $ + +# Character ranges in a locale other than the POSIX locale, not specified +# by POSIX. + +unset LC_ALL +LC_CTYPE=de_DE.ISO8859-1 +export LC_CTYPE +LC_COLLATE=de_DE.ISO8859-1 +export LC_COLLATE + +c1=e +# o umlaut +c2=$(printf '\366') + +case $c1$c2 in +[a-z][a-z]) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2 in +[a-f][n-p]) ;; +*) echo wrong at $LINENO ;; +esac diff --git a/bin/1sh/tests/builtins/case8.0 b/bin/1sh/tests/builtins/case8.0 new file mode 100644 index 00000000..b1938bf0 --- /dev/null +++ b/bin/1sh/tests/builtins/case8.0 @@ -0,0 +1,32 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case8.0 223120 2011-06-15 21:48:10Z jilles $ + +case aZ_ in +[[:alpha:]_][[:upper:]_][[:alpha:]_]) ;; +*) echo Failed at $LINENO ;; +esac + +case ' ' in +[[:alpha:][:digit:]]) echo Failed at $LINENO ;; +[![:alpha:][:digit:]]) ;; +*) echo Failed at $LINENO ;; +esac + +case '.X.' in +*[[:lower:]]*) echo Failed at $LINENO ;; +*[[:upper:]]*) ;; +*) echo Failed at $LINENO ;; +esac + +case ' ' in +[![:print:]]) echo Failed at $LINENO ;; +[![:alnum:][:punct:]]) ;; +*) echo Failed at $LINENO ;; +esac + +case ' +' in +[[:print:]]) echo Failed at $LINENO ;; +[' +'[:digit:]]) ;; +*) echo Failed at $LINENO ;; +esac diff --git a/bin/1sh/tests/builtins/case9.0 b/bin/1sh/tests/builtins/case9.0 new file mode 100644 index 00000000..b415fb02 --- /dev/null +++ b/bin/1sh/tests/builtins/case9.0 @@ -0,0 +1,39 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/case9.0 223186 2011-06-17 13:03:49Z jilles $ + +errors=0 + +f() { + result= + case $1 in + a) result=${result}a ;; + b) result=${result}b ;& + c) result=${result}c ;& + d) result=${result}d ;; + e) result=${result}e ;& + esac +} + +check() { + f "$1" + if [ "$result" != "$2" ]; then + printf "For %s, expected %s got %s\n" "$1" "$2" "$result" + errors=$((errors + 1)) + fi +} + +check '' '' +check a a +check b bcd +check c cd +check d d +check e e + +if ! (case 1 in + 1) false ;& + 2) true ;; +esac) then + echo "Subshell bad" + errors=$((errors + 1)) +fi + +exit $((errors != 0)) diff --git a/bin/1sh/tests/builtins/cd1.0 b/bin/1sh/tests/builtins/cd1.0 new file mode 100644 index 00000000..8379e3c5 --- /dev/null +++ b/bin/1sh/tests/builtins/cd1.0 @@ -0,0 +1,30 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd1.0 228975 2011-12-30 00:04:11Z uqs $ +set -e + +P=${TMPDIR:-/tmp} +cd $P +T=$(mktemp -d sh-test.XXXXXX) + +chmod 0 $T +if [ `id -u` -ne 0 ]; then + # Root can always cd, regardless of directory permissions. + cd -L $T 2>/dev/null && exit 1 + [ "$PWD" = "$P" ] + [ "$(pwd)" = "$P" ] + cd -P $T 2>/dev/null && exit 1 + [ "$PWD" = "$P" ] + [ "$(pwd)" = "$P" ] +fi + +chmod 755 $T +cd $T +mkdir -p 1/2/3 +ln -s 1/2 link1 +ln -s 2/3 1/link2 +(cd -L 1/../1 && [ "$(pwd -L)" = "$P/$T/1" ]) +(cd -L link1 && [ "$(pwd -L)" = "$P/$T/link1" ]) +(cd -L link1 && [ "$(pwd -P)" = "$P/$T/1/2" ]) +(cd -P link1 && [ "$(pwd -L)" = "$P/$T/1/2" ]) +(cd -P link1 && [ "$(pwd -P)" = "$P/$T/1/2" ]) + +rm -rf ${P}/${T} diff --git a/bin/1sh/tests/builtins/cd10.0 b/bin/1sh/tests/builtins/cd10.0 new file mode 100644 index 00000000..0b90f36a --- /dev/null +++ b/bin/1sh/tests/builtins/cd10.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd10.0 320340 2017-06-25 21:53:08Z jilles $ + +# Precondition +(cd /bin) || exit +# Verify write error is ignored. +$SH +m -ic 'CDPATH=/:; cd bin 1</dev/null' diff --git a/bin/1sh/tests/builtins/cd11.0 b/bin/1sh/tests/builtins/cd11.0 new file mode 100644 index 00000000..ab310da0 --- /dev/null +++ b/bin/1sh/tests/builtins/cd11.0 @@ -0,0 +1,24 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd11.0 336320 2018-07-15 21:55:17Z jilles $ + +set -e +T=$(mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXX") +trap 'rm -rf "$T"' 0 + +mkdir "$T/%?^&*" +cd -P "$T/%?^&*" +D=$(pwd) + +mkdir a a/1 b b/1 b/2 + +CDPATH=$D/a: +# Basic test. +cd 1 >/dev/null +[ "$(pwd)" = "$D/a/1" ] +# Test that the current directory is not checked before CDPATH. +cd "$D/b" +cd 1 >/dev/null +[ "$(pwd)" = "$D/a/1" ] +# Test not using a CDPATH entry. +cd "$D/b" +cd 2 +[ "$(pwd)" = "$D/b/2" ] diff --git a/bin/1sh/tests/builtins/cd2.0 b/bin/1sh/tests/builtins/cd2.0 new file mode 100644 index 00000000..ea7e396b --- /dev/null +++ b/bin/1sh/tests/builtins/cd2.0 @@ -0,0 +1,16 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd2.0 216019 2010-11-28 22:49:58Z jilles $ +set -e + +L=$(getconf PATH_MAX / 2>/dev/null) || L=4096 +[ "$L" -lt 100000 ] 2>/dev/null || L=4096 +L=$((L+100)) +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) +trap 'rm -rf ${T}' 0 +cd $T +D=$T +while [ ${#D} -lt $L ]; do + mkdir veryverylongdirectoryname + cd veryverylongdirectoryname + D=$D/veryverylongdirectoryname +done +[ $(pwd | wc -c) -eq $((${#D} + 1)) ] # +\n diff --git a/bin/1sh/tests/builtins/cd3.0 b/bin/1sh/tests/builtins/cd3.0 new file mode 100644 index 00000000..09aa74ca --- /dev/null +++ b/bin/1sh/tests/builtins/cd3.0 @@ -0,0 +1,21 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd3.0 222154 2011-05-20 22:55:18Z jilles $ + +# If fully successful, cd -Pe must be like cd -P. + +set -e + +cd "${TMPDIR:-/tmp}" +cd -Pe / +[ "$PWD" = / ] +[ "$(pwd)" = / ] +cd "${TMPDIR:-/tmp}" +cd -eP / +[ "$PWD" = / ] +[ "$(pwd)" = / ] + +set +e + +# If cd -Pe cannot chdir, the exit status must be greater than 1. + +v=$( (cd -Pe /var/empty/nonexistent) 2>&1 >/dev/null) +[ $? -gt 1 ] && [ -n "$v" ] diff --git a/bin/1sh/tests/builtins/cd4.0 b/bin/1sh/tests/builtins/cd4.0 new file mode 100644 index 00000000..ba32302e --- /dev/null +++ b/bin/1sh/tests/builtins/cd4.0 @@ -0,0 +1,38 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd4.0 222154 2011-05-20 22:55:18Z jilles $ + +# This test assumes that whatever mechanism cd -P uses to determine the +# pathname to the current directory if it is longer than PATH_MAX requires +# read permission on all parent directories. It also works if this +# requirement always applies. + +set -e +L=$(getconf PATH_MAX / 2>/dev/null) || L=4096 +[ "$L" -lt 100000 ] 2>/dev/null || L=4096 +L=$((L+100)) +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) +trap 'chmod u+r ${T}; rm -rf ${T}' 0 +cd -Pe $T +D=$(pwd) +chmod u-r "$D" +if [ -r "$D" ]; then + # Running as root, cannot test. + exit 0 +fi +set +e +while [ ${#D} -lt $L ]; do + mkdir veryverylongdirectoryname || exit + cd -Pe veryverylongdirectoryname 2>/dev/null + r=$? + [ $r -gt 1 ] && exit $r + if [ $r -eq 1 ]; then + # Verify that the directory was changed correctly. + cd -Pe .. || exit + [ "$(pwd)" = "$D" ] || exit + # Verify that omitting -e results in success. + cd -P veryverylongdirectoryname 2>/dev/null || exit + exit 0 + fi + D=$D/veryverylongdirectoryname +done +echo "cd -Pe never returned 1" +exit 0 diff --git a/bin/1sh/tests/builtins/cd5.0 b/bin/1sh/tests/builtins/cd5.0 new file mode 100644 index 00000000..9a9fbf4d --- /dev/null +++ b/bin/1sh/tests/builtins/cd5.0 @@ -0,0 +1,23 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd5.0 222379 2011-05-27 19:36:07Z jilles $ + +set -e +T=$(mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXX") +trap 'rm -rf "$T"' 0 + +cd -P "$T" +D=$(pwd) + +mkdir a a/1 b b/1 b/2 + +CDPATH=$D/a: +# Basic test. +cd 1 >/dev/null +[ "$(pwd)" = "$D/a/1" ] +# Test that the current directory is not checked before CDPATH. +cd "$D/b" +cd 1 >/dev/null +[ "$(pwd)" = "$D/a/1" ] +# Test not using a CDPATH entry. +cd "$D/b" +cd 2 +[ "$(pwd)" = "$D/b/2" ] diff --git a/bin/1sh/tests/builtins/cd6.0 b/bin/1sh/tests/builtins/cd6.0 new file mode 100644 index 00000000..7bfa20be --- /dev/null +++ b/bin/1sh/tests/builtins/cd6.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd6.0 222381 2011-05-27 20:01:46Z jilles $ + +set -e +cd -P /bin +d=$PWD +CDPATH=/: +cd -P . +[ "$d" = "$PWD" ] +cd -P ./ +[ "$d" = "$PWD" ] diff --git a/bin/1sh/tests/builtins/cd7.0 b/bin/1sh/tests/builtins/cd7.0 new file mode 100644 index 00000000..b5a522aa --- /dev/null +++ b/bin/1sh/tests/builtins/cd7.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd7.0 222381 2011-05-27 20:01:46Z jilles $ + +set -e +cd /usr/bin +[ "$PWD" = /usr/bin ] +CDPATH=/: +cd . +[ "$PWD" = /usr/bin ] +cd ./ +[ "$PWD" = /usr/bin ] +cd .. +[ "$PWD" = /usr ] +cd /usr/bin +cd ../ +[ "$PWD" = /usr ] diff --git a/bin/1sh/tests/builtins/cd8.0 b/bin/1sh/tests/builtins/cd8.0 new file mode 100644 index 00000000..477616da --- /dev/null +++ b/bin/1sh/tests/builtins/cd8.0 @@ -0,0 +1,26 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd8.0 230095 2012-01-13 23:32:27Z jilles $ + +# The exact wording of the error message is not standardized, but giving +# a description of the errno is useful. + +LC_ALL=C +export LC_ALL +r=0 + +t() { + exec 3>&1 + errmsg=`cd "$1" 2>&1 >&3 3>&-` + exec 3>&- + case $errmsg in + *[Nn]ot\ a\ directory*) + ;; + *) + printf "Wrong error message for %s: %s\n" "$1" "$errmsg" + r=3 + ;; + esac +} + +t /dev/tty +t /dev/tty/x +exit $r diff --git a/bin/1sh/tests/builtins/cd9.0 b/bin/1sh/tests/builtins/cd9.0 new file mode 100644 index 00000000..f3ccfb70 --- /dev/null +++ b/bin/1sh/tests/builtins/cd9.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/cd9.0 293371 2016-01-07 21:46:07Z jilles $ + +cd /dev +cd /bin +cd - >/dev/null +pwd +cd - >/dev/null +pwd diff --git a/bin/1sh/tests/builtins/cd9.0.stdout b/bin/1sh/tests/builtins/cd9.0.stdout new file mode 100644 index 00000000..dac16a76 --- /dev/null +++ b/bin/1sh/tests/builtins/cd9.0.stdout @@ -0,0 +1,2 @@ +/dev +/bin diff --git a/bin/1sh/tests/builtins/command1.0 b/bin/1sh/tests/builtins/command1.0 new file mode 100644 index 00000000..497ffdf5 --- /dev/null +++ b/bin/1sh/tests/builtins/command1.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command1.0 151797 2005-10-28 14:02:42Z stefanf $ +true() { + false +} +command true diff --git a/bin/1sh/tests/builtins/command10.0 b/bin/1sh/tests/builtins/command10.0 new file mode 100644 index 00000000..b043be14 --- /dev/null +++ b/bin/1sh/tests/builtins/command10.0 @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command10.0 204802 2010-03-06 17:31:09Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '"$(f() { shift x; }; { command eval f 2>/dev/null; } >/dev/null; echo hi)" = hi' + +exit $((failures > 0)) diff --git a/bin/1sh/tests/builtins/command11.0 b/bin/1sh/tests/builtins/command11.0 new file mode 100644 index 00000000..14cdae27 --- /dev/null +++ b/bin/1sh/tests/builtins/command11.0 @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command11.0 205154 2010-03-14 14:24:35Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '"$({ command eval \{ shift x\; \} 2\>/dev/null; } >/dev/null; echo hi)" = hi' + +exit $((failures > 0)) diff --git a/bin/1sh/tests/builtins/command12.0 b/bin/1sh/tests/builtins/command12.0 new file mode 100644 index 00000000..865f690b --- /dev/null +++ b/bin/1sh/tests/builtins/command12.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command12.0 257929 2013-11-10 23:00:39Z jilles $ + +alias aa=echo\ \'\"\' +cmd=$(command -v aa) +alias aa=echo\ bad +eval "$cmd" +[ "$(eval aa)" = \" ] diff --git a/bin/1sh/tests/builtins/command2.0 b/bin/1sh/tests/builtins/command2.0 new file mode 100644 index 00000000..6994b584 --- /dev/null +++ b/bin/1sh/tests/builtins/command2.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command2.0 151797 2005-10-28 14:02:42Z stefanf $ +PATH= +command -p cat < /dev/null diff --git a/bin/1sh/tests/builtins/command3.0 b/bin/1sh/tests/builtins/command3.0 new file mode 100644 index 00000000..20d56604 --- /dev/null +++ b/bin/1sh/tests/builtins/command3.0 @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command3.0 211399 2010-08-16 17:18:08Z jilles $ +command -v ls +command -v true +command -v /bin/ls + +fun() { + : +} +command -v fun +command -v break +command -v if + +alias foo=bar +command -v foo diff --git a/bin/1sh/tests/builtins/command3.0.stdout b/bin/1sh/tests/builtins/command3.0.stdout new file mode 100644 index 00000000..67b86915 --- /dev/null +++ b/bin/1sh/tests/builtins/command3.0.stdout @@ -0,0 +1,7 @@ +/bin/ls +true +/bin/ls +fun +break +if +alias foo=bar diff --git a/bin/1sh/tests/builtins/command4.0 b/bin/1sh/tests/builtins/command4.0 new file mode 100644 index 00000000..fa7ab6ce --- /dev/null +++ b/bin/1sh/tests/builtins/command4.0 @@ -0,0 +1,2 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command4.0 211973 2010-08-29 20:53:24Z jilles $ +! command -v nonexisting diff --git a/bin/1sh/tests/builtins/command5.0 b/bin/1sh/tests/builtins/command5.0 new file mode 100644 index 00000000..e99a36fe --- /dev/null +++ b/bin/1sh/tests/builtins/command5.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command5.0 211399 2010-08-16 17:18:08Z jilles $ +command -V ls +command -V true +command -V /bin/ls + +fun() { + : +} +command -V fun +command -V break +command -V if +command -V { + +alias foo=bar +command -V foo diff --git a/bin/1sh/tests/builtins/command5.0.stdout b/bin/1sh/tests/builtins/command5.0.stdout new file mode 100644 index 00000000..523f7b22 --- /dev/null +++ b/bin/1sh/tests/builtins/command5.0.stdout @@ -0,0 +1,8 @@ +ls is /bin/ls +true is a shell builtin +/bin/ls is /bin/ls +fun is a shell function +break is a special shell builtin +if is a shell keyword +{ is a shell keyword +foo is an alias for bar diff --git a/bin/1sh/tests/builtins/command6.0 b/bin/1sh/tests/builtins/command6.0 new file mode 100644 index 00000000..3f762875 --- /dev/null +++ b/bin/1sh/tests/builtins/command6.0 @@ -0,0 +1,22 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command6.0 218356 2011-02-05 23:00:24Z jilles $ +PATH=/var/empty +case $(command -pV ls) in +*/var/empty/ls*) + echo "Failed: \$(command -pV ls) should not match */var/empty/ls*" ;; +"ls is"*" "/*/ls) ;; +*) + echo "Failed: \$(command -pV ls) match \"ls is\"*\" \"/*/ls" ;; +esac +command -pV true +command -pV /bin/ls + +fun() { + : +} +command -pV fun +command -pV break +command -pV if +command -pV { + +alias foo=bar +command -pV foo diff --git a/bin/1sh/tests/builtins/command6.0.stdout b/bin/1sh/tests/builtins/command6.0.stdout new file mode 100644 index 00000000..3180207a --- /dev/null +++ b/bin/1sh/tests/builtins/command6.0.stdout @@ -0,0 +1,7 @@ +true is a shell builtin +/bin/ls is /bin/ls +fun is a shell function +break is a special shell builtin +if is a shell keyword +{ is a shell keyword +foo is an alias for bar diff --git a/bin/1sh/tests/builtins/command7.0 b/bin/1sh/tests/builtins/command7.0 new file mode 100644 index 00000000..213c2c50 --- /dev/null +++ b/bin/1sh/tests/builtins/command7.0 @@ -0,0 +1,34 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command7.0 218356 2011-02-05 23:00:24Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '"$(PATH=/libexec command -V ld-elf.so.1)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"' +check '"$(PATH=/libexec command -V ld-elf.so.1; :)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"' +check '"$(PATH=/libexec command -pv ld-elf.so.1)" = ""' +check '"$(PATH=/libexec command -pv ld-elf.so.1; :)" = ""' + +PATH=/libexec:$PATH + +check '"$(command -V ld-elf.so.1)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"' +check '"$(command -V ld-elf.so.1; :)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"' +check '"$(command -pv ld-elf.so.1)" = ""' +check '"$(command -pv ld-elf.so.1; :)" = ""' + +PATH=/libexec + +check '"$(command -v ls)" = ""' +case $(command -pv ls) in +/*/ls) ;; +*) + echo "Failed: \$(command -pv ls) match /*/ls" + : $((failures += 1)) ;; +esac + +exit $((failures > 0)) diff --git a/bin/1sh/tests/builtins/command8.0 b/bin/1sh/tests/builtins/command8.0 new file mode 100644 index 00000000..f8350092 --- /dev/null +++ b/bin/1sh/tests/builtins/command8.0 @@ -0,0 +1,45 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command8.0 213738 2010-10-12 18:20:38Z obrien $ +IFS=, + +SPECIAL="break,\ + :,\ + continue,\ + . /dev/null,\ + eval,\ + exec,\ + export -p,\ + readonly -p,\ + set,\ + shift 0,\ + times,\ + trap,\ + unset foo" + +set -e + +# Check that special builtins can be executed via "command". + +set -- ${SPECIAL} +for cmd in "$@" +do + ${SH} -c "v=:; while \$v; do v=false; command ${cmd}; done" >/dev/null +done + +while :; do + command break + echo Error on line $LINENO +done + +set p q r +command shift 2 +if [ $# -ne 1 ]; then + echo Error on line $LINENO +fi + +( + command exec >/dev/null + echo Error on line $LINENO +) + +set +e +! command shift 2 2>/dev/null diff --git a/bin/1sh/tests/builtins/command9.0 b/bin/1sh/tests/builtins/command9.0 new file mode 100644 index 00000000..704415f8 --- /dev/null +++ b/bin/1sh/tests/builtins/command9.0 @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/command9.0 204801 2010-03-06 17:09:22Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '"$({ command eval shift x 2>/dev/null; } >/dev/null; echo hi)" = hi' + +exit $((failures > 0)) diff --git a/bin/1sh/tests/builtins/dot1.0 b/bin/1sh/tests/builtins/dot1.0 new file mode 100644 index 00000000..e714e57a --- /dev/null +++ b/bin/1sh/tests/builtins/dot1.0 @@ -0,0 +1,21 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/dot1.0 208629 2010-05-28 22:08:34Z jilles $ + +failures= +failure() { + echo "Error at line $1" >&2 + failures=x$failures +} + +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) || exit +trap 'rm -rf $T' 0 +cd $T || exit 3 +unset x +echo 'x=2' >testscript +. ./testscript +[ "$x" = 2 ] || failure $LINENO +cd / || exit 3 +x=1 +PATH=$T:$PATH . testscript +[ "$x" = 2 ] || failure $LINENO + +test -z "$failures" diff --git a/bin/1sh/tests/builtins/dot2.0 b/bin/1sh/tests/builtins/dot2.0 new file mode 100644 index 00000000..e3b39569 --- /dev/null +++ b/bin/1sh/tests/builtins/dot2.0 @@ -0,0 +1,21 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/dot2.0 208630 2010-05-28 22:40:24Z jilles $ + +failures= +failure() { + echo "Error at line $1" >&2 + failures=x$failures +} + +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) || exit +trap 'rm -rf $T' 0 +cd $T || exit 3 +unset x +echo 'x=2' >testscript +. -- ./testscript +[ "$x" = 2 ] || failure $LINENO +cd / || exit 3 +x=1 +PATH=$T:$PATH . -- testscript +[ "$x" = 2 ] || failure $LINENO + +test -z "$failures" diff --git a/bin/1sh/tests/builtins/dot3.0 b/bin/1sh/tests/builtins/dot3.0 new file mode 100644 index 00000000..7759666e --- /dev/null +++ b/bin/1sh/tests/builtins/dot3.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/dot3.0 219390 2011-03-07 23:52:23Z jilles $ + +# . should return 0 if no command was executed. + +if false; then + exit 3 +else + . /dev/null + exit $? +fi diff --git a/bin/1sh/tests/builtins/dot4.0 b/bin/1sh/tests/builtins/dot4.0 new file mode 100644 index 00000000..60b6ff4c --- /dev/null +++ b/bin/1sh/tests/builtins/dot4.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/dot4.0 222174 2011-05-22 12:15:14Z jilles $ + +v=abcd +v=$v$v$v$v +v=$v$v$v$v +v=$v$v$v$v +v=$v$v$v$v +v=$v$v$v$v +r=$( ( + trap 'exit 0' 0 + . "$v" +) 2>&1 >/dev/null) && [ -n "$r" ] diff --git a/bin/1sh/tests/builtins/echo1.0 b/bin/1sh/tests/builtins/echo1.0 new file mode 100644 index 00000000..98a5b8bd --- /dev/null +++ b/bin/1sh/tests/builtins/echo1.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/echo1.0 305305 2016-09-02 21:13:46Z jilles $ + +# Not specified by POSIX. + +[ "`echo -n a b; echo c d; echo e f`" = "a bc d +e f" ] diff --git a/bin/1sh/tests/builtins/echo2.0 b/bin/1sh/tests/builtins/echo2.0 new file mode 100644 index 00000000..a7521a62 --- /dev/null +++ b/bin/1sh/tests/builtins/echo2.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/echo2.0 305305 2016-09-02 21:13:46Z jilles $ + +# Not specified by POSIX. + +a=`echo -e '\a\b\e\f\n\r\t\v\\\\\0041\c'; echo .` +b=`printf '\a\b\033\f\n\r\t\v\\\\!.'` +[ "$a" = "$b" ] diff --git a/bin/1sh/tests/builtins/echo3.0 b/bin/1sh/tests/builtins/echo3.0 new file mode 100644 index 00000000..c77eeb85 --- /dev/null +++ b/bin/1sh/tests/builtins/echo3.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/echo3.0 305305 2016-09-02 21:13:46Z jilles $ + +# Not specified by POSIX. + +[ "`echo -e 'a\cb' c; echo d`" = "ad" ] diff --git a/bin/1sh/tests/builtins/eval1.0 b/bin/1sh/tests/builtins/eval1.0 new file mode 100644 index 00000000..5e2e2e8e --- /dev/null +++ b/bin/1sh/tests/builtins/eval1.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/eval1.0 193178 2009-05-31 17:23:27Z stefanf $ +set -e + +eval +eval "" "" +eval "true" +! eval "false + +" diff --git a/bin/1sh/tests/builtins/eval2.0 b/bin/1sh/tests/builtins/eval2.0 new file mode 100644 index 00000000..0bb5fa7a --- /dev/null +++ b/bin/1sh/tests/builtins/eval2.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/eval2.0 194897 2009-06-24 20:22:54Z jilles $ + +eval ' +false + +' && exit 1 +exit 0 diff --git a/bin/1sh/tests/builtins/eval3.0 b/bin/1sh/tests/builtins/eval3.0 new file mode 100644 index 00000000..d9da6bc1 --- /dev/null +++ b/bin/1sh/tests/builtins/eval3.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/eval3.0 196607 2009-08-27 22:23:23Z jilles $ + +eval 'false;' && exit 1 +eval 'true;' || exit 1 +eval 'false; +' && exit 1 +eval 'true; +' || exit 1 +exit 0 diff --git a/bin/1sh/tests/builtins/eval4.0 b/bin/1sh/tests/builtins/eval4.0 new file mode 100644 index 00000000..2591e3d7 --- /dev/null +++ b/bin/1sh/tests/builtins/eval4.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/eval4.0 210738 2010-08-01 22:39:07Z jilles $ + +# eval should preserve $? from command substitutions when starting +# the parsed command. +[ $(eval 'echo $?' $(false)) = 1 ] diff --git a/bin/1sh/tests/builtins/eval5.0 b/bin/1sh/tests/builtins/eval5.0 new file mode 100644 index 00000000..a00f4de6 --- /dev/null +++ b/bin/1sh/tests/builtins/eval5.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/eval5.0 210829 2010-08-03 22:17:29Z jilles $ + +# eval should return 0 if no command was executed. +eval $(false) diff --git a/bin/1sh/tests/builtins/eval6.0 b/bin/1sh/tests/builtins/eval6.0 new file mode 100644 index 00000000..7a0548e5 --- /dev/null +++ b/bin/1sh/tests/builtins/eval6.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/eval6.0 249220 2013-04-06 22:30:46Z jilles $ + +# eval should preserve $? from command substitutions when starting +# the parsed command. +[ $(false; eval 'echo $?' $(:)) = 0 ] diff --git a/bin/1sh/tests/builtins/eval7.0 b/bin/1sh/tests/builtins/eval7.0 new file mode 100644 index 00000000..b9b09d5a --- /dev/null +++ b/bin/1sh/tests/builtins/eval7.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/eval7.0 272983 2014-10-12 13:12:06Z jilles $ +# Assumes that break can break out of a loop outside eval. + +while :; do + eval "break +echo bad1" + echo bad2 + exit 3 +done diff --git a/bin/1sh/tests/builtins/eval8.7 b/bin/1sh/tests/builtins/eval8.7 new file mode 100644 index 00000000..7420386e --- /dev/null +++ b/bin/1sh/tests/builtins/eval8.7 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/eval8.7 272983 2014-10-12 13:12:06Z jilles $ + +f() { + eval "return 7 +echo bad2" +} +f diff --git a/bin/1sh/tests/builtins/exec1.0 b/bin/1sh/tests/builtins/exec1.0 new file mode 100644 index 00000000..b4932749 --- /dev/null +++ b/bin/1sh/tests/builtins/exec1.0 @@ -0,0 +1,25 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/exec1.0 213738 2010-10-12 18:20:38Z obrien $ + +failures= +failure() { + echo "Error at line $1" >&2 + failures=x$failures +} + +( + exec >/dev/null + echo bad +) +[ $? = 0 ] || failure $LINENO +( + exec ${SH} -c 'exit 42' + echo bad +) +[ $? = 42 ] || failure $LINENO +( + exec /var/empty/nosuch + echo bad +) 2>/dev/null +[ $? = 127 ] || failure $LINENO + +test -z "$failures" diff --git a/bin/1sh/tests/builtins/exec2.0 b/bin/1sh/tests/builtins/exec2.0 new file mode 100644 index 00000000..93d32b13 --- /dev/null +++ b/bin/1sh/tests/builtins/exec2.0 @@ -0,0 +1,25 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/exec2.0 213738 2010-10-12 18:20:38Z obrien $ + +failures= +failure() { + echo "Error at line $1" >&2 + failures=x$failures +} + +( + exec -- >/dev/null + echo bad +) +[ $? = 0 ] || failure $LINENO +( + exec -- ${SH} -c 'exit 42' + echo bad +) +[ $? = 42 ] || failure $LINENO +( + exec -- /var/empty/nosuch + echo bad +) 2>/dev/null +[ $? = 127 ] || failure $LINENO + +test -z "$failures" diff --git a/bin/1sh/tests/builtins/exit1.0 b/bin/1sh/tests/builtins/exit1.0 new file mode 100644 index 00000000..45b7b0ec --- /dev/null +++ b/bin/1sh/tests/builtins/exit1.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/exit1.0 216871 2011-01-01 15:25:15Z jilles $ + +# exit with an argument should overwrite the exit status in an EXIT trap. + +trap 'true; exit $?' 0 +false diff --git a/bin/1sh/tests/builtins/exit2.8 b/bin/1sh/tests/builtins/exit2.8 new file mode 100644 index 00000000..d5f97159 --- /dev/null +++ b/bin/1sh/tests/builtins/exit2.8 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/exit2.8 217172 2011-01-08 23:00:38Z jilles $ + +# exit without arguments is the same as exit $? outside a trap. + +trap 'true; true' 0 +(exit 8) +exit diff --git a/bin/1sh/tests/builtins/exit3.0 b/bin/1sh/tests/builtins/exit3.0 new file mode 100644 index 00000000..c3835a46 --- /dev/null +++ b/bin/1sh/tests/builtins/exit3.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/exit3.0 217175 2011-01-08 23:08:13Z jilles $ + +# exit without arguments differs from exit $? in an EXIT trap. + +trap 'false; exit' 0 diff --git a/bin/1sh/tests/builtins/export1.0 b/bin/1sh/tests/builtins/export1.0 new file mode 100644 index 00000000..35ec714f --- /dev/null +++ b/bin/1sh/tests/builtins/export1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/export1.0 223183 2011-06-17 10:21:24Z jilles $ + +env @badness=1 ${SH} -c 'v=`export -p`; eval "$v"' diff --git a/bin/1sh/tests/builtins/fc1.0 b/bin/1sh/tests/builtins/fc1.0 new file mode 100644 index 00000000..86b6afe8 --- /dev/null +++ b/bin/1sh/tests/builtins/fc1.0 @@ -0,0 +1,27 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/fc1.0 213738 2010-10-12 18:20:38Z obrien $ +set -e +trap 'echo Broken pipe -- test failed' PIPE + +P=${TMPDIR:-/tmp} +cd $P +T=$(mktemp -d sh-test.XXXXXX) +cd $T + +mkfifo input output error +HISTFILE=/dev/null ${SH} +m -i <input >output 2>error & +{ + # Syntax error + echo ')' >&3 + # Read error message, shell will read new input now + read dummy <&5 + # Execute bad command again + echo 'fc -e true' >&3 + # Verify that the shell is still running + echo 'echo continued' >&3 || rc=3 + echo 'exit' >&3 || rc=3 + read line <&4 && [ "$line" = continued ] && : ${rc:=0} +} 3>input 4<output 5<error + +rm input output error +rmdir ${P}/${T} +exit ${rc:-3} diff --git a/bin/1sh/tests/builtins/fc2.0 b/bin/1sh/tests/builtins/fc2.0 new file mode 100644 index 00000000..ac267566 --- /dev/null +++ b/bin/1sh/tests/builtins/fc2.0 @@ -0,0 +1,34 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/fc2.0 213738 2010-10-12 18:20:38Z obrien $ +set -e +trap 'echo Broken pipe -- test failed' PIPE + +P=${TMPDIR:-/tmp} +cd $P +T=$(mktemp -d sh-test.XXXXXX) +cd $T + +mkfifo input output error +HISTFILE=/dev/null ${SH} +m -i <input >output 2>error & +exec 3>input +{ + # Command not found, containing slash + echo '/var/empty/nonexistent' >&3 + # Read error message, shell will read new input now + read dummy <&5 + # Execute bad command again + echo 'fc -e true; echo continued' >&3 + read dummy <&5 + read line <&4 && [ "$line" = continued ] && : ${rc:=0} + exec 3>&- + # Old sh duplicates itself after the fc, producing another line + # of output. + if read line <&4; then + echo "Extraneous output: $line" + rc=1 + fi +} 4<output 5<error +exec 3>&- + +rm input output error +rmdir ${P}/${T} +exit ${rc:-3} diff --git a/bin/1sh/tests/builtins/for1.0 b/bin/1sh/tests/builtins/for1.0 new file mode 100644 index 00000000..7906a193 --- /dev/null +++ b/bin/1sh/tests/builtins/for1.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/for1.0 226892 2011-10-28 23:02:21Z jilles $ + +false +for i in `false`; do exit 3; done diff --git a/bin/1sh/tests/builtins/for2.0 b/bin/1sh/tests/builtins/for2.0 new file mode 100644 index 00000000..b4c59710 --- /dev/null +++ b/bin/1sh/tests/builtins/for2.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/for2.0 230463 2012-01-22 14:00:33Z jilles $ + +r=x +f() { return 42; } +f +for i in x; do + r=$? +done +[ "$r" = 42 ] diff --git a/bin/1sh/tests/builtins/for3.0 b/bin/1sh/tests/builtins/for3.0 new file mode 100644 index 00000000..0e07a2a2 --- /dev/null +++ b/bin/1sh/tests/builtins/for3.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/for3.0 230463 2012-01-22 14:00:33Z jilles $ + +r=x +f() { return 42; } +for i in x`f`; do + r=$? +done +[ "$r" = 42 ] diff --git a/bin/1sh/tests/builtins/getopts1.0 b/bin/1sh/tests/builtins/getopts1.0 new file mode 100644 index 00000000..99cc05b3 --- /dev/null +++ b/bin/1sh/tests/builtins/getopts1.0 @@ -0,0 +1,25 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/getopts1.0 297752 2016-04-09 16:06:13Z jilles $ + +printf -- '-1-\n' +set -- -abc +getopts "ab:" OPTION +printf '%s\n' "${OPTION}" + +# In this case 'getopts' should realize that we have not provided the +# required argument for "-b". +# Note that Solaris 10's (UNIX 03) /usr/xpg4/bin/sh, /bin/sh, and /bin/ksh; +# ksh93 20090505; pdksh 5.2.14p2; mksh R39c; bash 4.1 PL7; and zsh 4.3.10. +# all recognize that "b" is missing its argument on the *first* iteration +# of 'getopts' and do not produce the "a" in $OPTION. +printf -- '-2-\n' +set -- -ab +getopts "ab:" OPTION +printf '%s\n' "${OPTION}" +getopts "ab:" OPTION 3>&2 2>&1 >&3 3>&- +printf '%s\n' "${OPTION}" + +# The 'shift' is aimed at causing an error. +printf -- '-3-\n' +shift 1 +getopts "ab:" OPTION +printf '%s\n' "${OPTION}" diff --git a/bin/1sh/tests/builtins/getopts1.0.stdout b/bin/1sh/tests/builtins/getopts1.0.stdout new file mode 100644 index 00000000..a0a347ee --- /dev/null +++ b/bin/1sh/tests/builtins/getopts1.0.stdout @@ -0,0 +1,8 @@ +-1- +a +-2- +a +No arg for -b option +? +-3- +? diff --git a/bin/1sh/tests/builtins/getopts10.0 b/bin/1sh/tests/builtins/getopts10.0 new file mode 100644 index 00000000..45297c82 --- /dev/null +++ b/bin/1sh/tests/builtins/getopts10.0 @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/getopts10.0 293359 2016-01-07 20:48:24Z jilles $ + +set -- -x arg +opt=not +getopts x opt +r1=$? OPTIND1=$OPTIND opt1=$opt +: $(: $((OPTIND = 1))) +getopts x opt +r2=$? OPTIND2=$OPTIND +[ "$r1" = 0 ] && [ "$OPTIND1" = 2 ] && [ "$opt1" = x ] && [ "$r2" != 0 ] && + [ "$OPTIND2" = 2 ] diff --git a/bin/1sh/tests/builtins/getopts2.0 b/bin/1sh/tests/builtins/getopts2.0 new file mode 100644 index 00000000..2f83d992 --- /dev/null +++ b/bin/1sh/tests/builtins/getopts2.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/getopts2.0 297752 2016-04-09 16:06:13Z jilles $ +set - -ax +getopts ax option +set -C +getopts ax option +printf '%s\n' "$option" diff --git a/bin/1sh/tests/builtins/getopts2.0.stdout b/bin/1sh/tests/builtins/getopts2.0.stdout new file mode 100644 index 00000000..587be6b4 --- /dev/null +++ b/bin/1sh/tests/builtins/getopts2.0.stdout @@ -0,0 +1 @@ +x diff --git a/bin/1sh/tests/builtins/getopts3.0 b/bin/1sh/tests/builtins/getopts3.0 new file mode 100644 index 00000000..5a24adbb --- /dev/null +++ b/bin/1sh/tests/builtins/getopts3.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/getopts3.0 265616 2014-05-07 21:45:25Z jilles $ + +shift $# +getopts x opt +r=$? +[ "$r" != 0 ] && [ "$OPTIND" = 1 ] diff --git a/bin/1sh/tests/builtins/getopts4.0 b/bin/1sh/tests/builtins/getopts4.0 new file mode 100644 index 00000000..8e68e38b --- /dev/null +++ b/bin/1sh/tests/builtins/getopts4.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/getopts4.0 265616 2014-05-07 21:45:25Z jilles $ + +set -- -x +opt=not +getopts x opt +r1=$? OPTIND1=$OPTIND opt1=$opt +getopts x opt +r2=$? OPTIND2=$OPTIND +[ "$r1" = 0 ] && [ "$OPTIND1" = 2 ] && [ "$opt1" = x ] && [ "$r2" != 0 ] && + [ "$OPTIND2" = 2 ] diff --git a/bin/1sh/tests/builtins/getopts5.0 b/bin/1sh/tests/builtins/getopts5.0 new file mode 100644 index 00000000..7ce25e31 --- /dev/null +++ b/bin/1sh/tests/builtins/getopts5.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/getopts5.0 265616 2014-05-07 21:45:25Z jilles $ + +set -- -x arg +opt=not +getopts x opt +r1=$? OPTIND1=$OPTIND opt1=$opt +getopts x opt +r2=$? OPTIND2=$OPTIND +[ "$r1" = 0 ] && [ "$OPTIND1" = 2 ] && [ "$opt1" = x ] && [ "$r2" != 0 ] && + [ "$OPTIND2" = 2 ] diff --git a/bin/1sh/tests/builtins/getopts6.0 b/bin/1sh/tests/builtins/getopts6.0 new file mode 100644 index 00000000..d968204a --- /dev/null +++ b/bin/1sh/tests/builtins/getopts6.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/getopts6.0 265844 2014-05-10 17:42:21Z jilles $ + +set -- -x -y +getopts :x var || echo "First getopts bad: $?" +getopts :x var +r=$? +[ r != 0 ] && [ "$OPTIND" = 3 ] diff --git a/bin/1sh/tests/builtins/getopts7.0 b/bin/1sh/tests/builtins/getopts7.0 new file mode 100644 index 00000000..b8f884a4 --- /dev/null +++ b/bin/1sh/tests/builtins/getopts7.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/getopts7.0 265844 2014-05-10 17:42:21Z jilles $ + +set -- -x +getopts :x: var +r=$? +[ r != 0 ] && [ "$OPTIND" = 2 ] diff --git a/bin/1sh/tests/builtins/getopts8.0 b/bin/1sh/tests/builtins/getopts8.0 new file mode 100644 index 00000000..841b3f4e --- /dev/null +++ b/bin/1sh/tests/builtins/getopts8.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/getopts8.0 265849 2014-05-10 19:18:49Z jilles $ + +set -- -yz -wx +opt=wrong1 OPTARG=wrong2 +while getopts :x opt; do + echo "$opt:${OPTARG-unset}" +done +echo "OPTIND=$OPTIND" diff --git a/bin/1sh/tests/builtins/getopts8.0.stdout b/bin/1sh/tests/builtins/getopts8.0.stdout new file mode 100644 index 00000000..f10cefcd --- /dev/null +++ b/bin/1sh/tests/builtins/getopts8.0.stdout @@ -0,0 +1,5 @@ +?:y +?:z +?:w +x:unset +OPTIND=3 diff --git a/bin/1sh/tests/builtins/getopts9.0 b/bin/1sh/tests/builtins/getopts9.0 new file mode 100644 index 00000000..a4864f53 --- /dev/null +++ b/bin/1sh/tests/builtins/getopts9.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/getopts9.0 297752 2016-04-09 16:06:13Z jilles $ + +args='-ab' +getopts ab opt $args +printf '%s\n' "$?:$opt:$OPTARG" +for dummy in dummy1 dummy2; do + getopts ab opt $args + printf '%s\n' "$?:$opt:$OPTARG" +done diff --git a/bin/1sh/tests/builtins/getopts9.0.stdout b/bin/1sh/tests/builtins/getopts9.0.stdout new file mode 100644 index 00000000..4d32063f --- /dev/null +++ b/bin/1sh/tests/builtins/getopts9.0.stdout @@ -0,0 +1,3 @@ +0:a: +0:b: +1:?: diff --git a/bin/1sh/tests/builtins/hash1.0 b/bin/1sh/tests/builtins/hash1.0 new file mode 100644 index 00000000..646066f8 --- /dev/null +++ b/bin/1sh/tests/builtins/hash1.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/hash1.0 149791 2005-09-05 09:42:10Z stefanf $ +cat /dev/null +hash +hash -r +hash diff --git a/bin/1sh/tests/builtins/hash1.0.stdout b/bin/1sh/tests/builtins/hash1.0.stdout new file mode 100644 index 00000000..3afc3e7b --- /dev/null +++ b/bin/1sh/tests/builtins/hash1.0.stdout @@ -0,0 +1 @@ +/bin/cat diff --git a/bin/1sh/tests/builtins/hash2.0 b/bin/1sh/tests/builtins/hash2.0 new file mode 100644 index 00000000..739638c4 --- /dev/null +++ b/bin/1sh/tests/builtins/hash2.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/hash2.0 149791 2005-09-05 09:42:10Z stefanf $ +hash +hash cat +hash diff --git a/bin/1sh/tests/builtins/hash2.0.stdout b/bin/1sh/tests/builtins/hash2.0.stdout new file mode 100644 index 00000000..3afc3e7b --- /dev/null +++ b/bin/1sh/tests/builtins/hash2.0.stdout @@ -0,0 +1 @@ +/bin/cat diff --git a/bin/1sh/tests/builtins/hash3.0 b/bin/1sh/tests/builtins/hash3.0 new file mode 100644 index 00000000..a0bfd48c --- /dev/null +++ b/bin/1sh/tests/builtins/hash3.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/hash3.0 149791 2005-09-05 09:42:10Z stefanf $ +hash -v cat +hash diff --git a/bin/1sh/tests/builtins/hash3.0.stdout b/bin/1sh/tests/builtins/hash3.0.stdout new file mode 100644 index 00000000..a34864cd --- /dev/null +++ b/bin/1sh/tests/builtins/hash3.0.stdout @@ -0,0 +1,2 @@ +/bin/cat +/bin/cat diff --git a/bin/1sh/tests/builtins/hash4.0 b/bin/1sh/tests/builtins/hash4.0 new file mode 100644 index 00000000..4faf4e70 --- /dev/null +++ b/bin/1sh/tests/builtins/hash4.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/hash4.0 231535 2012-02-11 21:06:45Z jilles $ + +exec 3>&1 +m=`hash nosuchtool 2>&1 >&3` +r=$? +[ "$r" != 0 ] && [ -n "$m" ] diff --git a/bin/1sh/tests/builtins/jobid1.0 b/bin/1sh/tests/builtins/jobid1.0 new file mode 100644 index 00000000..4610a710 --- /dev/null +++ b/bin/1sh/tests/builtins/jobid1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/jobid1.0 254412 2013-08-16 13:48:11Z jilles $ +# Non-standard builtin. + +: & +p1=$! +p2=$(jobid) +[ "${p1:?}" = "${p2:?}" ] diff --git a/bin/1sh/tests/builtins/jobid2.0 b/bin/1sh/tests/builtins/jobid2.0 new file mode 100644 index 00000000..b8af0d06 --- /dev/null +++ b/bin/1sh/tests/builtins/jobid2.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/jobid2.0 254413 2013-08-16 13:56:43Z jilles $ + +: & +p1=$(jobid) +p2=$(jobid --) +p3=$(jobid %+) +p4=$(jobid -- %+) +[ "${p1:?}" = "${p2:?}" ] && [ "${p2:?}" = "${p3:?}" ] && +[ "${p3:?}" = "${p4:?}" ] && [ "${p4:?}" = "${p1:?}" ] diff --git a/bin/1sh/tests/builtins/kill1.0 b/bin/1sh/tests/builtins/kill1.0 new file mode 100644 index 00000000..1b22f517 --- /dev/null +++ b/bin/1sh/tests/builtins/kill1.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/kill1.0 262931 2014-03-08 19:44:34Z jilles $ + +: & +p1=$! +: & +p2=$! +wait $p2 +kill %1 diff --git a/bin/1sh/tests/builtins/kill2.0 b/bin/1sh/tests/builtins/kill2.0 new file mode 100644 index 00000000..ff71c8af --- /dev/null +++ b/bin/1sh/tests/builtins/kill2.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/kill2.0 263206 2014-03-15 14:58:48Z jilles $ + +sleep 1 | sleep 1 & +kill %+ +wait "$!" +r=$? +[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = TERM ] diff --git a/bin/1sh/tests/builtins/lineno.0 b/bin/1sh/tests/builtins/lineno.0 new file mode 100644 index 00000000..6b1557a7 --- /dev/null +++ b/bin/1sh/tests/builtins/lineno.0 @@ -0,0 +1,16 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/lineno.0 179023 2008-05-15 19:58:44Z stefanf $ +echo $LINENO +echo $LINENO + +f() { + echo $LINENO + echo $LINENO +} + +f + +echo ${LINENO:-foo} +echo ${LINENO=foo} +echo ${LINENO:+foo} +echo ${LINENO+foo} +echo ${#LINENO} diff --git a/bin/1sh/tests/builtins/lineno.0.stdout b/bin/1sh/tests/builtins/lineno.0.stdout new file mode 100644 index 00000000..82583a93 --- /dev/null +++ b/bin/1sh/tests/builtins/lineno.0.stdout @@ -0,0 +1,9 @@ +2 +3 +2 +3 +12 +13 +foo +foo +2 diff --git a/bin/1sh/tests/builtins/lineno2.0 b/bin/1sh/tests/builtins/lineno2.0 new file mode 100644 index 00000000..154875d3 --- /dev/null +++ b/bin/1sh/tests/builtins/lineno2.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/lineno2.0 262565 2014-02-27 16:54:43Z jilles $ + +f() { + : ${LINENO+${x?}} +} + +unset -v x +command eval f 2>/dev/null && exit 3 +x=1 +f diff --git a/bin/1sh/tests/builtins/lineno3.0 b/bin/1sh/tests/builtins/lineno3.0 new file mode 100644 index 00000000..f0c6be19 --- /dev/null +++ b/bin/1sh/tests/builtins/lineno3.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/lineno3.0 272482 2014-10-03 20:24:56Z jilles $ + +echo before: $LINENO +dummy=$'a\0 +' +echo after: $LINENO diff --git a/bin/1sh/tests/builtins/lineno3.0.stdout b/bin/1sh/tests/builtins/lineno3.0.stdout new file mode 100644 index 00000000..6e0e4ac8 --- /dev/null +++ b/bin/1sh/tests/builtins/lineno3.0.stdout @@ -0,0 +1,2 @@ +before: 3 +after: 6 diff --git a/bin/1sh/tests/builtins/local1.0 b/bin/1sh/tests/builtins/local1.0 new file mode 100644 index 00000000..53b54b52 --- /dev/null +++ b/bin/1sh/tests/builtins/local1.0 @@ -0,0 +1,13 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/local1.0 238469 2012-07-15 10:22:13Z jilles $ +# A commonly used but non-POSIX builtin. + +f() { + local x + x=2 + [ "$x" = 2 ] +} +x=1 +f || exit 3 +[ "$x" = 1 ] || exit 3 +f || exit 3 +[ "$x" = 1 ] || exit 3 diff --git a/bin/1sh/tests/builtins/local2.0 b/bin/1sh/tests/builtins/local2.0 new file mode 100644 index 00000000..7c1bbe6f --- /dev/null +++ b/bin/1sh/tests/builtins/local2.0 @@ -0,0 +1,17 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/local2.0 251797 2013-06-15 22:22:03Z jilles $ + +f() { + local - + set -a + case $- in + *a*) : ;; + *) echo In-function \$- bad + esac +} +case $- in +*a*) echo Initial \$- bad +esac +f +case $- in +*a*) echo Final \$- bad +esac diff --git a/bin/1sh/tests/builtins/local3.0 b/bin/1sh/tests/builtins/local3.0 new file mode 100644 index 00000000..bb041366 --- /dev/null +++ b/bin/1sh/tests/builtins/local3.0 @@ -0,0 +1,26 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/local3.0 251797 2013-06-15 22:22:03Z jilles $ + +f() { + local "$@" + set -a + x=7 + case $- in + *a*) : ;; + *) echo In-function \$- bad + esac + [ "$x" = 7 ] || echo In-function \$x bad +} +x=1 +case $- in +*a*) echo Initial \$- bad +esac +f x - +case $- in +*a*) echo Intermediate \$- bad +esac +[ "$x" = 1 ] || echo Intermediate \$x bad +f - x +case $- in +*a*) echo Final \$- bad +esac +[ "$x" = 1 ] || echo Final \$x bad diff --git a/bin/1sh/tests/builtins/local4.0 b/bin/1sh/tests/builtins/local4.0 new file mode 100644 index 00000000..3d5ec0d4 --- /dev/null +++ b/bin/1sh/tests/builtins/local4.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/local4.0 254339 2013-08-14 21:59:48Z jilles $ + +f() { + local -- x + x=2 + [ "$x" = 2 ] +} +x=1 +f || exit 3 +[ "$x" = 1 ] || exit 3 +f || exit 3 +[ "$x" = 1 ] || exit 3 diff --git a/bin/1sh/tests/builtins/local5.0 b/bin/1sh/tests/builtins/local5.0 new file mode 100644 index 00000000..b2e1879f --- /dev/null +++ b/bin/1sh/tests/builtins/local5.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/local5.0 293635 2016-01-10 16:31:28Z jilles $ + +f() { + local PATH IFS elem + IFS=: + for elem in ''$PATH''; do + PATH=/var/empty/$elem:$PATH + done + ls -d / >/dev/null +} + +p1=$(command -v ls) +f +p2=$(command -v ls) +[ "$p1" = "$p2" ] diff --git a/bin/1sh/tests/builtins/local6.0 b/bin/1sh/tests/builtins/local6.0 new file mode 100644 index 00000000..1f31be32 --- /dev/null +++ b/bin/1sh/tests/builtins/local6.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/local6.0 294582 2016-01-22 18:10:36Z jilles $ + +f() { + local x + readonly x=2 +} +x=3 +f +x=4 +[ "$x" = 4 ] diff --git a/bin/1sh/tests/builtins/local7.0 b/bin/1sh/tests/builtins/local7.0 new file mode 100644 index 00000000..4ab4db53 --- /dev/null +++ b/bin/1sh/tests/builtins/local7.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/local7.0 294593 2016-01-22 20:10:08Z jilles $ + +f() { + local x + readonly x=2 +} +unset x +f +x=4 +[ "$x" = 4 ] diff --git a/bin/1sh/tests/builtins/locale1.0 b/bin/1sh/tests/builtins/locale1.0 new file mode 100644 index 00000000..1737a7e8 --- /dev/null +++ b/bin/1sh/tests/builtins/locale1.0 @@ -0,0 +1,134 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/locale1.0 218819 2011-02-18 20:37:09Z jilles $ +# Note: this test depends on strerror() using locale. + +failures=0 + +check() { + if ! eval "[ $1 ]"; then + echo "Failed: $1 at $2" + : $((failures += 1)) + fi +} + +unset LANG LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME LC_MESSAGES +unset LANGUAGE + +msgeng="No such file or directory" +msgdut="Bestand of map niet gevonden" + +# Verify C locale error message. +case $(command . /var/empty/foo 2>&1) in + *"$msgeng"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +# Various locale variables that should not affect the message. +case $(LC_ALL=C command . /var/empty/foo 2>&1) in + *"$msgeng"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(LC_ALL=C LANG=nl_NL.ISO8859-1 command . /var/empty/foo 2>&1) in + *"$msgeng"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(LC_ALL=C LC_MESSAGES=nl_NL.ISO8859-1 command . /var/empty/foo 2>&1) in + *"$msgeng"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(LC_CTYPE=nl_NL.ISO8859-1 command . /var/empty/foo 2>&1) in + *"$msgeng"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +# Verify Dutch message. +case $(export LANG=nl_NL.ISO8859-1; command . /var/empty/foo 2>&1) in + *"$msgdut"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(export LC_MESSAGES=nl_NL.ISO8859-1; command . /var/empty/foo 2>&1) in + *"$msgdut"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(export LC_ALL=nl_NL.ISO8859-1; command . /var/empty/foo 2>&1) in + *"$msgdut"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(LANG=nl_NL.ISO8859-1 command . /var/empty/foo 2>&1) in + *"$msgdut"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(LC_MESSAGES=nl_NL.ISO8859-1 command . /var/empty/foo 2>&1) in + *"$msgdut"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(LC_ALL=nl_NL.ISO8859-1 command . /var/empty/foo 2>&1) in + *"$msgdut"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +# Verify that command assignments do not set the locale persistently. +case $(command . /var/empty/foo 2>&1) in + *"$msgeng"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(LANG=nl_NL.ISO8859-1 command . /var/empty/foo 2>&1; command . /var/empty/foo 2>&1) in + *"$msgdut"*"$msgeng"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(LC_MESSAGES=nl_NL.ISO8859-1 command . /var/empty/foo 2>&1; command . /var/empty/foo 2>&1) in + *"$msgdut"*"$msgeng"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(LC_ALL=nl_NL.ISO8859-1 command . /var/empty/foo 2>&1; command . /var/empty/foo 2>&1) in + *"$msgdut"*"$msgeng"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +# Check special builtin; add colon invocation to avoid depending on certain fix. +case $(LC_ALL=nl_NL.ISO8859-1 . /var/empty/foo 2>&1; :) in + *"$msgdut"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +# Assignments on special builtins are exported to that builtin; the export +# is not persistent. +case $(LC_ALL=nl_NL.ISO8859-1 . /dev/null; . /var/empty/foo 2>&1) in + *"$msgeng"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +case $(export LC_ALL; LC_ALL=nl_NL.ISO8859-1 . /dev/null; . /var/empty/foo 2>&1) in + *"$msgdut"*) ok=1 ;; + *) ok=0 ;; +esac +check '$ok -eq 1' $LINENO + +exit $((failures > 0)) diff --git a/bin/1sh/tests/builtins/locale2.0 b/bin/1sh/tests/builtins/locale2.0 new file mode 100644 index 00000000..fd83df10 --- /dev/null +++ b/bin/1sh/tests/builtins/locale2.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/locale2.0 317912 2017-05-07 19:49:46Z jilles $ + +$SH -c 'LC_ALL=C true; kill -INT $$; echo continued' +r=$? +[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ] diff --git a/bin/1sh/tests/builtins/printf1.0 b/bin/1sh/tests/builtins/printf1.0 new file mode 100644 index 00000000..a4ba8d8d --- /dev/null +++ b/bin/1sh/tests/builtins/printf1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/printf1.0 214853 2010-11-05 21:47:58Z jilles $ + +[ "$(printf '%c\0%s%d' x '\' 010 | tr '\0' Z)" = 'xZ\8' ] diff --git a/bin/1sh/tests/builtins/printf2.0 b/bin/1sh/tests/builtins/printf2.0 new file mode 100644 index 00000000..97d5bd61 --- /dev/null +++ b/bin/1sh/tests/builtins/printf2.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/printf2.0 214853 2010-11-05 21:47:58Z jilles $ + +[ "$(printf '%cZ%s%d' x '\' 010)" = 'xZ\8' ] diff --git a/bin/1sh/tests/builtins/printf3.0 b/bin/1sh/tests/builtins/printf3.0 new file mode 100644 index 00000000..327f4da4 --- /dev/null +++ b/bin/1sh/tests/builtins/printf3.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/printf3.0 216606 2010-12-20 23:06:57Z jilles $ + +set -e +v=$(! printf "%d" @wrong 2>/dev/null) +[ "$v" = "0" ] diff --git a/bin/1sh/tests/builtins/printf4.0 b/bin/1sh/tests/builtins/printf4.0 new file mode 100644 index 00000000..c00d53f3 --- /dev/null +++ b/bin/1sh/tests/builtins/printf4.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/printf4.0 216606 2010-12-20 23:06:57Z jilles $ + +set -e +v=$(! printf "%d" 4wrong 2>/dev/null) +[ "$v" = "4" ] diff --git a/bin/1sh/tests/builtins/read1.0 b/bin/1sh/tests/builtins/read1.0 new file mode 100644 index 00000000..e0d75152 --- /dev/null +++ b/bin/1sh/tests/builtins/read1.0 @@ -0,0 +1,26 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/read1.0 190300 2009-03-22 23:00:52Z stefanf $ +set -e + +echo "1 2 3" | { read a; echo "x${a}x"; } +echo "1 2 3" | { read a b; echo "x${a}x${b}x"; } +echo "1 2 3" | { read a b c; echo "x${a}x${b}x${c}x"; } +echo "1 2 3" | { read a b c d; echo "x${a}x${b}x${c}x${d}x"; } + +echo " 1 2 3 " | { read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 2 3 " | { unset IFS; read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 2 3 " | { IFS=$(printf ' \t\n') read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 2 3 " | { IFS= read a b; echo "x${a}x${b}x"; } + +echo " 1,2 3 " | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; } +echo ", 2 ,3" | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 ,,3" | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 , , 3" | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 ,2 3," | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 ,2 3,," | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; } + +echo " 1,2 3 " | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; } +echo ", 2 ,3" | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 ,,3" | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 , , 3" | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 ,2 3," | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; } +echo " 1 ,2 3,," | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; } diff --git a/bin/1sh/tests/builtins/read1.0.stdout b/bin/1sh/tests/builtins/read1.0.stdout new file mode 100644 index 00000000..dbcb1af9 --- /dev/null +++ b/bin/1sh/tests/builtins/read1.0.stdout @@ -0,0 +1,20 @@ +x1 2 3x +x1x2 3x +x1x2x3x +x1x2x3xx +x1x2x3x +x1x2x3x +x1x2x3x +x 1 2 3 xx +x1x2x3x +xx2x3x +x1xx3x +x1xx3x +x1x2x3x +x1x2x3,,x +x1x2x3x +xx2x3x +x1xx3x +x1xx3x +x1x2x3x +x1x2x3,,x diff --git a/bin/1sh/tests/builtins/read2.0 b/bin/1sh/tests/builtins/read2.0 new file mode 100644 index 00000000..3747f0bf --- /dev/null +++ b/bin/1sh/tests/builtins/read2.0 @@ -0,0 +1,31 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/read2.0 212187 2010-09-03 21:17:33Z jilles $ + +set -e +{ + echo 1 + echo two + echo three +} | { + read x + [ "$x" = 1 ] + (read x + [ "$x" = two ]) + read x + [ "$x" = three ] +} + +T=`mktemp sh-test.XXXXXX` +trap 'rm -f "$T"' 0 +{ + echo 1 + echo two + echo three +} >$T +{ + read x + [ "$x" = 1 ] + (read x + [ "$x" = two ]) + read x + [ "$x" = three ] +} <$T diff --git a/bin/1sh/tests/builtins/read3.0 b/bin/1sh/tests/builtins/read3.0 new file mode 100644 index 00000000..84dec7cb --- /dev/null +++ b/bin/1sh/tests/builtins/read3.0 @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/read3.0 212330 2010-09-08 18:32:23Z jilles $ + +printf '%s\n' 'a\ b c' | { read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' 'a b\ c' | { read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' 'a\:b:c' | { IFS=: read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' 'a:b\:c' | { IFS=: read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\ a' | { read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\:a' | { IFS=: read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\\' | { read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\\\ a' | { read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\\\ a' | { read -r a b; printf '%s\n' "x${a}x${b}x"; } diff --git a/bin/1sh/tests/builtins/read3.0.stdout b/bin/1sh/tests/builtins/read3.0.stdout new file mode 100644 index 00000000..8ed98ca9 --- /dev/null +++ b/bin/1sh/tests/builtins/read3.0.stdout @@ -0,0 +1,9 @@ +xa bxcx +xaxb cx +xa:bxcx +xaxb:cx +x axx +x:axx +x\xx +x\ axx +x\\\xax diff --git a/bin/1sh/tests/builtins/read4.0 b/bin/1sh/tests/builtins/read4.0 new file mode 100644 index 00000000..f3109c2e --- /dev/null +++ b/bin/1sh/tests/builtins/read4.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/read4.0 212339 2010-09-08 20:35:43Z jilles $ + +printf '%s\n' '\a\ b c' | { read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\a b\ c' | { read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\a\:b:c' | { IFS=: read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\a:b\:c' | { IFS=: read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\\ a' | { read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\\:a' | { IFS=: read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\\\ a' | { read a b; printf '%s\n' "x${a}x${b}x"; } +printf '%s\n' '\\\:a' | { IFS=: read a b; printf '%s\n' "x${a}x${b}x"; } diff --git a/bin/1sh/tests/builtins/read4.0.stdout b/bin/1sh/tests/builtins/read4.0.stdout new file mode 100644 index 00000000..a8747a46 --- /dev/null +++ b/bin/1sh/tests/builtins/read4.0.stdout @@ -0,0 +1,8 @@ +xa bxcx +xaxb cx +xa:bxcx +xaxb:cx +x\xax +x\xax +x\ axx +x\:axx diff --git a/bin/1sh/tests/builtins/read5.0 b/bin/1sh/tests/builtins/read5.0 new file mode 100644 index 00000000..2263a656 --- /dev/null +++ b/bin/1sh/tests/builtins/read5.0 @@ -0,0 +1,32 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/read5.0 218821 2011-02-18 20:51:13Z jilles $ + +unset LC_ALL +LC_CTYPE=en_US.ISO8859-1 +export LC_CTYPE + +# Note: the first and last characters are not whitespace. +# Exclude backslash and newline. +bad1=`printf %03o \'\\\\` +bad2=`printf %03o \'' +'` +e= +for i in 0 1 2 3; do + for j in 0 1 2 3 4 5 6 7; do + for k in 0 1 2 3 4 5 6 7; do + case $i$j$k in + 000|$bad1|$bad2) continue ;; + esac + e="$e\\$i$j$k" + done + done +done +e=`printf "$e"` +[ "${#e}" = 253 ] || echo length bad + +r1=`printf '%s\n' "$e" | { read -r x; printf '%s' "$x"; }` +[ "$r1" = "$e" ] || echo "read with -r bad" +r2=`printf '%s\n' "$e" | { read x; printf '%s' "$x"; }` +[ "$r2" = "$e" ] || echo "read without -r bad 1" +IFS= +r3=`printf '%s\n' "$e" | { read x; printf '%s' "$x"; }` +[ "$r3" = "$e" ] || echo "read without -r bad 2" diff --git a/bin/1sh/tests/builtins/read6.0 b/bin/1sh/tests/builtins/read6.0 new file mode 100644 index 00000000..d924ec51 --- /dev/null +++ b/bin/1sh/tests/builtins/read6.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/read6.0 247190 2013-02-23 15:15:41Z jilles $ + +: | read x +r=$? +[ "$r" = 1 ] diff --git a/bin/1sh/tests/builtins/read7.0 b/bin/1sh/tests/builtins/read7.0 new file mode 100644 index 00000000..00da247f --- /dev/null +++ b/bin/1sh/tests/builtins/read7.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/read7.0 250214 2013-05-03 15:28:31Z jilles $ + +{ errmsg=`read x <&- 2>&1 >&3`; } 3>&1 +r=$? +[ "$r" -ge 2 ] && [ "$r" -le 128 ] && [ -n "$errmsg" ] diff --git a/bin/1sh/tests/builtins/read8.0 b/bin/1sh/tests/builtins/read8.0 new file mode 100644 index 00000000..f9426936 --- /dev/null +++ b/bin/1sh/tests/builtins/read8.0 @@ -0,0 +1,17 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/read8.0 286826 2015-08-16 12:57:17Z jilles $ + +read a b c <<\EOF +\ +A\ + \ + \ + \ +B\ + \ + \ +C\ + \ + \ + \ +EOF +[ "$a.$b.$c" = "A.B.C" ] diff --git a/bin/1sh/tests/builtins/read9.0 b/bin/1sh/tests/builtins/read9.0 new file mode 100644 index 00000000..5c5521db --- /dev/null +++ b/bin/1sh/tests/builtins/read9.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/read9.0 287308 2015-08-30 17:24:22Z jilles $ + +empty='' +read a b c <<EOF +\ \ A B\ \ B C\ \ $empty +EOF +read d e <<EOF +D\ $empty +EOF +[ "$a.$b.$c.$d.$e" = " A.B B.C .D ." ] diff --git a/bin/1sh/tests/builtins/return1.0 b/bin/1sh/tests/builtins/return1.0 new file mode 100644 index 00000000..3f804642 --- /dev/null +++ b/bin/1sh/tests/builtins/return1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/return1.0 149791 2005-09-05 09:42:10Z stefanf $ +f() { + return 0 + exit 1 +} + +f diff --git a/bin/1sh/tests/builtins/return2.1 b/bin/1sh/tests/builtins/return2.1 new file mode 100644 index 00000000..05204bae --- /dev/null +++ b/bin/1sh/tests/builtins/return2.1 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/return2.1 149791 2005-09-05 09:42:10Z stefanf $ +f() { + true && return 1 + return 0 +} + +f diff --git a/bin/1sh/tests/builtins/return3.1 b/bin/1sh/tests/builtins/return3.1 new file mode 100644 index 00000000..f45192bb --- /dev/null +++ b/bin/1sh/tests/builtins/return3.1 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/return3.1 149791 2005-09-05 09:42:10Z stefanf $ +return 1 +exit 0 diff --git a/bin/1sh/tests/builtins/return4.0 b/bin/1sh/tests/builtins/return4.0 new file mode 100644 index 00000000..d54cf8d6 --- /dev/null +++ b/bin/1sh/tests/builtins/return4.0 @@ -0,0 +1,16 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/return4.0 208629 2010-05-28 22:08:34Z jilles $ + +failures= +failure() { + echo "Error at line $1" >&2 + failures=x$failures +} + +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) || exit +trap 'rm -rf $T' 0 +cd $T || exit 3 +echo 'return 42; exit 4' >testscript +. ./testscript +[ "$?" = 42 ] || failure $LINENO + +test -z "$failures" diff --git a/bin/1sh/tests/builtins/return5.0 b/bin/1sh/tests/builtins/return5.0 new file mode 100644 index 00000000..61d29292 --- /dev/null +++ b/bin/1sh/tests/builtins/return5.0 @@ -0,0 +1,17 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/return5.0 211349 2010-08-15 21:06:53Z jilles $ + +if [ "$1" != nested ]; then + f() { + set -- nested + . "$0" + # Allow return to return from the function or the dot script. + return 4 + } + f + exit $(($? ^ 4)) +fi +# To trigger the bug, the following commands must be at the top level, +# with newlines in between. +return 4 +echo bad +exit 1 diff --git a/bin/1sh/tests/builtins/return6.4 b/bin/1sh/tests/builtins/return6.4 new file mode 100644 index 00000000..d70e805b --- /dev/null +++ b/bin/1sh/tests/builtins/return6.4 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/return6.4 212475 2010-09-11 15:07:40Z jilles $ + +while return 4; do exit 3; done diff --git a/bin/1sh/tests/builtins/return7.4 b/bin/1sh/tests/builtins/return7.4 new file mode 100644 index 00000000..7ecfe46e --- /dev/null +++ b/bin/1sh/tests/builtins/return7.4 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/return7.4 212475 2010-09-11 15:07:40Z jilles $ + +f() { + while return 4; do exit 3; done +} +f diff --git a/bin/1sh/tests/builtins/return8.0 b/bin/1sh/tests/builtins/return8.0 new file mode 100644 index 00000000..ebe6a78b --- /dev/null +++ b/bin/1sh/tests/builtins/return8.0 @@ -0,0 +1,13 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/return8.0 255215 2013-09-04 22:10:16Z jilles $ + +if [ "$1" = nested ]; then + return 17 +fi + +f() { + set -- nested + . "$0" + return $(($? ^ 1)) +} +f +exit $(($? ^ 16)) diff --git a/bin/1sh/tests/builtins/set1.0 b/bin/1sh/tests/builtins/set1.0 new file mode 100644 index 00000000..fc39fade --- /dev/null +++ b/bin/1sh/tests/builtins/set1.0 @@ -0,0 +1,32 @@ +# $FreeBSD$ + +set +C +set +f +set -e + +settings=$(set +o) +set -C +set -f +set +e +case $- in +*C*) ;; +*) echo missing C ;; +esac +case $- in +*f*) ;; +*) echo missing C ;; +esac +case $- in +*e*) echo bad e ;; +esac +eval "$settings" +case $- in +*C*) echo bad C ;; +esac +case $- in +*f*) echo bad f ;; +esac +case $- in +*e*) ;; +*) echo missing e ;; +esac diff --git a/bin/1sh/tests/builtins/set2.0 b/bin/1sh/tests/builtins/set2.0 new file mode 100644 index 00000000..9d7b2ed0 --- /dev/null +++ b/bin/1sh/tests/builtins/set2.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/set2.0 223183 2011-06-17 10:21:24Z jilles $ + +! env @badness=1 ${SH} -c 'v=`set`; eval "$v"' 2>&1 | grep @badness diff --git a/bin/1sh/tests/builtins/set3.0 b/bin/1sh/tests/builtins/set3.0 new file mode 100644 index 00000000..5dca36e5 --- /dev/null +++ b/bin/1sh/tests/builtins/set3.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/set3.0 296578 2016-03-09 21:05:21Z jilles $ + +settings1=$(set +o) && set -o nolog && settings2=$(set +o) && +[ "$settings1" != "$settings2" ] diff --git a/bin/1sh/tests/builtins/trap1.0 b/bin/1sh/tests/builtins/trap1.0 new file mode 100644 index 00000000..996fe91e --- /dev/null +++ b/bin/1sh/tests/builtins/trap1.0 @@ -0,0 +1,22 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap1.0 213738 2010-10-12 18:20:38Z obrien $ + +test "$(trap 'echo trapped' EXIT; :)" = trapped || exit 1 + +test "$(trap 'echo trapped' EXIT; /usr/bin/true)" = trapped || exit 1 + +result=$(${SH} -c 'trap "echo trapped" EXIT; /usr/bin/false') +test $? -eq 1 || exit 1 +test "$result" = trapped || exit 1 + +result=$(${SH} -c 'trap "echo trapped" EXIT; exec /usr/bin/false') +test $? -eq 1 || exit 1 +test -z "$result" || exit 1 + +result=0 +trap 'result=$((result+1))' INT +kill -INT $$ +test "$result" -eq 1 || exit 1 +(kill -INT $$) +test "$result" -eq 2 || exit 1 + +exit 0 diff --git a/bin/1sh/tests/builtins/trap10.0 b/bin/1sh/tests/builtins/trap10.0 new file mode 100644 index 00000000..75b3dd3e --- /dev/null +++ b/bin/1sh/tests/builtins/trap10.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap10.0 230212 2012-01-16 11:07:46Z dumbbell $ + +# Check that the return statement will not break the EXIT trap, ie. all +# trap commands are executed before the script exits. + +test "$(trap 'printf trap; echo ped' EXIT; f() { return; }; f)" = trapped || exit 1 diff --git a/bin/1sh/tests/builtins/trap11.0 b/bin/1sh/tests/builtins/trap11.0 new file mode 100644 index 00000000..b1e04746 --- /dev/null +++ b/bin/1sh/tests/builtins/trap11.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap11.0 230212 2012-01-16 11:07:46Z dumbbell $ + +# Check that the return statement will not break the USR1 trap, ie. all +# trap commands are executed before the script resumes. + +result=$(${SH} -c 'trap "printf trap; echo ped" USR1; f() { return $(kill -USR1 $$); }; f') +test $? -eq 0 || exit 1 +test "$result" = trapped || exit 1 diff --git a/bin/1sh/tests/builtins/trap12.0 b/bin/1sh/tests/builtins/trap12.0 new file mode 100644 index 00000000..bb805450 --- /dev/null +++ b/bin/1sh/tests/builtins/trap12.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap12.0 247720 2013-03-03 17:33:59Z jilles $ + +f() { + trap 'return 42' USR1 + kill -USR1 $$ + return 3 +} +f +r=$? +[ "$r" = 42 ] diff --git a/bin/1sh/tests/builtins/trap13.0 b/bin/1sh/tests/builtins/trap13.0 new file mode 100644 index 00000000..bb2b0ce3 --- /dev/null +++ b/bin/1sh/tests/builtins/trap13.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap13.0 257399 2013-10-30 21:36:15Z jilles $ + +{ + trap 'exit 0' INT + ${SH} -c 'kill -INT $PPID' + exit 3 +} & +wait $! diff --git a/bin/1sh/tests/builtins/trap14.0 b/bin/1sh/tests/builtins/trap14.0 new file mode 100644 index 00000000..e2e79649 --- /dev/null +++ b/bin/1sh/tests/builtins/trap14.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap14.0 257399 2013-10-30 21:36:15Z jilles $ + +{ + trap - INT + ${SH} -c 'kill -INT $PPID' & + wait +} & +wait $! +r=$? +[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ] diff --git a/bin/1sh/tests/builtins/trap15.0 b/bin/1sh/tests/builtins/trap15.0 new file mode 100644 index 00000000..97836e17 --- /dev/null +++ b/bin/1sh/tests/builtins/trap15.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap15.0 281718 2015-04-18 23:49:57Z bdrewery $ + +(${SH} -c 'term(){ exit 5;}; trap term TERM; kill -TERM $$') & +wait >/dev/null 2>&1 $! +[ $? -eq 5 ] diff --git a/bin/1sh/tests/builtins/trap16.0 b/bin/1sh/tests/builtins/trap16.0 new file mode 100644 index 00000000..0e3010dc --- /dev/null +++ b/bin/1sh/tests/builtins/trap16.0 @@ -0,0 +1,20 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap16.0 281718 2015-04-18 23:49:57Z bdrewery $ + +traps=$(${SH} -c 'trap "echo bad" 0; trap - 0; trap') +[ -z "$traps" ] || exit 1 +traps=$(${SH} -c 'trap "echo bad" 0; trap "" 0; trap') +expected_traps=$(${SH} -c 'trap "" EXIT; trap') +[ "$traps" = "$expected_traps" ] || exit 2 +traps=$(${SH} -c 'trap "echo bad" 0; trap 0; trap') +[ -z "$traps" ] || exit 3 +traps=$(${SH} -c 'trap "echo bad" 0; trap -- 0; trap') +[ -z "$traps" ] || exit 4 +traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap - 0 1 2; trap') +[ -z "$traps" ] || exit 5 +traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap "" 0 1 2; trap') +expected_traps=$(${SH} -c 'trap "" EXIT HUP INT; trap') +[ "$traps" = "$expected_traps" ] || exit 6 +traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap 0 1 2; trap') +[ -z "$traps" ] || exit 7 +traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap -- 0 1 2; trap') +[ -z "$traps" ] || exit 8 diff --git a/bin/1sh/tests/builtins/trap17.0 b/bin/1sh/tests/builtins/trap17.0 new file mode 100644 index 00000000..4ee48129 --- /dev/null +++ b/bin/1sh/tests/builtins/trap17.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap17.0 297360 2016-03-28 18:58:40Z jilles $ +# This use-after-free bug probably needs non-default settings to show up. + +v1=nothing v2=nothing +trap 'trap "echo bad" USR1 +v1=trap_received +v2=trap_invoked +:' USR1 +kill -USR1 "$$" +[ "$v1.$v2" = trap_received.trap_invoked ] diff --git a/bin/1sh/tests/builtins/trap2.0 b/bin/1sh/tests/builtins/trap2.0 new file mode 100644 index 00000000..eb17a03e --- /dev/null +++ b/bin/1sh/tests/builtins/trap2.0 @@ -0,0 +1,52 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap2.0 194517 2009-06-19 22:15:59Z jilles $ +# This is really a test for outqstr(), which is readily accessible via trap. + +runtest() +{ + teststring=$1 + trap -- "$teststring" USR1 + traps=$(trap) + if [ "$teststring" != "-" ] && [ -z "$traps" ]; then + # One possible reading of POSIX requires the above to return an + # empty string because backquote commands are executed in a + # subshell and subshells shall reset traps. However, an example + # in the normative description of the trap builtin shows the + # same usage as here, it is useful and our /bin/sh allows it. + echo '$(trap) is broken' + exit 1 + fi + trap - USR1 + eval "$traps" + traps2=$(trap) + if [ "$traps" != "$traps2" ]; then + echo "Mismatch for '$teststring'" + exit 1 + fi +} + +runtest 'echo' +runtest 'echo hi' +runtest "'echo' 'hi'" +runtest '"echo" $PATH' +runtest '\echo "$PATH"' +runtest ' 0' +runtest '0 ' +runtest ' 1' +runtest '1 ' +i=1 +while [ $i -le 127 ]; do + c=$(printf \\"$(printf %o $i)") + if [ $i -lt 48 ] || [ $i -gt 57 ]; then + runtest "$c" + fi + runtest " $c$c" + runtest "a$c" + i=$((i+1)) +done +IFS=, +runtest ' ' +runtest ',' +unset IFS +runtest ' ' + +exit 0 diff --git a/bin/1sh/tests/builtins/trap3.0 b/bin/1sh/tests/builtins/trap3.0 new file mode 100644 index 00000000..007cb0e6 --- /dev/null +++ b/bin/1sh/tests/builtins/trap3.0 @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap3.0 218889 2011-02-20 14:18:58Z jilles $ + +{ + trap '' garbage && exit 3 + trap - garbage && exit 3 + trap true garbage && exit 3 + trap '' 99999 && exit 3 + trap - 99999 && exit 3 + trap true 99999 && exit 3 +} 2>/dev/null +exit 0 diff --git a/bin/1sh/tests/builtins/trap4.0 b/bin/1sh/tests/builtins/trap4.0 new file mode 100644 index 00000000..e8f8ffe2 --- /dev/null +++ b/bin/1sh/tests/builtins/trap4.0 @@ -0,0 +1,17 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap4.0 217035 2011-01-05 23:17:29Z jilles $ + +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) +trap 'rm -rf $T' 0 +cd $T || exit 3 +mkfifo fifo1 + +v=$( + exec 3>&1 + : <fifo1 & + { + wait $! + trap 'trap "" PIPE; echo trapped >&3 2>/dev/null' PIPE + echo x 2>/dev/null + } >fifo1 +) +test "$v" = trapped diff --git a/bin/1sh/tests/builtins/trap5.0 b/bin/1sh/tests/builtins/trap5.0 new file mode 100644 index 00000000..1db05759 --- /dev/null +++ b/bin/1sh/tests/builtins/trap5.0 @@ -0,0 +1,19 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap5.0 217461 2011-01-15 21:09:00Z jilles $ + +set -e +trap - USR1 +initial=$(trap) +trap -- -l USR1 +added=$(trap) +[ -n "$added" ] +trap - USR1 +second=$(trap) +[ "$initial" = "$second" ] +eval "$added" +added2=$(trap) +added3=$(trap --) +[ "$added" = "$added2" ] +[ "$added2" = "$added3" ] +trap -- - USR1 +third=$(trap) +[ "$initial" = "$third" ] diff --git a/bin/1sh/tests/builtins/trap6.0 b/bin/1sh/tests/builtins/trap6.0 new file mode 100644 index 00000000..ee4a25c6 --- /dev/null +++ b/bin/1sh/tests/builtins/trap6.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap6.0 217472 2011-01-16 13:56:41Z jilles $ + +v=$( + ${SH} -c 'trap "echo ok; exit" USR1; kill -USR1 $$' & + # Suppress possible message about exit on signal + wait $! >/dev/null 2>&1 +) +r=$(kill -l $?) +[ "$v" = "ok" ] && { [ "$r" = "USR1" ] || [ "$r" = "usr1" ]; } diff --git a/bin/1sh/tests/builtins/trap7.0 b/bin/1sh/tests/builtins/trap7.0 new file mode 100644 index 00000000..84b80006 --- /dev/null +++ b/bin/1sh/tests/builtins/trap7.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap7.0 217996 2011-01-27 23:08:20Z jilles $ + +[ "$(trap 'echo trapped' EXIT)" = trapped ] diff --git a/bin/1sh/tests/builtins/trap8.0 b/bin/1sh/tests/builtins/trap8.0 new file mode 100644 index 00000000..1d4e8afc --- /dev/null +++ b/bin/1sh/tests/builtins/trap8.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap8.0 218889 2011-02-20 14:18:58Z jilles $ + +# I am not sure if POSIX requires the shell to continue processing +# further trap names in the same trap command after an invalid one. + +test -n "$(trap true garbage TERM 2>/dev/null || trap)" || exit 3 +exit 0 diff --git a/bin/1sh/tests/builtins/trap9.0 b/bin/1sh/tests/builtins/trap9.0 new file mode 100644 index 00000000..f53ac49a --- /dev/null +++ b/bin/1sh/tests/builtins/trap9.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap9.0 230211 2012-01-16 10:59:44Z dumbbell $ + +test "$(trap 'printf trap; echo ped' EXIT; f() { :; }; f)" = trapped || exit 1 diff --git a/bin/1sh/tests/builtins/type1.0 b/bin/1sh/tests/builtins/type1.0 new file mode 100644 index 00000000..09ae8692 --- /dev/null +++ b/bin/1sh/tests/builtins/type1.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/type1.0 165931 2007-01-11 00:25:20Z stefanf $ +command -v not-here && exit 1 +command -v /not-here && exit 1 +command -V not-here && exit 1 +command -V /not-here && exit 1 +type not-here && exit 1 +type /not-here && exit 1 +exit 0 diff --git a/bin/1sh/tests/builtins/type1.0.stderr b/bin/1sh/tests/builtins/type1.0.stderr new file mode 100644 index 00000000..7853418a --- /dev/null +++ b/bin/1sh/tests/builtins/type1.0.stderr @@ -0,0 +1,4 @@ +not-here: not found +/not-here: No such file or directory +not-here: not found +/not-here: No such file or directory diff --git a/bin/1sh/tests/builtins/type2.0 b/bin/1sh/tests/builtins/type2.0 new file mode 100644 index 00000000..9c8efc77 --- /dev/null +++ b/bin/1sh/tests/builtins/type2.0 @@ -0,0 +1,26 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/type2.0 201344 2009-12-31 17:44:24Z jilles $ + +failures=0 + +check() { + if ! eval "$*"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check 'PATH=/libexec type ld-elf.so.1 >/dev/null' +check '! PATH=/libexec type ls 2>/dev/null' + +PATH=/libexec:$PATH + +check 'type ld-elf.so.1 >/dev/null' + +PATH=/libexec + +check 'type ld-elf.so.1 >/dev/null' +check '! type ls 2>/dev/null' +check 'PATH=/bin type ls >/dev/null' +check '! PATH=/bin type ld-elf.so.1 2>/dev/null' + +exit $((failures > 0)) diff --git a/bin/1sh/tests/builtins/type3.0 b/bin/1sh/tests/builtins/type3.0 new file mode 100644 index 00000000..777af5e1 --- /dev/null +++ b/bin/1sh/tests/builtins/type3.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/type3.0 255072 2013-08-30 12:09:59Z jilles $ + +[ "$(type type)" = "$(type -- type)" ] diff --git a/bin/1sh/tests/builtins/unalias.0 b/bin/1sh/tests/builtins/unalias.0 new file mode 100644 index 00000000..ad2fe0c7 --- /dev/null +++ b/bin/1sh/tests/builtins/unalias.0 @@ -0,0 +1,21 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/unalias.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e + +alias false=true +false +unalias false +false && exit 1 +unalias false && exit 1 + +alias a1=foo a2=bar +unalias a1 a2 +unalias a1 && exit 1 +unalias a2 && exit 1 +alias a2=bar +unalias a1 a2 && exit 1 + +alias a1=foo a2=bar +unalias -a +unalias a1 && exit 1 +unalias a2 && exit 1 +exit 0 diff --git a/bin/1sh/tests/builtins/var-assign.0 b/bin/1sh/tests/builtins/var-assign.0 new file mode 100644 index 00000000..ff54d487 --- /dev/null +++ b/bin/1sh/tests/builtins/var-assign.0 @@ -0,0 +1,55 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/var-assign.0 327281 2017-12-28 08:22:26Z eadler $ +IFS=, + +SPECIAL="break,\ + :,\ + continue,\ + . /dev/null, + eval, + exec, + export -p, + readonly -p, + set, + shift 0, + times, + trap, + unset foo" + +UTILS="alias,\ + bg,\ + bind,\ + cd,\ + command echo,\ + echo,\ + false,\ + fc -l,\ + fg,\ + getopts a var,\ + hash,\ + jobs,\ + printf a,\ + pwd,\ + read var < /dev/null,\ + test,\ + true,\ + type ls,\ + ulimit,\ + umask,\ + unalias -a,\ + wait" + +set -e + +# For special built-ins variable assignments affect the shell environment. +set -- ${SPECIAL} +for cmd in "$@" +do + ${SH} -c "VAR=1; VAR=0 ${cmd}; exit \${VAR}" >/dev/null 2>&1 +done + +# For other built-ins and utilities they do not. +set -- ${UTILS} +for cmd in "$@" +do + ${SH} -c "VAR=0; VAR=1 ${cmd}; exit \${VAR}" >/dev/null 2>&1 +done diff --git a/bin/1sh/tests/builtins/var-assign2.0 b/bin/1sh/tests/builtins/var-assign2.0 new file mode 100644 index 00000000..e5b01ec7 --- /dev/null +++ b/bin/1sh/tests/builtins/var-assign2.0 @@ -0,0 +1,55 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/var-assign2.0 213738 2010-10-12 18:20:38Z obrien $ +IFS=, + +SPECIAL="break,\ + :,\ + continue,\ + . /dev/null,\ + eval,\ + exec,\ + export -p,\ + readonly -p,\ + set,\ + shift 0,\ + times,\ + trap,\ + unset foo" + +UTILS="alias,\ + bg,\ + bind,\ + cd,\ + command echo,\ + echo,\ + false,\ + fc -l,\ + fg,\ + getopts a var,\ + hash,\ + jobs,\ + printf a,\ + pwd,\ + read var < /dev/null,\ + test,\ + true,\ + type ls,\ + ulimit,\ + umask,\ + unalias -a,\ + wait" + +set -e + +# With 'command', variable assignments do not affect the shell environment. + +set -- ${SPECIAL} +for cmd in "$@" +do + ${SH} -c "VAR=0; VAR=1 command ${cmd}; exit \${VAR}" >/dev/null 2>&1 +done + +set -- ${UTILS} +for cmd in "$@" +do + ${SH} -c "VAR=0; VAR=1 command ${cmd}; exit \${VAR}" >/dev/null 2>&1 +done diff --git a/bin/1sh/tests/builtins/wait1.0 b/bin/1sh/tests/builtins/wait1.0 new file mode 100644 index 00000000..aab8c291 --- /dev/null +++ b/bin/1sh/tests/builtins/wait1.0 @@ -0,0 +1,23 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/wait1.0 208476 2010-05-23 22:10:20Z jilles $ + +failures= +failure() { + echo "Error at line $1" >&2 + failures=x$failures +} + +exit 4 & p4=$! +exit 8 & p8=$! +wait $p4 +[ $? = 4 ] || failure $LINENO +wait $p8 +[ $? = 8 ] || failure $LINENO + +exit 3 & p3=$! +exit 7 & p7=$! +wait $p7 +[ $? = 7 ] || failure $LINENO +wait $p3 +[ $? = 3 ] || failure $LINENO + +test -z "$failures" diff --git a/bin/1sh/tests/builtins/wait10.0 b/bin/1sh/tests/builtins/wait10.0 new file mode 100644 index 00000000..a6d62405 --- /dev/null +++ b/bin/1sh/tests/builtins/wait10.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/wait10.0 251430 2013-06-05 19:40:52Z jilles $ +# Init cannot be a child of the shell. +exit 49 & p49=$! +wait 1 "$p49" +[ "$?" = 49 ] diff --git a/bin/1sh/tests/builtins/wait2.0 b/bin/1sh/tests/builtins/wait2.0 new file mode 100644 index 00000000..f6a4db94 --- /dev/null +++ b/bin/1sh/tests/builtins/wait2.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/wait2.0 208476 2010-05-23 22:10:20Z jilles $ + +failures= +failure() { + echo "Error at line $1" >&2 + failures=x$failures +} + +for i in 1 2 3 4 5 6 7 8 9 10; do + exit $i & +done +wait || failure $LINENO +wait || failure $LINENO + +test -z "$failures" diff --git a/bin/1sh/tests/builtins/wait3.0 b/bin/1sh/tests/builtins/wait3.0 new file mode 100644 index 00000000..fd835b1b --- /dev/null +++ b/bin/1sh/tests/builtins/wait3.0 @@ -0,0 +1,21 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/wait3.0 236771 2012-06-08 22:54:25Z jilles $ + +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 4<fifo1 & +done +exec 3>fifo1 +wait || failure $LINENO +(${SH} -c echo >&3) 2>/dev/null && failure $LINENO +wait || failure $LINENO + +test -z "$failures" diff --git a/bin/1sh/tests/builtins/wait4.0 b/bin/1sh/tests/builtins/wait4.0 new file mode 100644 index 00000000..de4b3ad4 --- /dev/null +++ b/bin/1sh/tests/builtins/wait4.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/wait4.0 247206 2013-02-23 22:50:57Z jilles $ + +T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX` +trap 'rm -rf $T' 0 +cd $T || exit 3 +mkfifo fifo1 +trapped= +trap trapped=1 QUIT +{ kill -QUIT $$; sleep 1; exit 4; } >fifo1 & +wait $! <fifo1 +r=$? +[ "$r" -gt 128 ] && [ -n "$trapped" ] diff --git a/bin/1sh/tests/builtins/wait5.0 b/bin/1sh/tests/builtins/wait5.0 new file mode 100644 index 00000000..6ce6de8f --- /dev/null +++ b/bin/1sh/tests/builtins/wait5.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/wait5.0 247206 2013-02-23 22:50:57Z jilles $ + +T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX` +trap 'rm -rf $T' 0 +cd $T || exit 3 +mkfifo fifo1 +trapped= +trap trapped=1 QUIT +{ kill -QUIT $$; sleep 1; exit 4; } >fifo1 & +wait <fifo1 +r=$? +[ "$r" -gt 128 ] && [ -n "$trapped" ] diff --git a/bin/1sh/tests/builtins/wait6.0 b/bin/1sh/tests/builtins/wait6.0 new file mode 100644 index 00000000..a3730c1f --- /dev/null +++ b/bin/1sh/tests/builtins/wait6.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/wait6.0 248349 2013-03-15 20:29:31Z jilles $ + +wait -- diff --git a/bin/1sh/tests/builtins/wait7.0 b/bin/1sh/tests/builtins/wait7.0 new file mode 100644 index 00000000..b4e26d54 --- /dev/null +++ b/bin/1sh/tests/builtins/wait7.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/wait7.0 248349 2013-03-15 20:29:31Z jilles $ + +: & +wait -- $! diff --git a/bin/1sh/tests/builtins/wait8.0 b/bin/1sh/tests/builtins/wait8.0 new file mode 100644 index 00000000..3c6512fd --- /dev/null +++ b/bin/1sh/tests/builtins/wait8.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/wait8.0 251429 2013-06-05 19:08:22Z jilles $ + +exit 44 & p44=$! +exit 45 & p45=$! +exit 7 & p7=$! +wait "$p44" "$p7" "$p45" +[ "$?" = 45 ] diff --git a/bin/1sh/tests/builtins/wait9.127 b/bin/1sh/tests/builtins/wait9.127 new file mode 100644 index 00000000..30148075 --- /dev/null +++ b/bin/1sh/tests/builtins/wait9.127 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/builtins/wait9.127 251430 2013-06-05 19:40:52Z jilles $ +# Init cannot be a child of the shell. +wait 1 diff --git a/bin/1sh/tests/errors/Makefile b/bin/1sh/tests/errors/Makefile new file mode 100644 index 00000000..a25cf4f8 --- /dev/null +++ b/bin/1sh/tests/errors/Makefile @@ -0,0 +1,35 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/Makefile 319575 2017-06-04 20:52:55Z jilles $ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +${PACKAGE}FILES+= assignment-error1.0 +${PACKAGE}FILES+= assignment-error2.0 +${PACKAGE}FILES+= backquote-error1.0 +${PACKAGE}FILES+= backquote-error2.0 +${PACKAGE}FILES+= bad-binary1.126 +${PACKAGE}FILES+= bad-keyword1.0 +${PACKAGE}FILES+= bad-parm-exp1.0 +${PACKAGE}FILES+= bad-parm-exp2.2 bad-parm-exp2.2.stderr +${PACKAGE}FILES+= bad-parm-exp3.2 bad-parm-exp3.2.stderr +${PACKAGE}FILES+= bad-parm-exp4.2 bad-parm-exp4.2.stderr +${PACKAGE}FILES+= bad-parm-exp5.2 bad-parm-exp5.2.stderr +${PACKAGE}FILES+= bad-parm-exp6.2 bad-parm-exp6.2.stderr +${PACKAGE}FILES+= bad-parm-exp7.0 +${PACKAGE}FILES+= bad-parm-exp8.0 +${PACKAGE}FILES+= option-error.0 +${PACKAGE}FILES+= redirection-error.0 +${PACKAGE}FILES+= redirection-error2.2 +${PACKAGE}FILES+= redirection-error3.0 +${PACKAGE}FILES+= redirection-error4.0 +${PACKAGE}FILES+= redirection-error5.0 +${PACKAGE}FILES+= redirection-error6.0 +${PACKAGE}FILES+= redirection-error7.0 +${PACKAGE}FILES+= redirection-error8.0 +${PACKAGE}FILES+= write-error1.0 + +.include <bsd.test.mk> diff --git a/bin/1sh/tests/errors/Makefile.depend b/bin/1sh/tests/errors/Makefile.depend new file mode 100644 index 00000000..8c66cd28 --- /dev/null +++ b/bin/1sh/tests/errors/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/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/errors/assignment-error1.0 b/bin/1sh/tests/errors/assignment-error1.0 new file mode 100644 index 00000000..38c9553f --- /dev/null +++ b/bin/1sh/tests/errors/assignment-error1.0 @@ -0,0 +1,30 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/assignment-error1.0 213738 2010-10-12 18:20:38Z obrien $ +IFS=, + +SPECIAL="break,\ + :,\ + continue,\ + . /dev/null,\ + eval,\ + exec,\ + export -p,\ + readonly -p,\ + set,\ + shift,\ + times,\ + trap,\ + unset foo" + +# If there is no command word, the shell must abort on an assignment error. +${SH} -c "readonly a=0; a=2; exit 0" 2>/dev/null && exit 1 + +# Special built-in utilities must abort on an assignment error. +set -- ${SPECIAL} +for cmd in "$@" +do + ${SH} -c "readonly a=0; a=2 ${cmd}; exit 0" 2>/dev/null && exit 1 +done + +# Other utilities must not abort; we currently still execute them. +${SH} -c 'readonly a=0; a=1 true; exit $a' 2>/dev/null || exit 1 +${SH} -c 'readonly a=0; a=1 command :; exit $a' 2>/dev/null || exit 1 diff --git a/bin/1sh/tests/errors/assignment-error2.0 b/bin/1sh/tests/errors/assignment-error2.0 new file mode 100644 index 00000000..1d39d01b --- /dev/null +++ b/bin/1sh/tests/errors/assignment-error2.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/assignment-error2.0 216870 2011-01-01 13:26:18Z jilles $ + +set -e +HOME=/ +readonly HOME +cd /sbin +{ HOME=/bin cd; } 2>/dev/null || : +[ "$(pwd)" != /bin ] diff --git a/bin/1sh/tests/errors/backquote-error1.0 b/bin/1sh/tests/errors/backquote-error1.0 new file mode 100644 index 00000000..4d39ddb4 --- /dev/null +++ b/bin/1sh/tests/errors/backquote-error1.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/backquote-error1.0 213738 2010-10-12 18:20:38Z obrien $ + +echo 'echo `for` echo ".BAD"CODE.' | ${SH} +m -i 2>&1 | grep -q BADCODE && exit 1 +exit 0 diff --git a/bin/1sh/tests/errors/backquote-error2.0 b/bin/1sh/tests/errors/backquote-error2.0 new file mode 100644 index 00000000..0669617c --- /dev/null +++ b/bin/1sh/tests/errors/backquote-error2.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/backquote-error2.0 213738 2010-10-12 18:20:38Z obrien $ + +${SH} -c 'echo `echo .BA"DCODE.` +echo ".BAD"CODE.' 2>&1 | grep -q BADCODE && exit 1 +echo '`"`' | ${SH} -n 2>/dev/null && exit 1 +echo '`'"'"'`' | ${SH} -n 2>/dev/null && exit 1 +exit 0 diff --git a/bin/1sh/tests/errors/bad-binary1.126 b/bin/1sh/tests/errors/bad-binary1.126 new file mode 100644 index 00000000..24988e0e --- /dev/null +++ b/bin/1sh/tests/errors/bad-binary1.126 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/bad-binary1.126 218320 2011-02-05 12:54:59Z jilles $ +# Checking for binary "scripts" without magic number is permitted but not +# required by POSIX. However, it is preferable to getting errors like +# Syntax error: word unexpected (expecting ")") +# from trying to execute ELF binaries for the wrong architecture. + +T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit +trap 'rm -rf "${T}"' 0 +printf '\0echo bad\n' >"$T/testshellproc" +chmod 755 "$T/testshellproc" +PATH=$T:$PATH +testshellproc 2>/dev/null diff --git a/bin/1sh/tests/errors/bad-keyword1.0 b/bin/1sh/tests/errors/bad-keyword1.0 new file mode 100644 index 00000000..3a98871d --- /dev/null +++ b/bin/1sh/tests/errors/bad-keyword1.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/bad-keyword1.0 216398 2010-12-12 21:18:16Z jilles $ + +echo ':; fi' | ${SH} -n 2>/dev/null && exit 1 +exit 0 diff --git a/bin/1sh/tests/errors/bad-parm-exp1.0 b/bin/1sh/tests/errors/bad-parm-exp1.0 new file mode 100644 index 00000000..6fdd9039 --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/bad-parm-exp1.0 164004 2006-11-05 18:41:23Z stefanf $ +false && { + ${} + ${foo/} + ${foo@bar} +} +: diff --git a/bin/1sh/tests/errors/bad-parm-exp2.2 b/bin/1sh/tests/errors/bad-parm-exp2.2 new file mode 100644 index 00000000..e7655fce --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp2.2 @@ -0,0 +1,2 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/bad-parm-exp2.2 270101 2014-08-17 14:26:12Z jilles $ +eval '${}' diff --git a/bin/1sh/tests/errors/bad-parm-exp2.2.stderr b/bin/1sh/tests/errors/bad-parm-exp2.2.stderr new file mode 100644 index 00000000..51ea69ca --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp2.2.stderr @@ -0,0 +1 @@ +eval: ${}: Bad substitution diff --git a/bin/1sh/tests/errors/bad-parm-exp3.2 b/bin/1sh/tests/errors/bad-parm-exp3.2 new file mode 100644 index 00000000..7acda667 --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp3.2 @@ -0,0 +1,2 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/bad-parm-exp3.2 270101 2014-08-17 14:26:12Z jilles $ +eval '${foo/}' diff --git a/bin/1sh/tests/errors/bad-parm-exp3.2.stderr b/bin/1sh/tests/errors/bad-parm-exp3.2.stderr new file mode 100644 index 00000000..70473f9a --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp3.2.stderr @@ -0,0 +1 @@ +eval: ${foo/}: Bad substitution diff --git a/bin/1sh/tests/errors/bad-parm-exp4.2 b/bin/1sh/tests/errors/bad-parm-exp4.2 new file mode 100644 index 00000000..d9b0977f --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp4.2 @@ -0,0 +1,2 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/bad-parm-exp4.2 270101 2014-08-17 14:26:12Z jilles $ +eval '${foo:@abc}' diff --git a/bin/1sh/tests/errors/bad-parm-exp4.2.stderr b/bin/1sh/tests/errors/bad-parm-exp4.2.stderr new file mode 100644 index 00000000..3363f517 --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp4.2.stderr @@ -0,0 +1 @@ +eval: ${foo:@...}: Bad substitution diff --git a/bin/1sh/tests/errors/bad-parm-exp5.2 b/bin/1sh/tests/errors/bad-parm-exp5.2 new file mode 100644 index 00000000..6309c902 --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp5.2 @@ -0,0 +1,2 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/bad-parm-exp5.2 270101 2014-08-17 14:26:12Z jilles $ +eval '${/}' diff --git a/bin/1sh/tests/errors/bad-parm-exp5.2.stderr b/bin/1sh/tests/errors/bad-parm-exp5.2.stderr new file mode 100644 index 00000000..13763f8e --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp5.2.stderr @@ -0,0 +1 @@ +eval: ${/}: Bad substitution diff --git a/bin/1sh/tests/errors/bad-parm-exp6.2 b/bin/1sh/tests/errors/bad-parm-exp6.2 new file mode 100644 index 00000000..c58ea713 --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp6.2 @@ -0,0 +1,2 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/bad-parm-exp6.2 270101 2014-08-17 14:26:12Z jilles $ +eval '${#foo^}' diff --git a/bin/1sh/tests/errors/bad-parm-exp6.2.stderr b/bin/1sh/tests/errors/bad-parm-exp6.2.stderr new file mode 100644 index 00000000..cc56f65b --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp6.2.stderr @@ -0,0 +1 @@ +eval: ${foo...}: Bad substitution diff --git a/bin/1sh/tests/errors/bad-parm-exp7.0 b/bin/1sh/tests/errors/bad-parm-exp7.0 new file mode 100644 index 00000000..11469e23 --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp7.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/bad-parm-exp7.0 287081 2015-08-23 20:44:53Z jilles $ + +v=1 +eval ": $(printf '${v-${\372}}')" diff --git a/bin/1sh/tests/errors/bad-parm-exp8.0 b/bin/1sh/tests/errors/bad-parm-exp8.0 new file mode 100644 index 00000000..3a545eea --- /dev/null +++ b/bin/1sh/tests/errors/bad-parm-exp8.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/bad-parm-exp8.0 287081 2015-08-23 20:44:53Z jilles $ + +v=1 +eval ": $(printf '${v-${w\372}}')" diff --git a/bin/1sh/tests/errors/option-error.0 b/bin/1sh/tests/errors/option-error.0 new file mode 100644 index 00000000..d28d709f --- /dev/null +++ b/bin/1sh/tests/errors/option-error.0 @@ -0,0 +1,46 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/option-error.0 213738 2010-10-12 18:20:38Z obrien $ +IFS=, + +SPECIAL="break abc,\ + continue abc,\ + ., + exit abc, + export -x, + readonly -x, + return abc, + set -z, + shift abc, + trap -y, + unset -y" + +UTILS="alias -y,\ + cat -z,\ + cd abc def,\ + command break abc,\ + expr 1 +,\ + fc -z,\ + getopts,\ + hash -z,\ + jobs -z,\ + printf,\ + pwd abc,\ + read,\ + test abc =,\ + ulimit -z,\ + umask -z,\ + unalias -z,\ + wait abc" + +# Special built-in utilities must abort on an option or operand error. +set -- ${SPECIAL} +for cmd in "$@" +do + ${SH} -c "${cmd}; exit 0" 2>/dev/null && exit 1 +done + +# Other utilities must not abort. +set -- ${UTILS} +for cmd in "$@" +do + ${SH} -c "${cmd}; exit 0" 2>/dev/null || exit 1 +done diff --git a/bin/1sh/tests/errors/redirection-error.0 b/bin/1sh/tests/errors/redirection-error.0 new file mode 100644 index 00000000..221bbb07 --- /dev/null +++ b/bin/1sh/tests/errors/redirection-error.0 @@ -0,0 +1,53 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/redirection-error.0 213738 2010-10-12 18:20:38Z obrien $ +IFS=, + +SPECIAL="break,\ + :,\ + continue,\ + . /dev/null, + eval, + exec, + export -p, + readonly -p, + set, + shift, + times, + trap, + unset foo" + +UTILS="alias,\ + bg,\ + bind,\ + cd,\ + command echo,\ + echo,\ + false,\ + fc -l,\ + fg,\ + getopts a -a,\ + hash,\ + jobs,\ + printf a,\ + pwd,\ + read var < /dev/null,\ + test,\ + true,\ + type ls,\ + ulimit,\ + umask,\ + unalias -a,\ + wait" + +# Special built-in utilities must abort on a redirection error. +set -- ${SPECIAL} +for cmd in "$@" +do + ${SH} -c "${cmd} > /; exit 0" 2>/dev/null && exit 1 +done + +# Other utilities must not abort. +set -- ${UTILS} +for cmd in "$@" +do + ${SH} -c "${cmd} > /; exit 0" 2>/dev/null || exit 1 +done diff --git a/bin/1sh/tests/errors/redirection-error2.2 b/bin/1sh/tests/errors/redirection-error2.2 new file mode 100644 index 00000000..a81406f4 --- /dev/null +++ b/bin/1sh/tests/errors/redirection-error2.2 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/redirection-error2.2 213738 2010-10-12 18:20:38Z obrien $ + +# sh should fail gracefully on this bad redirect +${SH} -c 'echo 1 >&$a' 2>/dev/null diff --git a/bin/1sh/tests/errors/redirection-error3.0 b/bin/1sh/tests/errors/redirection-error3.0 new file mode 100644 index 00000000..586beed8 --- /dev/null +++ b/bin/1sh/tests/errors/redirection-error3.0 @@ -0,0 +1,54 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/redirection-error3.0 213738 2010-10-12 18:20:38Z obrien $ +IFS=, + +SPECIAL="break,\ + :,\ + continue,\ + . /dev/null,\ + eval,\ + exec,\ + export -p,\ + readonly -p,\ + set,\ + shift,\ + times,\ + trap,\ + unset foo" + +UTILS="alias,\ + bg,\ + bind,\ + cd,\ + command echo,\ + echo,\ + false,\ + fc -l,\ + fg,\ + getopts a -a,\ + hash,\ + jobs,\ + printf a,\ + pwd,\ + read var < /dev/null,\ + test,\ + true,\ + type ls,\ + ulimit,\ + umask,\ + unalias -a,\ + wait" + +# When used with 'command', neither special built-in utilities nor other +# utilities must abort on a redirection error. + +set -- ${SPECIAL} +for cmd in "$@" +do + ${SH} -c "command ${cmd} > /; exit 0" 2>/dev/null || exit 1 +done + +set -- ${UTILS} +for cmd in "$@" +do + ${SH} -c "command ${cmd} > /; exit 0" 2>/dev/null || exit 1 +done diff --git a/bin/1sh/tests/errors/redirection-error4.0 b/bin/1sh/tests/errors/redirection-error4.0 new file mode 100644 index 00000000..ed8ae732 --- /dev/null +++ b/bin/1sh/tests/errors/redirection-error4.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/redirection-error4.0 205138 2010-03-13 22:53:17Z jilles $ +# A redirection error should not abort the shell if there is no command word. +exec 2>/dev/null +</var/empty/x +</var/empty/x y=2 +y=2 </var/empty/x +exit 0 diff --git a/bin/1sh/tests/errors/redirection-error5.0 b/bin/1sh/tests/errors/redirection-error5.0 new file mode 100644 index 00000000..72bc9867 --- /dev/null +++ b/bin/1sh/tests/errors/redirection-error5.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/redirection-error5.0 205153 2010-03-14 13:51:12Z jilles $ +# A redirection error on a subshell should not abort the shell. +exec 2>/dev/null +( echo bad ) </var/empty/x +exit 0 diff --git a/bin/1sh/tests/errors/redirection-error6.0 b/bin/1sh/tests/errors/redirection-error6.0 new file mode 100644 index 00000000..ccfc925f --- /dev/null +++ b/bin/1sh/tests/errors/redirection-error6.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/redirection-error6.0 205154 2010-03-14 14:24:35Z jilles $ +# A redirection error on a compound command should not abort the shell. +exec 2>/dev/null +{ echo bad; } </var/empty/x +if :; then echo bad; fi </var/empty/x +for i in 1; do echo bad; done </var/empty/x +i=0 +while [ $i = 0 ]; do echo bad; i=1; done </var/empty/x +i=0 +until [ $i != 0 ]; do echo bad; i=1; done </var/empty/x +case i in *) echo bad ;; esac </var/empty/x +exit 0 diff --git a/bin/1sh/tests/errors/redirection-error7.0 b/bin/1sh/tests/errors/redirection-error7.0 new file mode 100644 index 00000000..3ce8777b --- /dev/null +++ b/bin/1sh/tests/errors/redirection-error7.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/redirection-error7.0 216851 2010-12-31 18:20:17Z jilles $ + +! dummy=$( + exec 3>&1 >&2 2>&3 + ulimit -n 9 + exec 9<. +) && [ -n "$dummy" ] diff --git a/bin/1sh/tests/errors/redirection-error8.0 b/bin/1sh/tests/errors/redirection-error8.0 new file mode 100644 index 00000000..b6c2f410 --- /dev/null +++ b/bin/1sh/tests/errors/redirection-error8.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/redirection-error8.0 319575 2017-06-04 20:52:55Z jilles $ + +$SH -c '{ { :; } </var/empty/x; } 2>/dev/null || kill -INT $$; echo continued' +r=$? +[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ] diff --git a/bin/1sh/tests/errors/write-error1.0 b/bin/1sh/tests/errors/write-error1.0 new file mode 100644 index 00000000..6e4f363f --- /dev/null +++ b/bin/1sh/tests/errors/write-error1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/errors/write-error1.0 244924 2013-01-01 12:48:24Z jilles $ + +! echo >&- 2>/dev/null diff --git a/bin/1sh/tests/execution/Makefile b/bin/1sh/tests/execution/Makefile new file mode 100644 index 00000000..966bc93c --- /dev/null +++ b/bin/1sh/tests/execution/Makefile @@ -0,0 +1,64 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/Makefile 345487 2019-03-24 22:10:26Z jilles $ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +${PACKAGE}FILES+= bg1.0 +${PACKAGE}FILES+= bg2.0 +${PACKAGE}FILES+= bg3.0 +${PACKAGE}FILES+= bg4.0 +${PACKAGE}FILES+= bg5.0 +${PACKAGE}FILES+= bg6.0 bg6.0.stdout +${PACKAGE}FILES+= bg7.0 +${PACKAGE}FILES+= bg8.0 +${PACKAGE}FILES+= bg9.0 +${PACKAGE}FILES+= bg10.0 bg10.0.stdout +${PACKAGE}FILES+= fork1.0 +${PACKAGE}FILES+= fork2.0 +${PACKAGE}FILES+= fork3.0 +${PACKAGE}FILES+= func1.0 +${PACKAGE}FILES+= func2.0 +${PACKAGE}FILES+= func3.0 +${PACKAGE}FILES+= hash1.0 +${PACKAGE}FILES+= int-cmd1.0 +${PACKAGE}FILES+= killed1.0 +${PACKAGE}FILES+= killed2.0 +${PACKAGE}FILES+= not1.0 +${PACKAGE}FILES+= not2.0 +${PACKAGE}FILES+= path1.0 +${PACKAGE}FILES+= pipefail1.0 +${PACKAGE}FILES+= pipefail2.42 +${PACKAGE}FILES+= pipefail3.42 +${PACKAGE}FILES+= pipefail4.42 +${PACKAGE}FILES+= pipefail5.42 +${PACKAGE}FILES+= pipefail6.42 +${PACKAGE}FILES+= pipefail7.0 +${PACKAGE}FILES+= redir1.0 +${PACKAGE}FILES+= redir2.0 +${PACKAGE}FILES+= redir3.0 +${PACKAGE}FILES+= redir4.0 +${PACKAGE}FILES+= redir5.0 +${PACKAGE}FILES+= redir6.0 +${PACKAGE}FILES+= redir7.0 +${PACKAGE}FILES+= set-C1.0 +${PACKAGE}FILES+= set-n1.0 +${PACKAGE}FILES+= set-n2.0 +${PACKAGE}FILES+= set-n3.0 +${PACKAGE}FILES+= set-n4.0 +${PACKAGE}FILES+= set-x1.0 +${PACKAGE}FILES+= set-x2.0 +${PACKAGE}FILES+= set-x3.0 +${PACKAGE}FILES+= set-x4.0 +${PACKAGE}FILES+= shellproc1.0 +${PACKAGE}FILES+= subshell1.0 subshell1.0.stdout +${PACKAGE}FILES+= subshell2.0 +${PACKAGE}FILES+= subshell3.0 +${PACKAGE}FILES+= subshell4.0 +${PACKAGE}FILES+= unknown1.0 +${PACKAGE}FILES+= var-assign1.0 + +.include <bsd.test.mk> diff --git a/bin/1sh/tests/execution/Makefile.depend b/bin/1sh/tests/execution/Makefile.depend new file mode 100644 index 00000000..746c07a0 --- /dev/null +++ b/bin/1sh/tests/execution/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/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/execution/bg1.0 b/bin/1sh/tests/execution/bg1.0 new file mode 100644 index 00000000..b7277fa8 --- /dev/null +++ b/bin/1sh/tests/execution/bg1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/bg1.0 221027 2011-04-25 20:54:12Z jilles $ + +: `false` & diff --git a/bin/1sh/tests/execution/bg10.0 b/bin/1sh/tests/execution/bg10.0 new file mode 100644 index 00000000..9eb15ed2 --- /dev/null +++ b/bin/1sh/tests/execution/bg10.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/bg10.0 258535 2013-11-24 23:12:13Z jilles $ +# The redirection overrides the </dev/null implicit in a background command. + +echo yes | ${SH} -c '{ cat & wait; } <&0' diff --git a/bin/1sh/tests/execution/bg10.0.stdout b/bin/1sh/tests/execution/bg10.0.stdout new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/bin/1sh/tests/execution/bg10.0.stdout @@ -0,0 +1 @@ +yes diff --git a/bin/1sh/tests/execution/bg2.0 b/bin/1sh/tests/execution/bg2.0 new file mode 100644 index 00000000..d0593687 --- /dev/null +++ b/bin/1sh/tests/execution/bg2.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/bg2.0 221027 2011-04-25 20:54:12Z jilles $ + +f() { return 42; } +f +: | : & diff --git a/bin/1sh/tests/execution/bg3.0 b/bin/1sh/tests/execution/bg3.0 new file mode 100644 index 00000000..e218ecd0 --- /dev/null +++ b/bin/1sh/tests/execution/bg3.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/bg3.0 221027 2011-04-25 20:54:12Z jilles $ + +f() { return 42; } +f +(:) & diff --git a/bin/1sh/tests/execution/bg4.0 b/bin/1sh/tests/execution/bg4.0 new file mode 100644 index 00000000..ddb5891f --- /dev/null +++ b/bin/1sh/tests/execution/bg4.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/bg4.0 223283 2011-06-19 00:00:36Z jilles $ + +x='' +: ${x:=1} & +wait +exit ${x:-0} diff --git a/bin/1sh/tests/execution/bg5.0 b/bin/1sh/tests/execution/bg5.0 new file mode 100644 index 00000000..cb9883ad --- /dev/null +++ b/bin/1sh/tests/execution/bg5.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/bg5.0 258489 2013-11-22 21:50:13Z jilles $ +# A background command has an implicit </dev/null redirection. + +echo bad | ${SH} -c '{ cat & wait; }' diff --git a/bin/1sh/tests/execution/bg6.0 b/bin/1sh/tests/execution/bg6.0 new file mode 100644 index 00000000..2883d2d4 --- /dev/null +++ b/bin/1sh/tests/execution/bg6.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/bg6.0 258489 2013-11-22 21:50:13Z jilles $ +# The redirection overrides the </dev/null implicit in a background command. + +echo yes | ${SH} -c '{ cat & wait; } </dev/stdin' diff --git a/bin/1sh/tests/execution/bg6.0.stdout b/bin/1sh/tests/execution/bg6.0.stdout new file mode 100644 index 00000000..7cfab5b0 --- /dev/null +++ b/bin/1sh/tests/execution/bg6.0.stdout @@ -0,0 +1 @@ +yes diff --git a/bin/1sh/tests/execution/bg7.0 b/bin/1sh/tests/execution/bg7.0 new file mode 100644 index 00000000..f15c3c21 --- /dev/null +++ b/bin/1sh/tests/execution/bg7.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/bg7.0 258533 2013-11-24 22:45:49Z jilles $ +# The redirection does not apply to the background command, and therefore +# does not override the implicit </dev/null. + +echo bad | ${SH} -c '</dev/null; { cat & wait; }' diff --git a/bin/1sh/tests/execution/bg8.0 b/bin/1sh/tests/execution/bg8.0 new file mode 100644 index 00000000..43c1e3f0 --- /dev/null +++ b/bin/1sh/tests/execution/bg8.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/bg8.0 258533 2013-11-24 22:45:49Z jilles $ +# The redirection does not apply to the background command, and therefore +# does not override the implicit </dev/null. + +echo bad | ${SH} -c 'command eval \) </dev/null 2>/dev/null; { cat & wait; }' diff --git a/bin/1sh/tests/execution/bg9.0 b/bin/1sh/tests/execution/bg9.0 new file mode 100644 index 00000000..4fee9946 --- /dev/null +++ b/bin/1sh/tests/execution/bg9.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/bg9.0 258533 2013-11-24 22:45:49Z jilles $ +# The redirection does not apply to the background command, and therefore +# does not override the implicit </dev/null. + +echo bad | ${SH} -c 'command eval eval \\\) \</dev/null 2>/dev/null; { cat & wait; }' diff --git a/bin/1sh/tests/execution/fork1.0 b/bin/1sh/tests/execution/fork1.0 new file mode 100644 index 00000000..edd8f6ad --- /dev/null +++ b/bin/1sh/tests/execution/fork1.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/fork1.0 218850 2011-02-19 13:22:18Z jilles $ + +shname=${SH%% *} +shname=${shname##*/} + +result=$(${SH} -c 'ps -p $$ -o comm=') +test "$result" = "ps" || exit 1 + +result=$(${SH} -c 'ps -p $$ -o comm=; :') +test "$result" = "$shname" || exit 1 diff --git a/bin/1sh/tests/execution/fork2.0 b/bin/1sh/tests/execution/fork2.0 new file mode 100644 index 00000000..f85f7e0a --- /dev/null +++ b/bin/1sh/tests/execution/fork2.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/fork2.0 213738 2010-10-12 18:20:38Z obrien $ + +result=$(${SH} -c '(/bin/sleep 1)& sleep 0.1; ps -p $! -o comm=; kill $!') +test "$result" = sleep || exit 1 + +result=$(${SH} -c '{ trap "echo trapped" EXIT; (/usr/bin/true); } & wait') +test "$result" = trapped || exit 1 + +exit 0 diff --git a/bin/1sh/tests/execution/fork3.0 b/bin/1sh/tests/execution/fork3.0 new file mode 100644 index 00000000..101a16c6 --- /dev/null +++ b/bin/1sh/tests/execution/fork3.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/fork3.0 220978 2011-04-23 22:28:56Z jilles $ + +result=$(${SH} -c 'f() { ps -p $$ -o comm=; }; f') +test "$result" = "ps" diff --git a/bin/1sh/tests/execution/func1.0 b/bin/1sh/tests/execution/func1.0 new file mode 100644 index 00000000..25b4781f --- /dev/null +++ b/bin/1sh/tests/execution/func1.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/func1.0 213738 2010-10-12 18:20:38Z obrien $ + +MALLOC_OPTIONS=J ${SH} -c 'g() { g() { :; }; :; }; g' && +MALLOC_OPTIONS=J ${SH} -c 'g() { unset -f g; :; }; g' diff --git a/bin/1sh/tests/execution/func2.0 b/bin/1sh/tests/execution/func2.0 new file mode 100644 index 00000000..a1f3e0cc --- /dev/null +++ b/bin/1sh/tests/execution/func2.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/func2.0 211399 2010-08-16 17:18:08Z jilles $ +# The empty pairs of braces here are to test that this does not cause a crash. + +f() { } +f +hash -v f >/dev/null +f() { { }; } +f +hash -v f >/dev/null +f() { { } } +f +hash -v f >/dev/null diff --git a/bin/1sh/tests/execution/func3.0 b/bin/1sh/tests/execution/func3.0 new file mode 100644 index 00000000..a92c12f6 --- /dev/null +++ b/bin/1sh/tests/execution/func3.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/func3.0 216398 2010-12-12 21:18:16Z jilles $ + +# This may fail when parsing or when defining the function, or the definition +# may silently do nothing. In no event may the function be executed. + +${SH} -c 'unset() { echo overriding function executed, bad; }; v=1; unset v; exit "${v-0}"' 2>/dev/null +: diff --git a/bin/1sh/tests/execution/hash1.0 b/bin/1sh/tests/execution/hash1.0 new file mode 100644 index 00000000..e47b86c8 --- /dev/null +++ b/bin/1sh/tests/execution/hash1.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/hash1.0 218323 2011-02-05 14:01:46Z jilles $ + +T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit +trap 'rm -rf "${T}"' 0 +PATH=$T:$PATH +ls -ld . >/dev/null +cat <<EOF >"$T/ls" +: +EOF +chmod 755 "$T/ls" +PATH=$PATH +ls -ld . diff --git a/bin/1sh/tests/execution/int-cmd1.0 b/bin/1sh/tests/execution/int-cmd1.0 new file mode 100644 index 00000000..6c415646 --- /dev/null +++ b/bin/1sh/tests/execution/int-cmd1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/int-cmd1.0 253271 2013-07-12 15:29:41Z jilles $ + +! echo echo bad | $SH -ic 'fi' 2>/dev/null diff --git a/bin/1sh/tests/execution/killed1.0 b/bin/1sh/tests/execution/killed1.0 new file mode 100644 index 00000000..c5b36ab6 --- /dev/null +++ b/bin/1sh/tests/execution/killed1.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/killed1.0 217557 2011-01-18 21:18:31Z jilles $ +# Sometimes the "Killed" message is not flushed soon enough and it +# is redirected along with the output of a builtin. +# Do not change the semicolon to a newline as it would hide the bug. + +exec 3>&1 +exec >/dev/null 2>&1 +${SH} -c 'kill -9 $$'; : >&3 2>&3 diff --git a/bin/1sh/tests/execution/killed2.0 b/bin/1sh/tests/execution/killed2.0 new file mode 100644 index 00000000..6d7a40e6 --- /dev/null +++ b/bin/1sh/tests/execution/killed2.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/killed2.0 218105 2011-01-30 22:57:52Z jilles $ +# Most shells print a message when a foreground job is killed by a signal. +# POSIX allows this, provided the message is sent to stderr, not stdout. +# Some trickery is needed to capture the message as redirecting stderr of +# the command itself does not affect it. The colon command ensures that +# the subshell forks for ${SH}. + +exec 3>&1 +r=`(${SH} -c 'kill $$'; :) 2>&1 >&3` +[ -n "$r" ] diff --git a/bin/1sh/tests/execution/not1.0 b/bin/1sh/tests/execution/not1.0 new file mode 100644 index 00000000..8e329c9b --- /dev/null +++ b/bin/1sh/tests/execution/not1.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/not1.0 249407 2013-04-12 15:19:35Z jilles $ + +f() { ! return $1; } +f 0 && ! f 1 diff --git a/bin/1sh/tests/execution/not2.0 b/bin/1sh/tests/execution/not2.0 new file mode 100644 index 00000000..0930f243 --- /dev/null +++ b/bin/1sh/tests/execution/not2.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/not2.0 249407 2013-04-12 15:19:35Z jilles $ + +while :; do + ! break + exit 3 +done diff --git a/bin/1sh/tests/execution/path1.0 b/bin/1sh/tests/execution/path1.0 new file mode 100644 index 00000000..63ab97a1 --- /dev/null +++ b/bin/1sh/tests/execution/path1.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/path1.0 217206 2011-01-09 21:07:30Z jilles $ +# Some builtins should not be overridable via PATH. + +set -e +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) +trap 'rm -rf ${T}' 0 +echo '#!/bin/sh +echo bad' >"$T/cd" +chmod 755 "$T/cd" +cd /bin +oPATH=$PATH +PATH=$T:$PATH:%builtin +cd / +PATH=$oPATH +[ "$(pwd)" = / ] diff --git a/bin/1sh/tests/execution/pipefail1.0 b/bin/1sh/tests/execution/pipefail1.0 new file mode 100644 index 00000000..4835d8c0 --- /dev/null +++ b/bin/1sh/tests/execution/pipefail1.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/pipefail1.0 345487 2019-03-24 22:10:26Z jilles $ + +set -o pipefail +: && : | : && : | : | : && : | : | : | : diff --git a/bin/1sh/tests/execution/pipefail2.42 b/bin/1sh/tests/execution/pipefail2.42 new file mode 100644 index 00000000..1d9d2759 --- /dev/null +++ b/bin/1sh/tests/execution/pipefail2.42 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/pipefail2.42 345487 2019-03-24 22:10:26Z jilles $ + +set -o pipefail +(exit 42) | : diff --git a/bin/1sh/tests/execution/pipefail3.42 b/bin/1sh/tests/execution/pipefail3.42 new file mode 100644 index 00000000..17f49894 --- /dev/null +++ b/bin/1sh/tests/execution/pipefail3.42 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/pipefail3.42 345487 2019-03-24 22:10:26Z jilles $ + +set -o pipefail +: | (exit 42) diff --git a/bin/1sh/tests/execution/pipefail4.42 b/bin/1sh/tests/execution/pipefail4.42 new file mode 100644 index 00000000..a7c9b4ad --- /dev/null +++ b/bin/1sh/tests/execution/pipefail4.42 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/pipefail4.42 345487 2019-03-24 22:10:26Z jilles $ + +set -o pipefail +(exit 43) | (exit 42) diff --git a/bin/1sh/tests/execution/pipefail5.42 b/bin/1sh/tests/execution/pipefail5.42 new file mode 100644 index 00000000..7882d8a5 --- /dev/null +++ b/bin/1sh/tests/execution/pipefail5.42 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/pipefail5.42 345487 2019-03-24 22:10:26Z jilles $ + +set -o pipefail +(exit 42) | : & +wait %+ diff --git a/bin/1sh/tests/execution/pipefail6.42 b/bin/1sh/tests/execution/pipefail6.42 new file mode 100644 index 00000000..70d84d72 --- /dev/null +++ b/bin/1sh/tests/execution/pipefail6.42 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/pipefail6.42 345487 2019-03-24 22:10:26Z jilles $ + +set -o pipefail +(exit 42) | : & +set +o pipefail +wait %+ diff --git a/bin/1sh/tests/execution/pipefail7.0 b/bin/1sh/tests/execution/pipefail7.0 new file mode 100644 index 00000000..1a23e90d --- /dev/null +++ b/bin/1sh/tests/execution/pipefail7.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/pipefail7.0 345487 2019-03-24 22:10:26Z jilles $ + +(exit 42) | : & +set -o pipefail +wait %+ diff --git a/bin/1sh/tests/execution/redir1.0 b/bin/1sh/tests/execution/redir1.0 new file mode 100644 index 00000000..797e42b2 --- /dev/null +++ b/bin/1sh/tests/execution/redir1.0 @@ -0,0 +1,27 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/redir1.0 211408 2010-08-16 22:23:19Z jilles $ +trap ': $((brokenpipe+=1))' PIPE + +P=${TMPDIR:-/tmp} +cd $P +T=$(mktemp -d sh-test.XXXXXX) +cd $T + +brokenpipe=0 +mkfifo fifo1 fifo2 +read dummy >fifo2 <fifo1 & +{ + exec 4>fifo2 +} 3<fifo2 # Formerly, sh would keep fd 3 and a duplicate of it open. +echo dummy >fifo1 +if [ $brokenpipe -ne 0 ]; then + rc=3 +fi +wait +echo dummy >&4 2>/dev/null +if [ $brokenpipe -eq 1 ]; then + : ${rc:=0} +fi + +rm fifo1 fifo2 +rmdir ${P}/${T} +exit ${rc:-3} diff --git a/bin/1sh/tests/execution/redir2.0 b/bin/1sh/tests/execution/redir2.0 new file mode 100644 index 00000000..1e2a9c16 --- /dev/null +++ b/bin/1sh/tests/execution/redir2.0 @@ -0,0 +1,29 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/redir2.0 213738 2010-10-12 18:20:38Z obrien $ +trap ': $((brokenpipe+=1))' PIPE + +P=${TMPDIR:-/tmp} +cd $P +T=$(mktemp -d sh-test.XXXXXX) +cd $T + +brokenpipe=0 +mkfifo fifo1 fifo2 +{ + { + exec ${SH} -c 'exec <fifo1; read dummy' + } 7<&- # fifo2 should be kept open, but not passed to programs + true +} 7<fifo2 & + +exec 4>fifo2 +exec 3>fifo1 +echo dummy >&4 2>/dev/null +if [ $brokenpipe -eq 1 ]; then + : ${rc:=0} +fi +echo dummy >&3 +wait + +rm fifo1 fifo2 +rmdir ${P}/${T} +exit ${rc:-3} diff --git a/bin/1sh/tests/execution/redir3.0 b/bin/1sh/tests/execution/redir3.0 new file mode 100644 index 00000000..ddd9e1c3 --- /dev/null +++ b/bin/1sh/tests/execution/redir3.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/redir3.0 214289 2010-10-24 19:56:34Z jilles $ + +3>&- 3>&- diff --git a/bin/1sh/tests/execution/redir4.0 b/bin/1sh/tests/execution/redir4.0 new file mode 100644 index 00000000..02cd9a8c --- /dev/null +++ b/bin/1sh/tests/execution/redir4.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/redir4.0 214290 2010-10-24 20:09:49Z jilles $ + +{ echo bad 0>&3; } 2>/dev/null 3>/dev/null 3>&- +exit 0 diff --git a/bin/1sh/tests/execution/redir5.0 b/bin/1sh/tests/execution/redir5.0 new file mode 100644 index 00000000..f0247102 --- /dev/null +++ b/bin/1sh/tests/execution/redir5.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/redir5.0 218325 2011-02-05 15:02:19Z jilles $ + +{ (echo bad) >/dev/null; } </dev/null diff --git a/bin/1sh/tests/execution/redir6.0 b/bin/1sh/tests/execution/redir6.0 new file mode 100644 index 00000000..846869d4 --- /dev/null +++ b/bin/1sh/tests/execution/redir6.0 @@ -0,0 +1,21 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/redir6.0 220978 2011-04-23 22:28:56Z jilles $ + +failures=0 + +check() { + if [ "$2" != "$3" ]; then + echo "Failure at $1" >&2 + failures=$((failures + 1)) + fi +} + +check $LINENO "$(trap "echo bye" EXIT; : >/dev/null)" bye +check $LINENO "$(trap "echo bye" EXIT; { :; } >/dev/null)" bye +check $LINENO "$(trap "echo bye" EXIT; (:) >/dev/null)" bye +check $LINENO "$(trap "echo bye" EXIT; (: >/dev/null))" bye +check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; : >/dev/null')" bye +check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; { :; } >/dev/null')" bye +check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; (:) >/dev/null')" bye +check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; (: >/dev/null)')" bye + +exit $((failures > 0)) diff --git a/bin/1sh/tests/execution/redir7.0 b/bin/1sh/tests/execution/redir7.0 new file mode 100644 index 00000000..f47c9db8 --- /dev/null +++ b/bin/1sh/tests/execution/redir7.0 @@ -0,0 +1,21 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/redir7.0 220978 2011-04-23 22:28:56Z jilles $ + +failures=0 + +check() { + if [ "$2" != "$3" ]; then + echo "Failure at $1" >&2 + failures=$((failures + 1)) + fi +} + +check $LINENO "$(trap "echo bye" EXIT; f() { :; }; f >/dev/null)" bye +check $LINENO "$(trap "echo bye" EXIT; f() { :; }; { f; } >/dev/null)" bye +check $LINENO "$(trap "echo bye" EXIT; f() { :; }; (f) >/dev/null)" bye +check $LINENO "$(trap "echo bye" EXIT; f() { :; }; (f >/dev/null))" bye +check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; f >/dev/null')" bye +check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; { f; } >/dev/null')" bye +check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; (f) >/dev/null')" bye +check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; (f >/dev/null)')" bye + +exit $((failures > 0)) diff --git a/bin/1sh/tests/execution/set-C1.0 b/bin/1sh/tests/execution/set-C1.0 new file mode 100644 index 00000000..736eefa6 --- /dev/null +++ b/bin/1sh/tests/execution/set-C1.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/set-C1.0 308229 2016-11-02 22:33:37Z jilles $ + +T=$(mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX") || exit +trap 'rm -rf "$T"' 0 + +set -C +echo . >"$T/a" && +[ -s "$T/a" ] && +{ ! true >"$T/a"; } 2>/dev/null && +[ -s "$T/a" ] && +ln -s /dev/null "$T/b" && +true >"$T/b" diff --git a/bin/1sh/tests/execution/set-n1.0 b/bin/1sh/tests/execution/set-n1.0 new file mode 100644 index 00000000..19afbda3 --- /dev/null +++ b/bin/1sh/tests/execution/set-n1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/set-n1.0 222661 2011-06-03 21:17:42Z jilles $ + +v=$( ($SH -n <<'EOF' +for +EOF +) 2>&1 >/dev/null) +[ $? -ne 0 ] && [ -n "$v" ] diff --git a/bin/1sh/tests/execution/set-n2.0 b/bin/1sh/tests/execution/set-n2.0 new file mode 100644 index 00000000..a6d9a1e4 --- /dev/null +++ b/bin/1sh/tests/execution/set-n2.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/set-n2.0 222661 2011-06-03 21:17:42Z jilles $ + +$SH -n <<'EOF' +echo bad +EOF diff --git a/bin/1sh/tests/execution/set-n3.0 b/bin/1sh/tests/execution/set-n3.0 new file mode 100644 index 00000000..65214703 --- /dev/null +++ b/bin/1sh/tests/execution/set-n3.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/set-n3.0 222661 2011-06-03 21:17:42Z jilles $ + +v=$( ($SH -nc 'for') 2>&1 >/dev/null) +[ $? -ne 0 ] && [ -n "$v" ] diff --git a/bin/1sh/tests/execution/set-n4.0 b/bin/1sh/tests/execution/set-n4.0 new file mode 100644 index 00000000..a7584dc3 --- /dev/null +++ b/bin/1sh/tests/execution/set-n4.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/set-n4.0 222676 2011-06-04 11:28:42Z jilles $ + +$SH -nc 'echo bad' diff --git a/bin/1sh/tests/execution/set-x1.0 b/bin/1sh/tests/execution/set-x1.0 new file mode 100644 index 00000000..8c8d11e4 --- /dev/null +++ b/bin/1sh/tests/execution/set-x1.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/set-x1.0 222882 2011-06-08 21:58:19Z jilles $ + +key='must_contain_this' +{ r=`set -x; { : "$key"; } 2>&1 >/dev/null`; } 2>/dev/null +case $r in +*"$key"*) true ;; +*) false ;; +esac diff --git a/bin/1sh/tests/execution/set-x2.0 b/bin/1sh/tests/execution/set-x2.0 new file mode 100644 index 00000000..0c5073b5 --- /dev/null +++ b/bin/1sh/tests/execution/set-x2.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/set-x2.0 222882 2011-06-08 21:58:19Z jilles $ + +key='must contain this' +PS4="$key+ " +{ r=`set -x; { :; } 2>&1 >/dev/null`; } 2>/dev/null +case $r in +*"$key"*) true ;; +*) false ;; +esac diff --git a/bin/1sh/tests/execution/set-x3.0 b/bin/1sh/tests/execution/set-x3.0 new file mode 100644 index 00000000..195219b2 --- /dev/null +++ b/bin/1sh/tests/execution/set-x3.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/set-x3.0 222907 2011-06-09 23:12:23Z jilles $ + +key='must contain this' +PS4='$key+ ' +{ r=`set -x; { :; } 2>&1 >/dev/null`; } 2>/dev/null +case $r in +*"$key"*) true ;; +*) false ;; +esac diff --git a/bin/1sh/tests/execution/set-x4.0 b/bin/1sh/tests/execution/set-x4.0 new file mode 100644 index 00000000..fcc638ec --- /dev/null +++ b/bin/1sh/tests/execution/set-x4.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/set-x4.0 275766 2014-12-14 16:26:19Z jilles $ + +key=`printf '\r\t\001\200\300'` +r=`{ set -x; : "$key"; } 2>&1 >/dev/null` +case $r in +*[![:print:]]*) echo fail; exit 3 +esac diff --git a/bin/1sh/tests/execution/shellproc1.0 b/bin/1sh/tests/execution/shellproc1.0 new file mode 100644 index 00000000..2d1fd919 --- /dev/null +++ b/bin/1sh/tests/execution/shellproc1.0 @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/shellproc1.0 218205 2011-02-02 22:03:18Z jilles $ + +T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit +trap 'rm -rf "${T}"' 0 +cat <<EOF >"$T/testshellproc" +printf 'this ' +echo is a test +EOF +chmod 755 "$T/testshellproc" +PATH=$T:$PATH +[ "`testshellproc`" = "this is a test" ] diff --git a/bin/1sh/tests/execution/subshell1.0 b/bin/1sh/tests/execution/subshell1.0 new file mode 100644 index 00000000..83819cc1 --- /dev/null +++ b/bin/1sh/tests/execution/subshell1.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/subshell1.0 245383 2013-01-13 19:39:13Z jilles $ + +(eval "cd / +v=$(printf %0100000d 1) +echo \${#v}") +echo end diff --git a/bin/1sh/tests/execution/subshell1.0.stdout b/bin/1sh/tests/execution/subshell1.0.stdout new file mode 100644 index 00000000..8c71af3c --- /dev/null +++ b/bin/1sh/tests/execution/subshell1.0.stdout @@ -0,0 +1,2 @@ +100000 +end diff --git a/bin/1sh/tests/execution/subshell2.0 b/bin/1sh/tests/execution/subshell2.0 new file mode 100644 index 00000000..e938ff82 --- /dev/null +++ b/bin/1sh/tests/execution/subshell2.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/subshell2.0 245383 2013-01-13 19:39:13Z jilles $ + +f() { + x=2 +} +( + x=1 + f + [ "$x" = 2 ] +) diff --git a/bin/1sh/tests/execution/subshell3.0 b/bin/1sh/tests/execution/subshell3.0 new file mode 100644 index 00000000..f703e9c1 --- /dev/null +++ b/bin/1sh/tests/execution/subshell3.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/subshell3.0 245383 2013-01-13 19:39:13Z jilles $ + +(false; exit) && exit 3 +exit 0 diff --git a/bin/1sh/tests/execution/subshell4.0 b/bin/1sh/tests/execution/subshell4.0 new file mode 100644 index 00000000..37ea313e --- /dev/null +++ b/bin/1sh/tests/execution/subshell4.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/subshell4.0 245383 2013-01-13 19:39:13Z jilles $ + +(eval "set v=1"; false) && echo bad; : diff --git a/bin/1sh/tests/execution/unknown1.0 b/bin/1sh/tests/execution/unknown1.0 new file mode 100644 index 00000000..c4258aa9 --- /dev/null +++ b/bin/1sh/tests/execution/unknown1.0 @@ -0,0 +1,29 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/unknown1.0 197820 2009-10-06 22:00:14Z jilles $ + +nosuchtool 2>/dev/null +[ $? -ne 127 ] && exit 1 +/var/empty/nosuchtool 2>/dev/null +[ $? -ne 127 ] && exit 1 +(nosuchtool) 2>/dev/null +[ $? -ne 127 ] && exit 1 +(/var/empty/nosuchtool) 2>/dev/null +[ $? -ne 127 ] && exit 1 +/ 2>/dev/null +[ $? -ne 126 ] && exit 1 +PATH=/usr bin 2>/dev/null +[ $? -ne 126 ] && exit 1 + +dummy=$(nosuchtool 2>/dev/null) +[ $? -ne 127 ] && exit 1 +dummy=$(/var/empty/nosuchtool 2>/dev/null) +[ $? -ne 127 ] && exit 1 +dummy=$( (nosuchtool) 2>/dev/null) +[ $? -ne 127 ] && exit 1 +dummy=$( (/var/empty/nosuchtool) 2>/dev/null) +[ $? -ne 127 ] && exit 1 +dummy=$(/ 2>/dev/null) +[ $? -ne 126 ] && exit 1 +dummy=$(PATH=/usr bin 2>/dev/null) +[ $? -ne 126 ] && exit 1 + +exit 0 diff --git a/bin/1sh/tests/execution/var-assign1.0 b/bin/1sh/tests/execution/var-assign1.0 new file mode 100644 index 00000000..6507c487 --- /dev/null +++ b/bin/1sh/tests/execution/var-assign1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/execution/var-assign1.0 212467 2010-09-11 14:15:50Z jilles $ + +[ "$(HOME=/etc HOME=/ cd && pwd)" = / ] diff --git a/bin/1sh/tests/expansion/Makefile b/bin/1sh/tests/expansion/Makefile new file mode 100644 index 00000000..a22f0db0 --- /dev/null +++ b/bin/1sh/tests/expansion/Makefile @@ -0,0 +1,112 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/Makefile 345117 2019-03-13 21:53:10Z jilles $ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +${PACKAGE}FILES+= arith1.0 +${PACKAGE}FILES+= arith2.0 +${PACKAGE}FILES+= arith3.0 +${PACKAGE}FILES+= arith4.0 +${PACKAGE}FILES+= arith5.0 +${PACKAGE}FILES+= arith6.0 +${PACKAGE}FILES+= arith7.0 +${PACKAGE}FILES+= arith8.0 +${PACKAGE}FILES+= arith9.0 +${PACKAGE}FILES+= arith10.0 +${PACKAGE}FILES+= arith11.0 +${PACKAGE}FILES+= arith12.0 +${PACKAGE}FILES+= arith13.0 +${PACKAGE}FILES+= arith14.0 +${PACKAGE}FILES+= arith15.0 +${PACKAGE}FILES+= arith16.0 +${PACKAGE}FILES+= arith17.0 +${PACKAGE}FILES+= assign1.0 +${PACKAGE}FILES+= cmdsubst1.0 +${PACKAGE}FILES+= cmdsubst2.0 +${PACKAGE}FILES+= cmdsubst3.0 +${PACKAGE}FILES+= cmdsubst4.0 +${PACKAGE}FILES+= cmdsubst5.0 +${PACKAGE}FILES+= cmdsubst6.0 +${PACKAGE}FILES+= cmdsubst7.0 +${PACKAGE}FILES+= cmdsubst8.0 +${PACKAGE}FILES+= cmdsubst9.0 +${PACKAGE}FILES+= cmdsubst10.0 +${PACKAGE}FILES+= cmdsubst11.0 +${PACKAGE}FILES+= cmdsubst12.0 +${PACKAGE}FILES+= cmdsubst13.0 +${PACKAGE}FILES+= cmdsubst14.0 +${PACKAGE}FILES+= cmdsubst15.0 +${PACKAGE}FILES+= cmdsubst16.0 +${PACKAGE}FILES+= cmdsubst17.0 +${PACKAGE}FILES+= cmdsubst18.0 +${PACKAGE}FILES+= cmdsubst19.0 +${PACKAGE}FILES+= cmdsubst20.0 +${PACKAGE}FILES+= cmdsubst21.0 +${PACKAGE}FILES+= cmdsubst22.0 +${PACKAGE}FILES+= cmdsubst23.0 +${PACKAGE}FILES+= cmdsubst24.0 +${PACKAGE}FILES+= cmdsubst25.0 +${PACKAGE}FILES+= cmdsubst26.0 +${PACKAGE}FILES+= export1.0 +${PACKAGE}FILES+= export2.0 +${PACKAGE}FILES+= export3.0 +${PACKAGE}FILES+= heredoc1.0 +${PACKAGE}FILES+= heredoc2.0 +${PACKAGE}FILES+= ifs1.0 +${PACKAGE}FILES+= ifs2.0 +${PACKAGE}FILES+= ifs3.0 +${PACKAGE}FILES+= ifs4.0 +${PACKAGE}FILES+= ifs5.0 +${PACKAGE}FILES+= ifs6.0 +${PACKAGE}FILES+= ifs7.0 +${PACKAGE}FILES+= length1.0 +${PACKAGE}FILES+= length2.0 +${PACKAGE}FILES+= length3.0 +${PACKAGE}FILES+= length4.0 +${PACKAGE}FILES+= length5.0 +${PACKAGE}FILES+= length6.0 +${PACKAGE}FILES+= length7.0 +${PACKAGE}FILES+= length8.0 +${PACKAGE}FILES+= local1.0 +${PACKAGE}FILES+= local2.0 +${PACKAGE}FILES+= pathname1.0 +${PACKAGE}FILES+= pathname2.0 +${PACKAGE}FILES+= pathname3.0 +${PACKAGE}FILES+= pathname4.0 +${PACKAGE}FILES+= pathname5.0 +${PACKAGE}FILES+= pathname6.0 +${PACKAGE}FILES+= plus-minus1.0 +${PACKAGE}FILES+= plus-minus2.0 +${PACKAGE}FILES+= plus-minus3.0 +${PACKAGE}FILES+= plus-minus4.0 +${PACKAGE}FILES+= plus-minus5.0 +${PACKAGE}FILES+= plus-minus6.0 +${PACKAGE}FILES+= plus-minus7.0 +${PACKAGE}FILES+= plus-minus8.0 +${PACKAGE}FILES+= plus-minus9.0 +${PACKAGE}FILES+= question1.0 +${PACKAGE}FILES+= question2.0 +${PACKAGE}FILES+= readonly1.0 +${PACKAGE}FILES+= redir1.0 +${PACKAGE}FILES+= set-u1.0 +${PACKAGE}FILES+= set-u2.0 +${PACKAGE}FILES+= set-u3.0 +${PACKAGE}FILES+= tilde1.0 +${PACKAGE}FILES+= tilde2.0 +${PACKAGE}FILES+= trim1.0 +${PACKAGE}FILES+= trim2.0 +${PACKAGE}FILES+= trim3.0 +${PACKAGE}FILES+= trim4.0 +${PACKAGE}FILES+= trim5.0 +${PACKAGE}FILES+= trim6.0 +${PACKAGE}FILES+= trim7.0 +${PACKAGE}FILES+= trim8.0 +${PACKAGE}FILES+= trim9.0 +${PACKAGE}FILES+= trim10.0 +${PACKAGE}FILES+= trim11.0 + +.include <bsd.test.mk> diff --git a/bin/1sh/tests/expansion/Makefile.depend b/bin/1sh/tests/expansion/Makefile.depend new file mode 100644 index 00000000..b1212738 --- /dev/null +++ b/bin/1sh/tests/expansion/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/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/expansion/arith1.0 b/bin/1sh/tests/expansion/arith1.0 new file mode 100644 index 00000000..cd5a28df --- /dev/null +++ b/bin/1sh/tests/expansion/arith1.0 @@ -0,0 +1,30 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith1.0 201259 2009-12-30 15:59:40Z jilles $ + +failures=0 + +check() { + if [ $(($1)) != $2 ]; then + failures=$((failures+1)) + echo "For $1, expected $2 actual $(($1))" + fi +} + +check "0&&0" 0 +check "1&&0" 0 +check "0&&1" 0 +check "1&&1" 1 +check "2&&2" 1 +check "1&&2" 1 +check "1<<40&&1<<40" 1 +check "1<<40&&4" 1 + +check "0||0" 0 +check "1||0" 1 +check "0||1" 1 +check "1||1" 1 +check "2||2" 1 +check "1||2" 1 +check "1<<40||1<<40" 1 +check "1<<40||4" 1 + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/arith10.0 b/bin/1sh/tests/expansion/arith10.0 new file mode 100644 index 00000000..4e152463 --- /dev/null +++ b/bin/1sh/tests/expansion/arith10.0 @@ -0,0 +1,35 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith10.0 218469 2011-02-08 23:23:55Z jilles $ + +failures=0 + +check() { + if [ $(($1)) != $2 ]; then + failures=$((failures+1)) + echo "For $1, expected $2 actual $(($1))" + fi +} + +readonly ro=4 +rw=1 +check "0 && 0 / 0" 0 +check "1 || 0 / 0" 1 +check "0 && (ro = 2)" 0 +check "ro" 4 +check "1 || (ro = -1)" 1 +check "ro" 4 +check "0 && (rw += 1)" 0 +check "rw" 1 +check "1 || (rw += 1)" 1 +check "rw" 1 +check "0 ? 44 / 0 : 51" 51 +check "0 ? ro = 3 : 52" 52 +check "ro" 4 +check "0 ? rw += 1 : 52" 52 +check "rw" 1 +check "1 ? 68 : 30 / 0" 68 +check "2 ? 1 : (ro += 2)" 1 +check "ro" 4 +check "4 ? 1 : (rw += 1)" 1 +check "rw" 1 + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/arith11.0 b/bin/1sh/tests/expansion/arith11.0 new file mode 100644 index 00000000..6fc08175 --- /dev/null +++ b/bin/1sh/tests/expansion/arith11.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith11.0 218626 2011-02-12 23:44:05Z jilles $ +# Try to divide the smallest integer by -1. +# On amd64 this causes SIGFPE, so make sure the shell checks. + +# Calculate the minimum possible value, assuming two's complement and +# a certain interpretation of overflow when shifting left. +minint=1 +while [ $((minint <<= 1)) -gt 0 ]; do + : +done +v=$( eval ': $((minint / -1))' 2>&1 >/dev/null) +[ $? -ne 0 ] && [ -n "$v" ] diff --git a/bin/1sh/tests/expansion/arith12.0 b/bin/1sh/tests/expansion/arith12.0 new file mode 100644 index 00000000..69dac270 --- /dev/null +++ b/bin/1sh/tests/expansion/arith12.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith12.0 232839 2012-03-11 22:12:05Z jilles $ + +_x=4 y_=5 z_z=6 +[ "$((_x*100+y_*10+z_z))" = 456 ] diff --git a/bin/1sh/tests/expansion/arith13.0 b/bin/1sh/tests/expansion/arith13.0 new file mode 100644 index 00000000..2142f410 --- /dev/null +++ b/bin/1sh/tests/expansion/arith13.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith13.0 254806 2013-08-24 20:06:00Z jilles $ +# Pre-increment and pre-decrement in arithmetic expansion are not in POSIX. +# Require either an error or a correct implementation. + +! (eval 'x=4; [ $((++x)) != 5 ] || [ $x != 5 ]') 2>/dev/null && +! (eval 'x=2; [ $((--x)) != 1 ] || [ $x != 1 ]') 2>/dev/null diff --git a/bin/1sh/tests/expansion/arith14.0 b/bin/1sh/tests/expansion/arith14.0 new file mode 100644 index 00000000..c6f84701 --- /dev/null +++ b/bin/1sh/tests/expansion/arith14.0 @@ -0,0 +1,40 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith14.0 270029 2014-08-15 22:36:41Z jilles $ +# Check that <</>> use the low bits of the shift count. + +if [ $((1<<16<<16)) = 0 ]; then + width=32 +elif [ $((1<<32<<32)) = 0 ]; then + width=64 +elif [ $((1<<64<<64)) = 0 ]; then + width=128 +elif [ $((1<<64>>64)) = 1 ]; then + # Integers are wider than 128 bits; assume arbitrary precision. + # Nothing to test here. + exit 0 +else + echo "Cannot determine integer width" + exit 2 +fi + +twowidth=$((width * 2)) +j=43 k=$((1 << (width - 2))) r=0 + +i=0 +while [ $i -lt $twowidth ]; do + if [ "$((j << i))" != "$((j << (i + width)))" ]; then + echo "Problem with $j << $i" + r=2 + fi + i=$((i + 1)) +done + +i=0 +while [ $i -lt $twowidth ]; do + if [ "$((k >> i))" != "$((k >> (i + width)))" ]; then + echo "Problem with $k >> $i" + r=2 + fi + i=$((i + 1)) +done + +exit $r diff --git a/bin/1sh/tests/expansion/arith15.0 b/bin/1sh/tests/expansion/arith15.0 new file mode 100644 index 00000000..f9897908 --- /dev/null +++ b/bin/1sh/tests/expansion/arith15.0 @@ -0,0 +1,20 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith15.0 345117 2019-03-13 21:53:10Z jilles $ + +failures=0 + +check() { + if [ $(($1)) != $2 ]; then + failures=$((failures+1)) + echo "For $1, expected $2 actual $(($1))" + fi +} + +XXX=-9223372036854775808 +check "XXX" -9223372036854775808 +check "XXX - 1" 9223372036854775807 +check "$XXX - 1" 9223372036854775807 +check "$XXX - 2" 9223372036854775806 +check "0x8000000000000000 == 0x7fffffffffffffff" \ + 0 + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/arith16.0 b/bin/1sh/tests/expansion/arith16.0 new file mode 100644 index 00000000..619889f8 --- /dev/null +++ b/bin/1sh/tests/expansion/arith16.0 @@ -0,0 +1,26 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith16.0 345117 2019-03-13 21:53:10Z jilles $ + +failures=0 + +for x in \ + 0x10000000000000000 \ + -0x8000000000000001 \ + 0xfffffffffffffffffffffffffffffffff \ + -0xfffffffffffffffffffffffffffffffff \ + 02000000000000000000000 \ + 9223372036854775808 \ + 9223372036854775809 \ + -9223372036854775809 \ + 9999999999999999999999999 \ + -9999999999999999999999999 +do + msg=$({ + v=$((x)) || : + } 3>&1 >&2 2>&3 3>&-) + r=$? + if [ "$r" = 0 ] || [ -z "$msg" ]; then + printf 'Failed: %s\n' "$x" + : $((failures += 1)) + fi +done +exit $((failures > 0)) diff --git a/bin/1sh/tests/expansion/arith17.0 b/bin/1sh/tests/expansion/arith17.0 new file mode 100644 index 00000000..c306a67d --- /dev/null +++ b/bin/1sh/tests/expansion/arith17.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith17.0 345117 2019-03-13 21:53:10Z jilles $ + +[ $((9223372036854775809)) -gt 0 ] diff --git a/bin/1sh/tests/expansion/arith2.0 b/bin/1sh/tests/expansion/arith2.0 new file mode 100644 index 00000000..4e3daf6d --- /dev/null +++ b/bin/1sh/tests/expansion/arith2.0 @@ -0,0 +1,77 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith2.0 209652 2010-07-02 21:31:24Z jilles $ + +failures=0 + +check() { + if [ $(($1)) != $2 ]; then + failures=$((failures+1)) + echo "For $1, expected $2 actual $(($1))" + fi +} + +# variables +unset v +check "v=2" 2 +check "v" 2 +check "$(($v))" 2 +check "v+=1" 3 +check "v" 3 + +# constants +check "4611686018427387904" 4611686018427387904 +check "0x4000000000000000" 4611686018427387904 +check "0400000000000000000000" 4611686018427387904 +check "0x4Ab0000000000000" 5381801554707742720 +check "010" 8 + +# try out all operators +v=42 +check "!v" 0 +check "!!v" 1 +check "!0" 1 +check "~0" -1 +check "~(-1)" 0 +check "-0" 0 +check "-v" -42 +check "v*v" 1764 +check "v/2" 21 +check "v%10" 2 +check "v+v" 84 +check "v-4" 38 +check "v<<1" 84 +check "v>>1" 21 +check "v<43" 1 +check "v>42" 0 +check "v<=43" 1 +check "v>=43" 0 +check "v==41" 0 +check "v!=42" 0 +check "v&3" 2 +check "v^3" 41 +check "v|3" 43 +check "v>=40&&v<=44" 1 +check "v<40||v>44" 0 +check "(v=42)&&(v+=1)==43" 1 +check "v" 43 +check "(v=42)&&(v-=1)==41" 1 +check "v" 41 +check "(v=42)&&(v*=2)==84" 1 +check "v" 84 +check "(v=42)&&(v/=10)==4" 1 +check "v" 4 +check "(v=42)&&(v%=10)==2" 1 +check "v" 2 +check "(v=42)&&(v<<=1)==84" 1 +check "v" 84 +check "(v=42)&&(v>>=2)==10" 1 +check "v" 10 +check "(v=42)&&(v&=32)==32" 1 +check "v" 32 +check "(v=42)&&(v^=32)==10" 1 +check "v" 10 +check "(v=42)&&(v|=32)==42" 1 +check "v" 42 + +# missing: ternary + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/arith3.0 b/bin/1sh/tests/expansion/arith3.0 new file mode 100644 index 00000000..a8db53d3 --- /dev/null +++ b/bin/1sh/tests/expansion/arith3.0 @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith3.0 204017 2010-02-17 22:25:22Z jilles $ + +failures=0 + +check() { + if [ $(($1)) != $2 ]; then + failures=$((failures+1)) + echo "For $1, expected $2 actual $(($1))" + fi +} + +check "1 << 1 + 1 | 1" 5 + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/arith4.0 b/bin/1sh/tests/expansion/arith4.0 new file mode 100644 index 00000000..32a61d87 --- /dev/null +++ b/bin/1sh/tests/expansion/arith4.0 @@ -0,0 +1,20 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith4.0 206167 2010-04-04 16:29:48Z jilles $ + +failures=0 + +check() { + if [ $(($1)) != $2 ]; then + failures=$((failures+1)) + echo "For $1, expected $2 actual $(($1))" + fi +} + +check '20 / 2 / 2' 5 +check '20 - 2 - 2' 16 +unset a b c d +check "a = b = c = d = 1" 1 +check "a == 1 && b == 1 && c == 1 && d == 1" 1 +check "a += b += c += d" 4 +check "a == 4 && b == 3 && c == 2 && d == 1" 1 + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/arith5.0 b/bin/1sh/tests/expansion/arith5.0 new file mode 100644 index 00000000..c87d49d3 --- /dev/null +++ b/bin/1sh/tests/expansion/arith5.0 @@ -0,0 +1,17 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith5.0 206168 2010-04-04 16:48:33Z jilles $ + +failures=0 + +check() { + if [ "$2" != "$3" ]; then + failures=$((failures+1)) + echo "For $1, expected $3 actual $2" + fi +} + +unset a +check '$((1+${a:-$((7+2))}))' "$((1+${a:-$((7+2))}))" 10 +check '$((1+${a:=$((2+2))}))' "$((1+${a:=$((2+2))}))" 5 +check '$a' "$a" 4 + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/arith6.0 b/bin/1sh/tests/expansion/arith6.0 new file mode 100644 index 00000000..31d2a8cd --- /dev/null +++ b/bin/1sh/tests/expansion/arith6.0 @@ -0,0 +1,16 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith6.0 215550 2010-11-19 22:25:32Z jilles $ + +v1=1\ +\ 1 +v2=D +v3=C123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 +f() { v4="$*"; } + +while [ ${#v2} -lt 1250 ]; do + eval $v2=$((3+${#v2})) $v3=$((4-${#v2})) + eval f $(($v2+ $v1 +$v3)) + if [ $v4 -ne 9 ]; then + echo bad: $v4 -ne 9 at ${#v2} + fi + v2=x$v2 + v3=y$v3 +done diff --git a/bin/1sh/tests/expansion/arith7.0 b/bin/1sh/tests/expansion/arith7.0 new file mode 100644 index 00000000..2df33fbd --- /dev/null +++ b/bin/1sh/tests/expansion/arith7.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith7.0 216395 2010-12-12 16:56:16Z jilles $ + +v=1+ +v=$v$v$v$v +v=$v$v$v$v +v=$v$v$v$v +v=$v$v$v$v +v=$v$v$v$v +[ "$(cat <<EOF +$(($v 1)) +EOF +)" = 1025 ] diff --git a/bin/1sh/tests/expansion/arith8.0 b/bin/1sh/tests/expansion/arith8.0 new file mode 100644 index 00000000..a9d9e7e7 --- /dev/null +++ b/bin/1sh/tests/expansion/arith8.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith8.0 216547 2010-12-18 23:03:51Z jilles $ + +v=$( (eval ': $((08))') 2>&1 >/dev/null) +[ $? -ne 0 ] && [ -n "$v" ] diff --git a/bin/1sh/tests/expansion/arith9.0 b/bin/1sh/tests/expansion/arith9.0 new file mode 100644 index 00000000..98c9859a --- /dev/null +++ b/bin/1sh/tests/expansion/arith9.0 @@ -0,0 +1,20 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/arith9.0 218469 2011-02-08 23:23:55Z jilles $ + +failures=0 + +check() { + if [ $(($1)) != $2 ]; then + failures=$((failures+1)) + echo "For $1, expected $2 actual $(($1))" + fi +} + +check "0 ? 44 : 51" 51 +check "1 ? 68 : 30" 68 +check "2 ? 1 : -5" 1 +check "0 ? 4 : 0 ? 5 : 6" 6 +check "0 ? 4 : 1 ? 5 : 6" 5 +check "1 ? 4 : 0 ? 5 : 6" 4 +check "1 ? 4 : 1 ? 5 : 6" 4 + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/assign1.0 b/bin/1sh/tests/expansion/assign1.0 new file mode 100644 index 00000000..25035f57 --- /dev/null +++ b/bin/1sh/tests/expansion/assign1.0 @@ -0,0 +1,37 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/assign1.0 204842 2010-03-07 18:43:29Z jilles $ + +e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' +h='##' +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 'v=; set -- ${v=a b} $v' '0|' +testcase 'unset v; set -- ${v=a b} $v' '4|a|b|a|b' +testcase 'v=; set -- ${v:=a b} $v' '4|a|b|a|b' +testcase 'v=; set -- "${v:=a b}" "$v"' '2|a b|a b' +# expect sensible behaviour, although it disagrees with POSIX +testcase 'v=; set -- ${v:=a\ b} $v' '4|a|b|a|b' +testcase 'v=; set -- ${v:=$p} $v' '2|/etc/|/etc/' +testcase 'v=; set -- "${v:=$p}" "$v"' '2|/et[c]/|/et[c]/' +testcase 'v=; set -- "${v:=a\ b}" "$v"' '2|a\ b|a\ b' +testcase 'v=; set -- ${v:="$p"} $v' '2|/etc/|/etc/' +# whether $p is quoted or not shouldn't really matter +testcase 'v=; set -- "${v:="$p"}" "$v"' '2|/et[c]/|/et[c]/' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/cmdsubst1.0 b/bin/1sh/tests/expansion/cmdsubst1.0 new file mode 100644 index 00000000..7b8768a7 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst1.0 @@ -0,0 +1,48 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst1.0 201366 2010-01-01 18:17:46Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '"$(echo abcde)" = "abcde"' +check '"$(echo abcde; :)" = "abcde"' + +check '"$(printf abcde)" = "abcde"' +check '"$(printf abcde; :)" = "abcde"' + +# regular +check '-n "$(umask)"' +check '-n "$(umask; :)"' +check '-n "$(umask 2>&1)"' +check '-n "$(umask 2>&1; :)"' + +# special +check '-n "$(times)"' +check '-n "$(times; :)"' +check '-n "$(times 2>&1)"' +check '-n "$(times 2>&1; :)"' + +# regular +check '".$(umask -@ 2>&1)." = ".umask: Illegal option -@."' +check '".$(umask -@ 2>&1; :)." = ".umask: Illegal option -@."' +check '".$({ umask -@; } 2>&1)." = ".umask: Illegal option -@."' + +# special +check '".$(shift xyz 2>&1)." = ".shift: Illegal number: xyz."' +check '".$(shift xyz 2>&1; :)." = ".shift: Illegal number: xyz."' +check '".$({ shift xyz; } 2>&1)." = ".shift: Illegal number: xyz."' + +v=1 +check '-z "$(v=2 :)"' +check '"$v" = 1' +check '-z "$(v=3)"' +check '"$v" = 1' +check '"$(v=4 eval echo \$v)" = 4' +check '"$v" = 1' + +exit $((failures > 0)) diff --git a/bin/1sh/tests/expansion/cmdsubst10.0 b/bin/1sh/tests/expansion/cmdsubst10.0 new file mode 100644 index 00000000..fe357a7d --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst10.0 @@ -0,0 +1,51 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst10.0 216826 2010-12-30 22:33:55Z jilles $ + +a1=$(alias) +: $(alias testalias=abcd) +a2=$(alias) +[ "$a1" = "$a2" ] || echo Error at line $LINENO + +alias testalias2=abcd +a1=$(alias) +: $(unalias testalias2) +a2=$(alias) +[ "$a1" = "$a2" ] || echo Error at line $LINENO + +[ "$(command -V pwd)" = "$(command -V pwd; exit $?)" ] || echo Error at line $LINENO + +v=1 +: $(export v=2) +[ "$v" = 1 ] || echo Error at line $LINENO + +rotest=1 +: $(readonly rotest=2) +[ "$rotest" = 1 ] || echo Error at line $LINENO + +set +u +: $(set -u) +case $- in +*u*) echo Error at line $LINENO ;; +esac +set +u + +set +u +: $(set -o nounset) +case $- in +*u*) echo Error at line $LINENO ;; +esac +set +u + +set +u +: $(command set -u) +case $- in +*u*) echo Error at line $LINENO ;; +esac +set +u + +umask 77 +u1=$(umask) +: $(umask 022) +u2=$(umask) +[ "$u1" = "$u2" ] || echo Error at line $LINENO + +dummy=$(exit 3); [ $? -eq 3 ] || echo Error at line $LINENO diff --git a/bin/1sh/tests/expansion/cmdsubst11.0 b/bin/1sh/tests/expansion/cmdsubst11.0 new file mode 100644 index 00000000..320395ef --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst11.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst11.0 223163 2011-06-16 21:50:28Z jilles $ + +# Not required by POSIX but useful for efficiency. + +[ $$ = $(eval '${SH} -c echo\ \$PPID') ] diff --git a/bin/1sh/tests/expansion/cmdsubst12.0 b/bin/1sh/tests/expansion/cmdsubst12.0 new file mode 100644 index 00000000..927d3748 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst12.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst12.0 230121 2012-01-14 23:10:18Z jilles $ + +f() { + echo x$(printf foo >&2)y +} +[ "$(f 2>&1)" = "fooxy" ] diff --git a/bin/1sh/tests/expansion/cmdsubst13.0 b/bin/1sh/tests/expansion/cmdsubst13.0 new file mode 100644 index 00000000..849a8823 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst13.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst13.0 230121 2012-01-14 23:10:18Z jilles $ + +x=1 y=2 +[ "$( + case $((x+=1)) in + ($((y+=1))) echo bad1 ;; + ($((y-1))) echo $x.$y ;; + ($((y=2))) echo bad2 ;; + (*) echo bad3 ;; + esac +)" = "2.3" ] || echo "Error at $LINENO" +[ "$x.$y" = "1.2" ] || echo "Error at $LINENO" diff --git a/bin/1sh/tests/expansion/cmdsubst14.0 b/bin/1sh/tests/expansion/cmdsubst14.0 new file mode 100644 index 00000000..4f133796 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst14.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst14.0 245381 2013-01-13 19:19:40Z jilles $ + +! v=`false + +` diff --git a/bin/1sh/tests/expansion/cmdsubst15.0 b/bin/1sh/tests/expansion/cmdsubst15.0 new file mode 100644 index 00000000..fbe97009 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst15.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst15.0 245381 2013-01-13 19:19:40Z jilles $ + +! v=`false; + +` diff --git a/bin/1sh/tests/expansion/cmdsubst16.0 b/bin/1sh/tests/expansion/cmdsubst16.0 new file mode 100644 index 00000000..f031d9fa --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst16.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst16.0 245392 2013-01-13 22:35:51Z jilles $ + +f() { return 3; } +f +[ `echo $?` = 3 ] diff --git a/bin/1sh/tests/expansion/cmdsubst17.0 b/bin/1sh/tests/expansion/cmdsubst17.0 new file mode 100644 index 00000000..ea274080 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst17.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst17.0 245422 2013-01-14 12:20:55Z jilles $ + +f() { return 3; } +f +[ `echo $?; :` = 3 ] diff --git a/bin/1sh/tests/expansion/cmdsubst18.0 b/bin/1sh/tests/expansion/cmdsubst18.0 new file mode 100644 index 00000000..d090925b --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst18.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst18.0 314637 2017-03-03 22:46:20Z jilles $ + +x=X +unset n +r=${x+$(echo a)}${x-$(echo b)}${n+$(echo c)}${n-$(echo d)}$(echo e) +[ "$r" = aXde ] diff --git a/bin/1sh/tests/expansion/cmdsubst19.0 b/bin/1sh/tests/expansion/cmdsubst19.0 new file mode 100644 index 00000000..abc76471 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst19.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst19.0 314637 2017-03-03 22:46:20Z jilles $ + +b=200 c=30 d=5 x=4 +r=$(echo a)$(($(echo b) + ${x+$(echo c)} + ${x-$(echo d)}))$(echo e) +[ "$r" = a234e ] diff --git a/bin/1sh/tests/expansion/cmdsubst2.0 b/bin/1sh/tests/expansion/cmdsubst2.0 new file mode 100644 index 00000000..cf533c34 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst2.0 @@ -0,0 +1,43 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst2.0 205105 2010-03-12 23:23:46Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '`echo /et[c]/` = "/etc/"' +check '`printf /var/empty%s /et[c]/` = "/var/empty/etc/"' +check '"`echo /et[c]/`" = "/etc/"' +check '`echo "/et[c]/"` = "/etc/"' +check '`printf /var/empty%s "/et[c]/"` = "/var/empty/et[c]/"' +check '`printf /var/empty/%s \"/et[c]/\"` = "/var/empty/\"/et[c]/\""' +check '"`echo \"/et[c]/\"`" = "/et[c]/"' +check '"`echo "/et[c]/"`" = "/et[c]/"' +check '`echo $$` = $$' +check '"`echo $$`" = $$' +check '`echo \$\$` = $$' +check '"`echo \$\$`" = $$' + +# Command substitutions consisting of a single builtin may be treated +# differently. +check '`:; echo /et[c]/` = "/etc/"' +check '`:; printf /var/empty%s /et[c]/` = "/var/empty/etc/"' +check '"`:; echo /et[c]/`" = "/etc/"' +check '`:; echo "/et[c]/"` = "/etc/"' +check '`:; printf /var/empty%s "/et[c]/"` = "/var/empty/et[c]/"' +check '`:; printf /var/empty/%s \"/et[c]/\"` = "/var/empty/\"/et[c]/\""' +check '"`:; echo \"/et[c]/\"`" = "/et[c]/"' +check '"`:; echo "/et[c]/"`" = "/et[c]/"' +check '`:; echo $$` = $$' +check '"`:; echo $$`" = $$' +check '`:; echo \$\$` = $$' +check '"`:; echo \$\$`" = $$' + +check '`set -f; echo /et[c]/` = "/etc/"' +check '"`set -f; echo /et[c]/`" = "/et[c]/"' + +exit $((failures > 0)) diff --git a/bin/1sh/tests/expansion/cmdsubst20.0 b/bin/1sh/tests/expansion/cmdsubst20.0 new file mode 100644 index 00000000..7b6bd1b1 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst20.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst20.0 314637 2017-03-03 22:46:20Z jilles $ + +set -T +trapped='' +trap "trapped=x$trapped" USR1 +[ "x$(kill -USR1 $$)y" = xy ] && [ "$trapped" = x ] diff --git a/bin/1sh/tests/expansion/cmdsubst21.0 b/bin/1sh/tests/expansion/cmdsubst21.0 new file mode 100644 index 00000000..dbed0646 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst21.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst21.0 314686 2017-03-04 22:58:34Z jilles $ + +set -T +trapped='' +trap "trapped=x$trapped" TERM +[ "x$($SH -c "kill $$")y" = xy ] && [ "$trapped" = x ] diff --git a/bin/1sh/tests/expansion/cmdsubst22.0 b/bin/1sh/tests/expansion/cmdsubst22.0 new file mode 100644 index 00000000..941d8161 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst22.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst22.0 314686 2017-03-04 22:58:34Z jilles $ + +set -T +trapped='' +trap "trapped=x$trapped" TERM +[ "x$(:; kill $$)y" = xy ] && [ "$trapped" = x ] diff --git a/bin/1sh/tests/expansion/cmdsubst23.0 b/bin/1sh/tests/expansion/cmdsubst23.0 new file mode 100644 index 00000000..02ed0c41 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst23.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst23.0 315005 2017-03-10 16:04:00Z jilles $ + +unset n +x=abcd +[ "X${n#$(echo a)}X${x#$(echo ab)}X$(echo abc)X" = XXcdXabcX ] diff --git a/bin/1sh/tests/expansion/cmdsubst24.0 b/bin/1sh/tests/expansion/cmdsubst24.0 new file mode 100644 index 00000000..a9ab8f99 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst24.0 @@ -0,0 +1,24 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst24.0 317347 2017-04-23 21:58:17Z jilles $ +# POSIX leaves the effect of NUL bytes in command substitution output +# unspecified but we have always discarded them. + +failures=0 + +check() { + if [ "$2" != "$3" ]; then + printf "Failed at line %s: got \"%s\" expected \"%s\"\n" "$1" "$2" "$3" + : $((failures += 1)) + fi +} + +fmt='\0a\0 \0b\0c d\0' +assign_builtin=$(printf "$fmt") +check "$LINENO" "$assign_builtin" "a bc d" +assign_pipeline=$(printf "$fmt" | cat) +check "$LINENO" "$assign_pipeline" "a bc d" +set -- $(printf "$fmt") $(printf "$fmt" | cat) "$(printf "$fmt")" "$(printf "$fmt" | cat)" +IFS=@ +splits="$*" +check "$LINENO" "$splits" "a@bc@d@a@bc@d@a bc d@a bc d" + +[ "$failures" = 0 ] diff --git a/bin/1sh/tests/expansion/cmdsubst25.0 b/bin/1sh/tests/expansion/cmdsubst25.0 new file mode 100644 index 00000000..d9e2b95b --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst25.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst25.0 317514 2017-04-27 18:52:18Z jilles $ + +IFS=' ' +set -- `printf '\n '` +IFS=: +[ "$*" = ' +' ] diff --git a/bin/1sh/tests/expansion/cmdsubst26.0 b/bin/1sh/tests/expansion/cmdsubst26.0 new file mode 100644 index 00000000..674bbe01 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst26.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst26.0 317514 2017-04-27 18:52:18Z jilles $ + +nl=' +' +v=$nl`printf '\n'` +[ "$v" = "$nl" ] diff --git a/bin/1sh/tests/expansion/cmdsubst3.0 b/bin/1sh/tests/expansion/cmdsubst3.0 new file mode 100644 index 00000000..4089210c --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst3.0 @@ -0,0 +1,23 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst3.0 218819 2011-02-18 20:37:09Z jilles $ + +unset LC_ALL +export LC_CTYPE=en_US.ISO8859-1 + +e= +for i in 0 1 2 3; do + for j in 0 1 2 3 4 5 6 7; do + for k in 0 1 2 3 4 5 6 7; do + case $i$j$k in + 000) continue ;; + esac + e="$e\n\\$i$j$k" + done + done +done +e1=$(printf "$e") +e2="$(printf "$e")" +[ "${#e1}" = 510 ] || echo length bad +[ "$e1" = "$e2" ] || echo e1 != e2 +[ "$e1" = "$(printf "$e")" ] || echo quoted bad +IFS= +[ "$e1" = $(printf "$e") ] || echo unquoted bad diff --git a/bin/1sh/tests/expansion/cmdsubst4.0 b/bin/1sh/tests/expansion/cmdsubst4.0 new file mode 100644 index 00000000..dd200c01 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst4.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst4.0 216747 2010-12-27 23:56:03Z jilles $ + +exec 2>/dev/null +! y=$(: </var/empty/nonexistent) diff --git a/bin/1sh/tests/expansion/cmdsubst5.0 b/bin/1sh/tests/expansion/cmdsubst5.0 new file mode 100644 index 00000000..b58f8ce4 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst5.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst5.0 216761 2010-12-28 13:28:24Z jilles $ + +unset v +exec 2>/dev/null +! y=$(: ${v?}) diff --git a/bin/1sh/tests/expansion/cmdsubst6.0 b/bin/1sh/tests/expansion/cmdsubst6.0 new file mode 100644 index 00000000..afe519f0 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst6.0 @@ -0,0 +1,53 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst6.0 216763 2010-12-28 14:58:08Z jilles $ +# 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/bin/1sh/tests/expansion/cmdsubst7.0 b/bin/1sh/tests/expansion/cmdsubst7.0 new file mode 100644 index 00000000..91f991cb --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst7.0 @@ -0,0 +1,31 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst7.0 216778 2010-12-28 21:27:08Z jilles $ + +failures='' +ok='' + +testcase() { + code="$1" + + unset v + eval ": \$($code)" + + if [ "${v:+bad}" = "" ]; then + ok=x$ok + else + failures=x$failures + echo "Failure for $code" + fi +} + +testcase ': ${v=0}' +testcase ': ${v:=0}' +testcase ': $((v=1))' +testcase ': $((v+=1))' +w='v=1' +testcase ': $(($w))' +testcase ': $((${$+v=1}))' +testcase ': $((v${$+=1}))' +testcase ': $((v $(echo =) 1))' +testcase ': $(($(echo $w)))' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/cmdsubst8.0 b/bin/1sh/tests/expansion/cmdsubst8.0 new file mode 100644 index 00000000..b22473d9 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst8.0 @@ -0,0 +1,17 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst8.0 216819 2010-12-30 15:04:59Z jilles $ +# 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/bin/1sh/tests/expansion/cmdsubst9.0 b/bin/1sh/tests/expansion/cmdsubst9.0 new file mode 100644 index 00000000..e2d9fa67 --- /dev/null +++ b/bin/1sh/tests/expansion/cmdsubst9.0 @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/cmdsubst9.0 216819 2010-12-30 15:04:59Z jilles $ + +set -e + +cd / +dummy=$(cd /bin) +[ "$(pwd)" = / ] + +v=1 +dummy=$(eval v=2) +[ "$v" = 1 ] diff --git a/bin/1sh/tests/expansion/export1.0 b/bin/1sh/tests/expansion/export1.0 new file mode 100644 index 00000000..da65d309 --- /dev/null +++ b/bin/1sh/tests/expansion/export1.0 @@ -0,0 +1,13 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/export1.0 238430 2012-07-13 22:29:02Z jilles $ + +w='@ vv=6' + +v=0 vv=0 +export \v=$w +[ "$v" = "@" ] || echo "Expected @ got $v" +[ "$vv" = "6" ] || echo "Expected 6 got $vv" + +HOME=/known/value + +export \v=~ +[ "$v" = \~ ] || echo "Expected ~ got $v" diff --git a/bin/1sh/tests/expansion/export2.0 b/bin/1sh/tests/expansion/export2.0 new file mode 100644 index 00000000..41fe44d2 --- /dev/null +++ b/bin/1sh/tests/expansion/export2.0 @@ -0,0 +1,24 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/export2.0 238468 2012-07-15 10:19:43Z jilles $ + +w='@ @' +check() { + [ "$v" = "$w" ] || echo "Expected $w got $v" +} + +export v=$w +check + +HOME=/known/value +check() { + [ "$v" = ~ ] || echo "Expected $HOME got $v" +} + +export v=~ +check + +check() { + [ "$v" = "x:$HOME" ] || echo "Expected x:$HOME got $v" +} + +export v=x:~ +check diff --git a/bin/1sh/tests/expansion/export3.0 b/bin/1sh/tests/expansion/export3.0 new file mode 100644 index 00000000..cc981eac --- /dev/null +++ b/bin/1sh/tests/expansion/export3.0 @@ -0,0 +1,30 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/export3.0 238468 2012-07-15 10:19:43Z jilles $ + +w='@ @' +check() { + [ "$v" = "$w" ] || echo "Expected $w got $v" +} + +command export v=$w +check +command command export v=$w +check + +HOME=/known/value +check() { + [ "$v" = ~ ] || echo "Expected $HOME got $v" +} + +command export v=~ +check +command command export v=~ +check + +check() { + [ "$v" = "x:$HOME" ] || echo "Expected x:$HOME got $v" +} + +command export v=x:~ +check +command command export v=x:~ +check diff --git a/bin/1sh/tests/expansion/heredoc1.0 b/bin/1sh/tests/expansion/heredoc1.0 new file mode 100644 index 00000000..364e909c --- /dev/null +++ b/bin/1sh/tests/expansion/heredoc1.0 @@ -0,0 +1,25 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/heredoc1.0 222715 2011-06-05 12:46:26Z jilles $ + +f() { return $1; } + +[ `f 42; { cat; } <<EOF +$? +EOF +` = 42 ] || echo compound command bad + +[ `f 42; (cat) <<EOF +$? +EOF +` = 42 ] || echo subshell bad + +long=`printf %08192d 0` + +[ `f 42; { cat; } <<EOF +$long.$? +EOF +` = $long.42 ] || echo long compound command bad + +[ `f 42; (cat) <<EOF +$long.$? +EOF +` = $long.42 ] || echo long subshell bad diff --git a/bin/1sh/tests/expansion/heredoc2.0 b/bin/1sh/tests/expansion/heredoc2.0 new file mode 100644 index 00000000..937f7b11 --- /dev/null +++ b/bin/1sh/tests/expansion/heredoc2.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/heredoc2.0 222716 2011-06-05 14:13:15Z jilles $ + +f() { return $1; } + +[ `f 42; cat <<EOF +$? +EOF +` = 42 ] || echo simple command bad + +long=`printf %08192d 0` + +[ `f 42; cat <<EOF +$long.$? +EOF +` = $long.42 ] || echo long simple command bad diff --git a/bin/1sh/tests/expansion/ifs1.0 b/bin/1sh/tests/expansion/ifs1.0 new file mode 100644 index 00000000..6245422f --- /dev/null +++ b/bin/1sh/tests/expansion/ifs1.0 @@ -0,0 +1,35 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/ifs1.0 194981 2009-06-25 17:36:08Z jilles $ + +c=: e= s=' ' +failures='' +ok='' + +check_result() { + if [ "x$2" = "x$3" ]; then + ok=x$ok + else + failures=x$failures + echo "For $1, expected $3 actual $2" + fi +} + +IFS=' +' +set -- a '' +set -- "$@" +check_result 'set -- "$@"' "($#)($1)($2)" "(2)(a)()" + +set -- a '' +set -- "$@"$e +check_result 'set -- "$@"$e' "($#)($1)($2)" "(2)(a)()" + +set -- a '' +set -- "$@"$s +check_result 'set -- "$@"$s' "($#)($1)($2)" "(2)(a)()" + +IFS="$c" +set -- a '' +set -- "$@"$c +check_result 'set -- "$@"$c' "($#)($1)($2)" "(2)(a)()" + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/ifs2.0 b/bin/1sh/tests/expansion/ifs2.0 new file mode 100644 index 00000000..98d87696 --- /dev/null +++ b/bin/1sh/tests/expansion/ifs2.0 @@ -0,0 +1,24 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/ifs2.0 211341 2010-08-15 17:14:05Z jilles $ + +failures=0 +i=1 +set -f +while [ "$i" -le 127 ]; do + # A different byte still in the range 1..127. + i2=$((i^2+(i==2))) + # Add a character to work around command substitution's removal of + # final newlines, then remove it again. + c=$(printf \\"$(printf %o@ "$i")") + c=${c%@} + c2=$(printf \\"$(printf %o@ "$i2")") + c2=${c2%@} + IFS=$c + set -- $c2$c$c2$c$c2 + if [ "$#" -ne 3 ] || [ "$1" != "$c2" ] || [ "$2" != "$c2" ] || + [ "$3" != "$c2" ]; then + echo "Bad results for separator $i (word $i2)" >&2 + : $((failures += 1)) + fi + i=$((i+1)) +done +exit $((failures > 0)) diff --git a/bin/1sh/tests/expansion/ifs3.0 b/bin/1sh/tests/expansion/ifs3.0 new file mode 100644 index 00000000..e43d92e3 --- /dev/null +++ b/bin/1sh/tests/expansion/ifs3.0 @@ -0,0 +1,21 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/ifs3.0 211622 2010-08-22 13:09:12Z jilles $ + +failures=0 +unset LC_ALL +export LC_CTYPE=en_US.ISO8859-1 +i=128 +set -f +while [ "$i" -le 255 ]; do + i2=$((i^2)) + c=$(printf \\"$(printf %o "$i")") + c2=$(printf \\"$(printf %o "$i2")") + IFS=$c + set -- $c2$c$c2$c$c2 + if [ "$#" -ne 3 ] || [ "$1" != "$c2" ] || [ "$2" != "$c2" ] || + [ "$3" != "$c2" ]; then + echo "Bad results for separator $i (word $i2)" >&2 + : $((failures += 1)) + fi + i=$((i+1)) +done +exit $((failures > 0)) diff --git a/bin/1sh/tests/expansion/ifs4.0 b/bin/1sh/tests/expansion/ifs4.0 new file mode 100644 index 00000000..8b9967b8 --- /dev/null +++ b/bin/1sh/tests/expansion/ifs4.0 @@ -0,0 +1,39 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/ifs4.0 222361 2011-05-27 15:56:13Z jilles $ + +c=: e= s=' ' +failures='' +ok='' + +check_result() { + if [ "x$2" = "x$3" ]; then + ok=x$ok + else + failures=x$failures + echo "For $1, expected $3 actual $2" + fi +} + +IFS=' +' +set -- a b '' c +set -- $@ +check_result 'set -- $@' "($#)($1)($2)($3)($4)" "(3)(a)(b)(c)()" + +IFS='' +set -- a b '' c +set -- $@ +check_result 'set -- $@' "($#)($1)($2)($3)($4)" "(3)(a)(b)(c)()" + +set -- a b '' c +set -- $* +check_result 'set -- $*' "($#)($1)($2)($3)($4)" "(3)(a)(b)(c)()" + +set -- a b '' c +set -- "$@" +check_result 'set -- "$@"' "($#)($1)($2)($3)($4)" "(4)(a)(b)()(c)" + +set -- a b '' c +set -- "$*" +check_result 'set -- "$*"' "($#)($1)($2)($3)($4)" "(1)(abc)()()()" + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/ifs5.0 b/bin/1sh/tests/expansion/ifs5.0 new file mode 100644 index 00000000..04db254a --- /dev/null +++ b/bin/1sh/tests/expansion/ifs5.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/ifs5.0 278806 2015-02-15 19:48:29Z jilles $ + +set -- $(echo a b c d) +[ "$#" = 4 ] diff --git a/bin/1sh/tests/expansion/ifs6.0 b/bin/1sh/tests/expansion/ifs6.0 new file mode 100644 index 00000000..e151c9c0 --- /dev/null +++ b/bin/1sh/tests/expansion/ifs6.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/ifs6.0 280920 2015-03-31 20:59:37Z jilles $ + +IFS=': ' +x=': :' +set -- $x +[ "$#|$1|$2|$3" = "2|||" ] diff --git a/bin/1sh/tests/expansion/ifs7.0 b/bin/1sh/tests/expansion/ifs7.0 new file mode 100644 index 00000000..f9e9ca49 --- /dev/null +++ b/bin/1sh/tests/expansion/ifs7.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/ifs7.0 280920 2015-03-31 20:59:37Z jilles $ + +IFS=2 +set -- $((123)) +[ "$#|$1|$2|$3" = "2|1|3|" ] diff --git a/bin/1sh/tests/expansion/length1.0 b/bin/1sh/tests/expansion/length1.0 new file mode 100644 index 00000000..9f3b9443 --- /dev/null +++ b/bin/1sh/tests/expansion/length1.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/length1.0 219611 2011-03-13 16:20:38Z jilles $ + +v=abcd +[ "${#v}" = 4 ] || echo '${#v} wrong' +v=$$ +[ "${#$}" = "${#v}" ] || echo '${#$} wrong' +[ "${#!}" = 0 ] || echo '${#!} wrong' +set -- 01 2 3 4 5 6 7 8 9 10 11 12 0013 +[ "${#1}" = 2 ] || echo '${#1} wrong' +[ "${#13}" = 4 ] || echo '${#13} wrong' +v=$0 +[ "${#0}" = "${#v}" ] || echo '${#0} wrong' diff --git a/bin/1sh/tests/expansion/length2.0 b/bin/1sh/tests/expansion/length2.0 new file mode 100644 index 00000000..0ff07bd6 --- /dev/null +++ b/bin/1sh/tests/expansion/length2.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/length2.0 219611 2011-03-13 16:20:38Z jilles $ + +v=$- +[ "${#-}" = "${#v}" ] || echo '${#-} wrong' diff --git a/bin/1sh/tests/expansion/length3.0 b/bin/1sh/tests/expansion/length3.0 new file mode 100644 index 00000000..4c4391cd --- /dev/null +++ b/bin/1sh/tests/expansion/length3.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/length3.0 219611 2011-03-13 16:20:38Z jilles $ + +set -- 1 2 3 4 5 6 7 8 9 10 11 12 13 +[ "$#" = 13 ] || echo '$# wrong' +[ "${#}" = 13 ] || echo '${#} wrong' +[ "${##}" = 2 ] || echo '${##} wrong' +set -- +[ "$#" = 0 ] || echo '$# wrong' +[ "${#}" = 0 ] || echo '${#} wrong' +[ "${##}" = 1 ] || echo '${##} wrong' diff --git a/bin/1sh/tests/expansion/length4.0 b/bin/1sh/tests/expansion/length4.0 new file mode 100644 index 00000000..4a39fea1 --- /dev/null +++ b/bin/1sh/tests/expansion/length4.0 @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/length4.0 220655 2011-04-15 15:26:05Z jilles $ + +# The construct ${#?} is ambiguous in POSIX.1-2008: it could be the length +# of $? or it could be $# giving an error in the (impossible) case that it +# is not set. +# We use the former interpretation; it seems more useful. + +: +[ "${#?}" = 1 ] || echo '${#?} wrong' +(exit 42) +[ "${#?}" = 2 ] || echo '${#?} wrong' diff --git a/bin/1sh/tests/expansion/length5.0 b/bin/1sh/tests/expansion/length5.0 new file mode 100644 index 00000000..dcc76831 --- /dev/null +++ b/bin/1sh/tests/expansion/length5.0 @@ -0,0 +1,27 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/length5.0 220656 2011-04-15 15:33:24Z jilles $ + +unset LC_ALL +LC_CTYPE=en_US.ISO8859-1 +export LC_CTYPE + +e= +for i in 0 1 2 3; do + for j in 0 1 2 3 4 5 6 7; do + for k in 0 1 2 3 4 5 6 7; do + case $i$j$k in + 000) continue ;; + esac + e="$e\\$i$j$k" + done + done +done +ee=`printf "$e"` +[ ${#ee} = 255 ] || echo bad 1 +[ "${#ee}" = 255 ] || echo bad 2 +[ $((${#ee})) = 255 ] || echo bad 3 +[ "$((${#ee}))" = 255 ] || echo bad 4 +set -- "$ee" +[ ${#1} = 255 ] || echo bad 5 +[ "${#1}" = 255 ] || echo bad 6 +[ $((${#1})) = 255 ] || echo bad 7 +[ "$((${#1}))" = 255 ] || echo bad 8 diff --git a/bin/1sh/tests/expansion/length6.0 b/bin/1sh/tests/expansion/length6.0 new file mode 100644 index 00000000..cf65ea4c --- /dev/null +++ b/bin/1sh/tests/expansion/length6.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/length6.0 220903 2011-04-20 22:24:54Z jilles $ + +x='!@#$%^&*()[]' +[ ${#x} = 12 ] || echo bad 1 +[ "${#x}" = 12 ] || echo bad 2 +IFS=2 +[ ${#x} = 1 ] || echo bad 3 +[ "${#x}" = 12 ] || echo bad 4 diff --git a/bin/1sh/tests/expansion/length7.0 b/bin/1sh/tests/expansion/length7.0 new file mode 100644 index 00000000..a89ed1c6 --- /dev/null +++ b/bin/1sh/tests/expansion/length7.0 @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/length7.0 221602 2011-05-07 14:32:16Z jilles $ + +unset LC_ALL +LC_CTYPE=en_US.UTF-8 +export LC_CTYPE + +# a umlaut +s=$(printf '\303\244') +# euro sign +s=$s$(printf '\342\202\254') +# some sort of 't' outside BMP +s=$s$(printf '\360\235\225\245') +set -- "$s" +[ ${#s} = 3 ] && [ ${#1} = 3 ] diff --git a/bin/1sh/tests/expansion/length8.0 b/bin/1sh/tests/expansion/length8.0 new file mode 100644 index 00000000..01e52283 --- /dev/null +++ b/bin/1sh/tests/expansion/length8.0 @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/length8.0 221602 2011-05-07 14:32:16Z jilles $ + +unset LC_ALL +LC_CTYPE=en_US.ISO8859-1 +export LC_CTYPE + +# a umlaut +s=$(printf '\303\244') +# euro sign +s=$s$(printf '\342\202\254') +# some sort of 't' outside BMP +s=$s$(printf '\360\235\225\245') +set -- "$s" +[ ${#s} = 9 ] && [ ${#1} = 9 ] diff --git a/bin/1sh/tests/expansion/local1.0 b/bin/1sh/tests/expansion/local1.0 new file mode 100644 index 00000000..722e376f --- /dev/null +++ b/bin/1sh/tests/expansion/local1.0 @@ -0,0 +1,28 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/local1.0 238468 2012-07-15 10:19:43Z jilles $ + +run_test() { + w='@ @' + check() { + [ "$v" = "$w" ] || echo "Expected $w got $v" + } + + local v=$w + check + + HOME=/known/value + check() { + [ "$v" = ~ ] || echo "Expected $HOME got $v" + } + + local v=~ + check + + check() { + [ "$v" = "x:$HOME" ] || echo "Expected x:$HOME got $v" + } + + local v=x:~ + check +} + +run_test diff --git a/bin/1sh/tests/expansion/local2.0 b/bin/1sh/tests/expansion/local2.0 new file mode 100644 index 00000000..25d7dbf8 --- /dev/null +++ b/bin/1sh/tests/expansion/local2.0 @@ -0,0 +1,34 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/local2.0 238468 2012-07-15 10:19:43Z jilles $ + +run_test() { + w='@ @' + check() { + [ "$v" = "$w" ] || echo "Expected $w got $v" + } + + command local v=$w + check + command command local v=$w + check + + HOME=/known/value + check() { + [ "$v" = ~ ] || echo "Expected $HOME got $v" + } + + command local v=~ + check + command command local v=~ + check + + check() { + [ "$v" = "x:$HOME" ] || echo "Expected x:$HOME got $v" + } + + command local v=x:~ + check + command command local v=x:~ + check +} + +run_test diff --git a/bin/1sh/tests/expansion/pathname1.0 b/bin/1sh/tests/expansion/pathname1.0 new file mode 100644 index 00000000..b1daef58 --- /dev/null +++ b/bin/1sh/tests/expansion/pathname1.0 @@ -0,0 +1,65 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/pathname1.0 302937 2016-07-16 13:26:18Z ache $ + +unset LC_ALL +LC_COLLATE=C +export LC_COLLATE + +failures=0 + +check() { + testcase=$1 + expect=$2 + eval "set -- $testcase" + actual="$*" + if [ "$actual" != "$expect" ]; then + failures=$((failures+1)) + printf '%s\n' "For $testcase, expected $expect actual $actual" + fi +} + +set -e +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) +trap 'rm -rf $T' 0 +cd -P $T + +mkdir testdir testdir2 'testdir/*' 'testdir/?' testdir/a testdir/b testdir2/b +mkdir testdir2/.c +touch testf 'testdir/*/1' 'testdir/?/1' testdir/a/1 testdir/b/1 testdir2/b/.a + +check '' '' +check 'testdir/b' 'testdir/b' +check 'testdir/c' 'testdir/c' +check '\*' '*' +check '\?' '?' +check '*' 'testdir testdir2 testf' +check '*""' 'testdir testdir2 testf' +check '""*' 'testdir testdir2 testf' +check '*/' 'testdir/ testdir2/' +check 'testdir*/a' 'testdir/a' +check 'testdir*/b' 'testdir/b testdir2/b' +check '*/.c' 'testdir2/.c' +check 'testdir2/*' 'testdir2/b' +check 'testdir2/b/*' 'testdir2/b/*' +check 'testdir/*' 'testdir/* testdir/? testdir/a testdir/b' +check 'testdir/*/1' 'testdir/*/1 testdir/?/1 testdir/a/1 testdir/b/1' +check '"testdir/"*/1' 'testdir/*/1 testdir/?/1 testdir/a/1 testdir/b/1' +check 'testdir/\*/*' 'testdir/*/1' +check 'testdir/\?/*' 'testdir/?/1' +check 'testdir/"?"/*' 'testdir/?/1' +check '"testdir"/"?"/*' 'testdir/?/1' +check '"testdir"/"?"*/*' 'testdir/?/1' +check '"testdir"/*"?"/*' 'testdir/?/1' +check '"testdir/?"*/*' 'testdir/?/1' +check 'testdir/\*/' 'testdir/*/' +check 'testdir/\?/' 'testdir/?/' +check 'testdir/"?"/' 'testdir/?/' +check '"testdir"/"?"/' 'testdir/?/' +check '"testdir"/"?"*/' 'testdir/?/' +check '"testdir"/*"?"/' 'testdir/?/' +check '"testdir/?"*/' 'testdir/?/' +check 'testdir/[*]/' 'testdir/*/' +check 'testdir/[?]/' 'testdir/?/' +check 'testdir/[*?]/' 'testdir/*/ testdir/?/' +check '[tz]estdir/[*]/' 'testdir/*/' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/pathname2.0 b/bin/1sh/tests/expansion/pathname2.0 new file mode 100644 index 00000000..e4ee5be5 --- /dev/null +++ b/bin/1sh/tests/expansion/pathname2.0 @@ -0,0 +1,35 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/pathname2.0 302937 2016-07-16 13:26:18Z ache $ + +unset LC_ALL +LC_COLLATE=C +export LC_COLLATE + +failures=0 + +check() { + testcase=$1 + expect=$2 + eval "set -- $testcase" + actual="$*" + if [ "$actual" != "$expect" ]; then + failures=$((failures+1)) + printf '%s\n' "For $testcase, expected $expect actual $actual" + fi +} + +set -e +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) +trap 'rm -rf $T' 0 +cd -P $T + +mkdir testdir testdir2 'testdir/*' 'testdir/?' testdir/a testdir/b testdir2/b +mkdir testdir2/.c +touch testf 'testdir/*/1' 'testdir/?/1' testdir/a/1 testdir/b/1 testdir2/b/.a + +check '*\/' 'testdir/ testdir2/' +check '"testdir/"*"/1"' 'testdir/*/1 testdir/?/1 testdir/a/1 testdir/b/1' +check '"testdir/"*"/"*' 'testdir/*/1 testdir/?/1 testdir/a/1 testdir/b/1' +check '"testdir/"*\/*' 'testdir/*/1 testdir/?/1 testdir/a/1 testdir/b/1' +check '"testdir"*"/"*"/"*' 'testdir/*/1 testdir/?/1 testdir/a/1 testdir/b/1' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/pathname3.0 b/bin/1sh/tests/expansion/pathname3.0 new file mode 100644 index 00000000..f291eea5 --- /dev/null +++ b/bin/1sh/tests/expansion/pathname3.0 @@ -0,0 +1,29 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/pathname3.0 211155 2010-08-10 22:45:59Z jilles $ + +v=12345678 +v=$v$v$v$v +v=$v$v$v$v +v=$v$v$v$v +v=$v$v$v$v +v=$v$v$v$v +# 8192 bytes +v=${v##???} +[ /*/$v = "/*/$v" ] || exit 1 + +s=//// +s=$s$s$s$s +s=$s$s$s$s +s=$s$s$s$s +s=$s$s$s$s +# 1024 bytes +s=${s##??????????} +[ /var/empt[y]/$s/$v = "/var/empt[y]/$s/$v" ] || exit 2 +while [ ${#s} -lt 1034 ]; do + set -- /.${s}et[c] + [ ${#s} -gt 1018 ] || [ "$1" = /.${s}etc ] || exit 3 + set -- /.${s}et[c]/ + [ ${#s} -gt 1017 ] || [ "$1" = /.${s}etc/ ] || exit 4 + set -- /.${s}et[c]/. + [ ${#s} -gt 1016 ] || [ "$1" = /.${s}etc/. ] || exit 5 + s=$s/ +done diff --git a/bin/1sh/tests/expansion/pathname4.0 b/bin/1sh/tests/expansion/pathname4.0 new file mode 100644 index 00000000..e3cabf4c --- /dev/null +++ b/bin/1sh/tests/expansion/pathname4.0 @@ -0,0 +1,28 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/pathname4.0 211646 2010-08-22 21:18:21Z jilles $ + +failures=0 + +check() { + testcase=$1 + expect=$2 + eval "set -- $testcase" + actual="$*" + if [ "$actual" != "$expect" ]; then + failures=$((failures+1)) + printf '%s\n' "For $testcase, expected $expect actual $actual" + fi +} + +set -e +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) +trap 'rm -rf $T' 0 +cd -P $T + +mkdir !!a +touch !!a/fff + +chmod u-r . +check '!!a/ff*' '!!a/fff' +chmod u+r . + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/pathname5.0 b/bin/1sh/tests/expansion/pathname5.0 new file mode 100644 index 00000000..ad105468 --- /dev/null +++ b/bin/1sh/tests/expansion/pathname5.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/pathname5.0 278806 2015-02-15 19:48:29Z jilles $ + +[ `echo '/[e]tc'` = /etc ] diff --git a/bin/1sh/tests/expansion/pathname6.0 b/bin/1sh/tests/expansion/pathname6.0 new file mode 100644 index 00000000..2cf6f07d --- /dev/null +++ b/bin/1sh/tests/expansion/pathname6.0 @@ -0,0 +1,29 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/pathname6.0 302937 2016-07-16 13:26:18Z ache $ + +unset LC_ALL +LC_COLLATE=en_US.US-ASCII +export LC_COLLATE + +failures=0 + +check() { + testcase=$1 + expect=$2 + eval "set -- $testcase" + actual="$*" + if [ "$actual" != "$expect" ]; then + failures=$((failures+1)) + printf '%s\n' "For $testcase, expected $expect actual $actual" + fi +} + +set -e +T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) +trap 'rm -rf $T' 0 +cd -P $T + +touch A B a b + +check '*' 'a A b B' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/expansion/plus-minus1.0 b/bin/1sh/tests/expansion/plus-minus1.0 new file mode 100644 index 00000000..41410e44 --- /dev/null +++ b/bin/1sh/tests/expansion/plus-minus1.0 @@ -0,0 +1,76 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/plus-minus1.0 216738 2010-12-27 15:57:41Z emaste $ + +e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' +h='##' +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' '2|a|b' +testcase 'set --' '0|' +testcase 'set -- ${e}' '0|' +testcase 'set -- "${e}"' '1|' + +testcase 'set -- $p' '1|/etc/' +testcase 'set -- "$p"' '1|/et[c]/' +testcase 'set -- ${s+$p}' '1|/etc/' +testcase 'set -- "${s+$p}"' '1|/et[c]/' +testcase 'set -- ${s+"$p"}' '1|/et[c]/' +# Dquotes in dquotes is undefined for Bourne shell operators +#testcase 'set -- "${s+"$p"}"' '1|/et[c]/' +testcase 'set -- ${e:-$p}' '1|/etc/' +testcase 'set -- "${e:-$p}"' '1|/et[c]/' +testcase 'set -- ${e:-"$p"}' '1|/et[c]/' +# Dquotes in dquotes is undefined for Bourne shell operators +#testcase 'set -- "${e:-"$p"}"' '1|/et[c]/' +testcase 'set -- ${e:+"$e"}' '0|' +testcase 'set -- ${e:+$w"$e"}' '0|' +testcase 'set -- ${w:+"$w"}' '1|a b c' +testcase 'set -- ${w:+$w"$w"}' '3|a|b|ca b c' + +testcase 'set -- "${s+a b}"' '1|a b' +testcase 'set -- "${e:-a b}"' '1|a b' +testcase 'set -- ${e:-\}}' '1|}' +testcase 'set -- ${e:+{}}' '1|}' +testcase 'set -- "${e:+{}}"' '1|}' + +testcase 'set -- ${e+x}${e+x}' '1|xx' +testcase 'set -- "${e+x}"${e+x}' '1|xx' +testcase 'set -- ${e+x}"${e+x}"' '1|xx' +testcase 'set -- "${e+x}${e+x}"' '1|xx' +testcase 'set -- "${e+x}""${e+x}"' '1|xx' + +testcase 'set -- ${e:-${e:-$p}}' '1|/etc/' +testcase 'set -- "${e:-${e:-$p}}"' '1|/et[c]/' +testcase 'set -- ${e:-"${e:-$p}"}' '1|/et[c]/' +testcase 'set -- ${e:-${e:-"$p"}}' '1|/et[c]/' +testcase 'set -- ${e:-${e:-${e:-$w}}}' '3|a|b|c' +testcase 'set -- ${e:-${e:-${e:-"$w"}}}' '1|a b c' +testcase 'set -- ${e:-${e:-"${e:-$w}"}}' '1|a b c' +testcase 'set -- ${e:-"${e:-${e:-$w}}"}' '1|a b c' +testcase 'set -- "${e:-${e:-${e:-$w}}}"' '1|a b c' + +testcase 'shift $#; set -- ${1+"$@"}' '0|' +testcase 'set -- ""; set -- ${1+"$@"}' '1|' +testcase 'set -- "" a; set -- ${1+"$@"}' '2||a' +testcase 'set -- a ""; set -- ${1+"$@"}' '2|a|' +testcase 'set -- a b; set -- ${1+"$@"}' '2|a|b' +testcase 'set -- a\ b; set -- ${1+"$@"}' '1|a b' +testcase 'set -- " " ""; set -- ${1+"$@"}' '2| |' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/plus-minus2.0 b/bin/1sh/tests/expansion/plus-minus2.0 new file mode 100644 index 00000000..2920c9e5 --- /dev/null +++ b/bin/1sh/tests/expansion/plus-minus2.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/plus-minus2.0 206145 2010-04-03 20:55:56Z jilles $ + +e= +test "${e:-\}}" = '}' diff --git a/bin/1sh/tests/expansion/plus-minus3.0 b/bin/1sh/tests/expansion/plus-minus3.0 new file mode 100644 index 00000000..acbc04ae --- /dev/null +++ b/bin/1sh/tests/expansion/plus-minus3.0 @@ -0,0 +1,44 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/plus-minus3.0 206817 2010-04-18 22:13:45Z jilles $ + +e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' +h='##' +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 +} + +# We follow original ash behaviour for quoted ${var+-=?} expansions: +# a double-quote in one switches back to unquoted state. +# This allows expanding a variable as a single word if it is set +# and substituting multiple words otherwise. +# It is also close to the Bourne and Korn shells. +# POSIX leaves this undefined, and various other shells treat +# such double-quotes as introducing a second level of quoting +# which does not do much except quoting close braces. + +testcase 'set -- "${p+"/et[c]/"}"' '1|/etc/' +testcase 'set -- "${p-"/et[c]/"}"' '1|/et[c]/' +testcase 'set -- "${p+"$p"}"' '1|/etc/' +testcase 'set -- "${p-"$p"}"' '1|/et[c]/' +testcase 'set -- "${p+"""/et[c]/"}"' '1|/etc/' +testcase 'set -- "${p-"""/et[c]/"}"' '1|/et[c]/' +testcase 'set -- "${p+"""$p"}"' '1|/etc/' +testcase 'set -- "${p-"""$p"}"' '1|/et[c]/' +testcase 'set -- "${p+"\@"}"' '1|@' +testcase 'set -- "${p+"'\''/et[c]/'\''"}"' '1|/et[c]/' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/plus-minus4.0 b/bin/1sh/tests/expansion/plus-minus4.0 new file mode 100644 index 00000000..980b1785 --- /dev/null +++ b/bin/1sh/tests/expansion/plus-minus4.0 @@ -0,0 +1,38 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/plus-minus4.0 211080 2010-08-08 17:03:23Z jilles $ + +# These may be a bit unclear in the POSIX spec or the proposed revisions, +# and conflict with bash's interpretation, but I think ksh93's interpretation +# makes most sense. In particular, it makes no sense to me that single-quotes +# must match but are not removed. + +e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' +h='##' +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 -- ${e:-'"'"'}'"'"'}' '1|}' +testcase "set -- \${e:-\\'}" "1|'" +testcase "set -- \${e:-\\'\\'}" "1|''" +testcase "set -- \"\${e:-'}\"" "1|'" +testcase "set -- \"\${e:-'}'}\"" "1|''}" +testcase "set -- \"\${e:-''}\"" "1|''" +testcase 'set -- ${e:-\a}' '1|a' +testcase 'set -- "${e:-\a}"' '1|\a' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/plus-minus5.0 b/bin/1sh/tests/expansion/plus-minus5.0 new file mode 100644 index 00000000..b8a57f5b --- /dev/null +++ b/bin/1sh/tests/expansion/plus-minus5.0 @@ -0,0 +1,31 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/plus-minus5.0 214492 2010-10-28 22:34:49Z jilles $ + +e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' +h='##' +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 -- ${e:-"{x}"}' '1|{x}' +testcase 'set -- "${e:-"{x}"}"' '1|{x}' +testcase 'set -- ${h+"{x}"}' '1|{x}' +testcase 'set -- "${h+"{x}"}"' '1|{x}' +testcase 'set -- ${h:-"{x}"}' '1|##' +testcase 'set -- "${h:-"{x}"}"' '1|##' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/plus-minus6.0 b/bin/1sh/tests/expansion/plus-minus6.0 new file mode 100644 index 00000000..df57df97 --- /dev/null +++ b/bin/1sh/tests/expansion/plus-minus6.0 @@ -0,0 +1,34 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/plus-minus6.0 214512 2010-10-29 13:42:18Z jilles $ + +failures=0 +unset LC_ALL +export LC_CTYPE=en_US.ISO8859-1 +nl=' +' +i=1 +set -f +while [ "$i" -le 255 ]; do + # A different byte still in the range 1..255. + i2=$((i^2+(i==2))) + # Add a character to work around command substitution's removal of + # final newlines, then remove it again. + c=$(printf \\"$(printf %o@ "$i")") + c=${c%@} + c2=$(printf \\"$(printf %o@ "$i2")") + c2=${c2%@} + case $c in + [\'$nl'$}();&|\"`']) c=M + esac + case $c2 in + [\'$nl'$}();&|\"`']) c2=N + esac + IFS=$c + command eval "set -- \${\$+$c2$c$c2$c$c2}" + if [ "$#" -ne 3 ] || [ "$1" != "$c2" ] || [ "$2" != "$c2" ] || + [ "$3" != "$c2" ]; then + echo "Bad results for separator $i (word $i2)" >&2 + : $((failures += 1)) + fi + i=$((i+1)) +done +exit $((failures > 0)) diff --git a/bin/1sh/tests/expansion/plus-minus7.0 b/bin/1sh/tests/expansion/plus-minus7.0 new file mode 100644 index 00000000..e6161700 --- /dev/null +++ b/bin/1sh/tests/expansion/plus-minus7.0 @@ -0,0 +1,26 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/plus-minus7.0 216738 2010-12-27 15:57:41Z emaste $ + +e= s='foo' +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 -- ${s+a b}' '2|a|b' +testcase 'set -- ${e:-a b}' '2|a|b' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/plus-minus8.0 b/bin/1sh/tests/expansion/plus-minus8.0 new file mode 100644 index 00000000..49385cd7 --- /dev/null +++ b/bin/1sh/tests/expansion/plus-minus8.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/plus-minus8.0 219623 2011-03-13 20:02:39Z jilles $ + +set -- 1 2 3 4 5 6 7 8 9 10 11 12 13 +[ "${#+hi}" = hi ] || echo '${#+hi} wrong' +[ "${#-hi}" = 13 ] || echo '${#-hi} wrong' diff --git a/bin/1sh/tests/expansion/plus-minus9.0 b/bin/1sh/tests/expansion/plus-minus9.0 new file mode 100644 index 00000000..30f754a1 --- /dev/null +++ b/bin/1sh/tests/expansion/plus-minus9.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/plus-minus9.0 333927 2018-05-20 17:25:52Z jilles $ + +a=1 +b=${a+ +} +n=' +' +[ "$b" = "$n" ] diff --git a/bin/1sh/tests/expansion/question1.0 b/bin/1sh/tests/expansion/question1.0 new file mode 100644 index 00000000..8795be66 --- /dev/null +++ b/bin/1sh/tests/expansion/question1.0 @@ -0,0 +1,22 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/question1.0 213738 2010-10-12 18:20:38Z obrien $ + +x=a\ b +[ "$x" = "${x?}" ] || exit 1 +set -- ${x?} +{ [ "$#" = 2 ] && [ "$1" = a ] && [ "$2" = b ]; } || exit 1 +unset x +(echo ${x?abcdefg}) 2>&1 | grep -q abcdefg || exit 1 +${SH} -c 'unset foo; echo ${foo?}' 2>/dev/null && exit 1 +${SH} -c 'foo=; echo ${foo:?}' 2>/dev/null && exit 1 +${SH} -c 'foo=; echo ${foo?}' >/dev/null || exit 1 +${SH} -c 'foo=1; echo ${foo:?}' >/dev/null || exit 1 +${SH} -c 'echo ${!?}' 2>/dev/null && exit 1 +${SH} -c ':& echo ${!?}' >/dev/null || exit 1 +${SH} -c 'echo ${#?}' >/dev/null || exit 1 +${SH} -c 'echo ${*?}' 2>/dev/null && exit 1 +${SH} -c 'echo ${*?}' ${SH} x >/dev/null || exit 1 +${SH} -c 'echo ${1?}' 2>/dev/null && exit 1 +${SH} -c 'echo ${1?}' ${SH} x >/dev/null || exit 1 +${SH} -c 'echo ${2?}' ${SH} x 2>/dev/null && exit 1 +${SH} -c 'echo ${2?}' ${SH} x y >/dev/null || exit 1 +exit 0 diff --git a/bin/1sh/tests/expansion/question2.0 b/bin/1sh/tests/expansion/question2.0 new file mode 100644 index 00000000..abf5f99a --- /dev/null +++ b/bin/1sh/tests/expansion/question2.0 @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/question2.0 341767 2018-12-09 19:14:21Z jilles $ + +unset dummyvar +msg=`(: ${dummyvar?}) 2>&1` +r=$? +[ "$r" != 0 ] && case $msg in +*dummyvar?* | *?dummyvar*) : ;; +*) + printf 'Bad message: [%s]\n' "$msg" + exit 1 +esac diff --git a/bin/1sh/tests/expansion/readonly1.0 b/bin/1sh/tests/expansion/readonly1.0 new file mode 100644 index 00000000..7a8f7335 --- /dev/null +++ b/bin/1sh/tests/expansion/readonly1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/readonly1.0 238468 2012-07-15 10:19:43Z jilles $ + +w='@ @' + +v=0 HOME=/known/value +readonly v=~:~/:$w +[ "$v" = "$HOME:$HOME/:$w" ] || echo "Expected $HOME/:$w got $v" diff --git a/bin/1sh/tests/expansion/redir1.0 b/bin/1sh/tests/expansion/redir1.0 new file mode 100644 index 00000000..fbbb2088 --- /dev/null +++ b/bin/1sh/tests/expansion/redir1.0 @@ -0,0 +1,26 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/redir1.0 273920 2014-10-31 22:28:10Z jilles $ + +bad=0 +for i in 0 1 2 3; do + for j in 0 1 2 3 4 5 6 7; do + for k in 0 1 2 3 4 5 6 7; do + case $i$j$k in + 000) continue ;; + esac + set -- "$(printf \\$i$j$k@)" + set -- "${1%@}" + ff= + for f in /dev/null /dev/zero /; do + if [ -e "$f" ] && [ ! -e "$f$1" ]; then + ff=$f + fi + done + [ -n "$ff" ] || continue + if { true <$ff$1; } 2>/dev/null; then + echo "Bad: $i$j$k ($ff)" >&2 + : $((bad += 1)) + fi + done + done +done +exit $((bad ? 2 : 0)) diff --git a/bin/1sh/tests/expansion/set-u1.0 b/bin/1sh/tests/expansion/set-u1.0 new file mode 100644 index 00000000..08ad6118 --- /dev/null +++ b/bin/1sh/tests/expansion/set-u1.0 @@ -0,0 +1,29 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/set-u1.0 213738 2010-10-12 18:20:38Z obrien $ + +${SH} -uc 'unset foo; echo $foo' 2>/dev/null && exit 1 +${SH} -uc 'foo=; echo $foo' >/dev/null || exit 1 +${SH} -uc 'foo=1; echo $foo' >/dev/null || exit 1 +# -/+/= are unaffected by set -u +${SH} -uc 'unset foo; echo ${foo-}' >/dev/null || exit 1 +${SH} -uc 'unset foo; echo ${foo+}' >/dev/null || exit 1 +${SH} -uc 'unset foo; echo ${foo=}' >/dev/null || exit 1 +# length/trimming are affected +${SH} -uc 'unset foo; echo ${#foo}' 2>/dev/null && exit 1 +${SH} -uc 'foo=; echo ${#foo}' >/dev/null || exit 1 +${SH} -uc 'unset foo; echo ${foo#?}' 2>/dev/null && exit 1 +${SH} -uc 'foo=1; echo ${foo#?}' >/dev/null || exit 1 +${SH} -uc 'unset foo; echo ${foo##?}' 2>/dev/null && exit 1 +${SH} -uc 'foo=1; echo ${foo##?}' >/dev/null || exit 1 +${SH} -uc 'unset foo; echo ${foo%?}' 2>/dev/null && exit 1 +${SH} -uc 'foo=1; echo ${foo%?}' >/dev/null || exit 1 +${SH} -uc 'unset foo; echo ${foo%%?}' 2>/dev/null && exit 1 +${SH} -uc 'foo=1; echo ${foo%%?}' >/dev/null || exit 1 + +${SH} -uc 'echo $!' 2>/dev/null && exit 1 +${SH} -uc ':& echo $!' >/dev/null || exit 1 +${SH} -uc 'echo $#' >/dev/null || exit 1 +${SH} -uc 'echo $1' 2>/dev/null && exit 1 +${SH} -uc 'echo $1' ${SH} x >/dev/null || exit 1 +${SH} -uc 'echo $2' ${SH} x 2>/dev/null && exit 1 +${SH} -uc 'echo $2' ${SH} x y >/dev/null || exit 1 +exit 0 diff --git a/bin/1sh/tests/expansion/set-u2.0 b/bin/1sh/tests/expansion/set-u2.0 new file mode 100644 index 00000000..fff4e09f --- /dev/null +++ b/bin/1sh/tests/expansion/set-u2.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/set-u2.0 198454 2009-10-24 21:20:04Z jilles $ + +set -u +: $* $@ "$@" "$*" +set -- x +: $* $@ "$@" "$*" +shift $# +: $* $@ "$@" "$*" +set -- y +set -- +: $* $@ "$@" "$*" +exit 0 diff --git a/bin/1sh/tests/expansion/set-u3.0 b/bin/1sh/tests/expansion/set-u3.0 new file mode 100644 index 00000000..c68a4240 --- /dev/null +++ b/bin/1sh/tests/expansion/set-u3.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/set-u3.0 221463 2011-05-04 22:12:22Z jilles $ + +set -u +unset x +v=$( (eval ': $((x))') 2>&1 >/dev/null) +[ $? -ne 0 ] && [ -n "$v" ] diff --git a/bin/1sh/tests/expansion/tilde1.0 b/bin/1sh/tests/expansion/tilde1.0 new file mode 100644 index 00000000..9623209a --- /dev/null +++ b/bin/1sh/tests/expansion/tilde1.0 @@ -0,0 +1,56 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/tilde1.0 206149 2010-04-03 21:56:24Z jilles $ + +HOME=/tmp +roothome=~root +if [ "$roothome" = "~root" ]; then + echo "~root is not expanded!" + exit 2 +fi + +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 -- ~' '1|/tmp' +testcase 'set -- ~/foo' '1|/tmp/foo' +testcase 'set -- x~' '1|x~' +testcase 'set -- ~root' "1|$roothome" +h=~ +testcase 'set -- "$h"' '1|/tmp' +ooIFS=$IFS +IFS=m +testcase 'set -- ~' '1|/tmp' +testcase 'set -- ~/foo' '1|/tmp/foo' +testcase 'set -- $h' '2|/t|p' +IFS=$ooIFS +t=\~ +testcase 'set -- $t' '1|~' +r=$(cat <<EOF +~ +EOF +) +testcase 'set -- $r' '1|~' +r=$(cat <<EOF +${t+~} +EOF +) +testcase 'set -- $r' '1|~' +r=$(cat <<EOF +${t+~/.} +EOF +) +testcase 'set -- $r' '1|~/.' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/tilde2.0 b/bin/1sh/tests/expansion/tilde2.0 new file mode 100644 index 00000000..6313b4dc --- /dev/null +++ b/bin/1sh/tests/expansion/tilde2.0 @@ -0,0 +1,90 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/tilde2.0 206150 2010-04-03 22:04:44Z jilles $ + +HOME=/tmp +roothome=~root +if [ "$roothome" = "~root" ]; then + echo "~root is not expanded!" + exit 2 +fi + +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 -- ${$+~}' '1|/tmp' +testcase 'set -- ${$+~/}' '1|/tmp/' +testcase 'set -- ${$+~/foo}' '1|/tmp/foo' +testcase 'set -- ${$+x~}' '1|x~' +testcase 'set -- ${$+~root}' "1|$roothome" +testcase 'set -- ${$+"~"}' '1|~' +testcase 'set -- ${$+"~/"}' '1|~/' +testcase 'set -- ${$+"~/foo"}' '1|~/foo' +testcase 'set -- ${$+"x~"}' '1|x~' +testcase 'set -- ${$+"~root"}' "1|~root" +testcase 'set -- "${$+~}"' '1|~' +testcase 'set -- "${$+~/}"' '1|~/' +testcase 'set -- "${$+~/foo}"' '1|~/foo' +testcase 'set -- "${$+x~}"' '1|x~' +testcase 'set -- "${$+~root}"' "1|~root" +testcase 'set -- ${HOME#~}' '0|' +h=~ +testcase 'set -- "$h"' '1|/tmp' +f=~/foo +testcase 'set -- "$f"' '1|/tmp/foo' +testcase 'set -- ${f#~}' '1|/foo' +testcase 'set -- ${f#~/}' '1|foo' + +ooIFS=$IFS +IFS=m +testcase 'set -- ${$+~}' '1|/tmp' +testcase 'set -- ${$+~/foo}' '1|/tmp/foo' +testcase 'set -- ${$+$h}' '2|/t|p' +testcase 'set -- ${HOME#~}' '0|' +IFS=$ooIFS + +t=\~ +testcase 'set -- ${$+$t}' '1|~' +r=$(cat <<EOF +${HOME#~} +EOF +) +testcase 'set -- $r' '0|' +r=$(cat <<EOF +${HOME#'~'} +EOF +) +testcase 'set -- $r' '1|/tmp' +r=$(cat <<EOF +${t#'~'} +EOF +) +testcase 'set -- $r' '0|' +r=$(cat <<EOF +${roothome#~root} +EOF +) +testcase 'set -- $r' '0|' +r=$(cat <<EOF +${f#~} +EOF +) +testcase 'set -- $r' '1|/foo' +r=$(cat <<EOF +${f#~/} +EOF +) +testcase 'set -- $r' '1|foo' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/trim1.0 b/bin/1sh/tests/expansion/trim1.0 new file mode 100644 index 00000000..13bc5b6d --- /dev/null +++ b/bin/1sh/tests/expansion/trim1.0 @@ -0,0 +1,85 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim1.0 206143 2010-04-03 20:14:10Z jilles $ + +e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' +h='##' +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 -- ${t%t}' '1|texttex' +testcase 'set -- "${t%t}"' '1|texttex' +testcase 'set -- ${t%e*}' '1|textt' +testcase 'set -- "${t%e*}"' '1|textt' +testcase 'set -- ${t%%e*}' '1|t' +testcase 'set -- "${t%%e*}"' '1|t' +testcase 'set -- ${t%%*}' '0|' +testcase 'set -- "${t%%*}"' '1|' +testcase 'set -- ${t#t}' '1|exttext' +testcase 'set -- "${t#t}"' '1|exttext' +testcase 'set -- ${t#*x}' '1|ttext' +testcase 'set -- "${t#*x}"' '1|ttext' +testcase 'set -- ${t##*x}' '1|t' +testcase 'set -- "${t##*x}"' '1|t' +testcase 'set -- ${t##*}' '0|' +testcase 'set -- "${t##*}"' '1|' +testcase 'set -- ${t%e$a}' '1|textt' + +set -f +testcase 'set -- ${s%[?]*}' '1|ast*que' +testcase 'set -- "${s%[?]*}"' '1|ast*que' +testcase 'set -- ${s%[*]*}' '1|ast' +testcase 'set -- "${s%[*]*}"' '1|ast' +set +f + +testcase 'set -- $b' '1|{{(#)}}' +testcase 'set -- ${b%\}}' '1|{{(#)}' +testcase 'set -- ${b#{}' '1|{(#)}}' +testcase 'set -- "${b#{}"' '1|{(#)}}' +# Parentheses are special in ksh, check that they can be escaped +testcase 'set -- ${b%\)*}' '1|{{(#' +testcase 'set -- ${b#{}' '1|{(#)}}' +testcase 'set -- $h' '1|##' +testcase 'set -- ${h#\#}' '1|#' +testcase 'set -- ${h###}' '1|#' +testcase 'set -- "${h###}"' '1|#' +testcase 'set -- ${h%#}' '1|#' +testcase 'set -- "${h%#}"' '1|#' + +set -f +testcase 'set -- ${s%"${s#?}"}' '1|a' +testcase 'set -- ${s%"${s#????}"}' '1|ast*' +testcase 'set -- ${s%"${s#????????}"}' '1|ast*que?' +testcase 'set -- ${s#"${s%?}"}' '1|n' +testcase 'set -- ${s#"${s%????}"}' '1|?non' +testcase 'set -- ${s#"${s%????????}"}' '1|*que?non' +set +f +testcase 'set -- "${s%"${s#?}"}"' '1|a' +testcase 'set -- "${s%"${s#????}"}"' '1|ast*' +testcase 'set -- "${s%"${s#????????}"}"' '1|ast*que?' +testcase 'set -- "${s#"${s%?}"}"' '1|n' +testcase 'set -- "${s#"${s%????}"}"' '1|?non' +testcase 'set -- "${s#"${s%????????}"}"' '1|*que?non' +testcase 'set -- ${p#${p}}' '1|/etc/' +testcase 'set -- "${p#${p}}"' '1|/et[c]/' +testcase 'set -- ${p#*[[]}' '1|c]/' +testcase 'set -- "${p#*[[]}"' '1|c]/' +testcase 'set -- ${p#*\[}' '1|c]/' +testcase 'set -- ${p#*"["}' '1|c]/' +testcase 'set -- "${p#*"["}"' '1|c]/' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/trim10.0 b/bin/1sh/tests/expansion/trim10.0 new file mode 100644 index 00000000..177bfe41 --- /dev/null +++ b/bin/1sh/tests/expansion/trim10.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim10.0 333927 2018-05-20 17:25:52Z jilles $ + +a='z +' +b=${a% +} +[ "$b" = z ] diff --git a/bin/1sh/tests/expansion/trim11.0 b/bin/1sh/tests/expansion/trim11.0 new file mode 100644 index 00000000..4dd05ee6 --- /dev/null +++ b/bin/1sh/tests/expansion/trim11.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim11.0 333927 2018-05-20 17:25:52Z jilles $ + +a='z +' +b="${a% +}" +[ "$b" = z ] diff --git a/bin/1sh/tests/expansion/trim2.0 b/bin/1sh/tests/expansion/trim2.0 new file mode 100644 index 00000000..4c0d3778 --- /dev/null +++ b/bin/1sh/tests/expansion/trim2.0 @@ -0,0 +1,55 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim2.0 206147 2010-04-03 21:07:50Z jilles $ + +e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' +h='##' +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 +} + +set -f +testcase 'set -- $s' '1|ast*que?non' +testcase 'set -- ${s%\?*}' '1|ast*que' +testcase 'set -- "${s%\?*}"' '1|ast*que' +testcase 'set -- ${s%\**}' '1|ast' +testcase 'set -- "${s%\**}"' '1|ast' +testcase 'set -- ${s%"$q"*}' '1|ast*que' +testcase 'set -- "${s%"$q"*}"' '1|ast*que' +testcase 'set -- ${s%"$a"*}' '1|ast' +testcase 'set -- "${s%"$a"*}"' '1|ast' +testcase 'set -- ${s%"$q"$a}' '1|ast*que' +testcase 'set -- "${s%"$q"$a}"' '1|ast*que' +testcase 'set -- ${s%"$a"$a}' '1|ast' +testcase 'set -- "${s%"$a"$a}"' '1|ast' +set +f + +testcase 'set -- "${b%\}}"' '1|{{(#)}' +# Parentheses are special in ksh, check that they can be escaped +testcase 'set -- "${b%\)*}"' '1|{{(#' +testcase 'set -- "${h#\#}"' '1|#' + +testcase 'set -- ${p%"${p#?}"}' '1|/' +testcase 'set -- ${p%"${p#??????}"}' '1|/etc' +testcase 'set -- ${p%"${p#???????}"}' '1|/etc/' +testcase 'set -- "${p%"${p#?}"}"' '1|/' +testcase 'set -- "${p%"${p#??????}"}"' '1|/et[c]' +testcase 'set -- "${p%"${p#???????}"}"' '1|/et[c]/' +testcase 'set -- ${p#"${p}"}' '0|' +testcase 'set -- "${p#"${p}"}"' '1|' +testcase 'set -- "${p#*\[}"' '1|c]/' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/trim3.0 b/bin/1sh/tests/expansion/trim3.0 new file mode 100644 index 00000000..bc9cd5f0 --- /dev/null +++ b/bin/1sh/tests/expansion/trim3.0 @@ -0,0 +1,46 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim3.0 207127 2010-04-23 17:26:49Z jilles $ + +e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' +h='##' c='\\\\' +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 +} + +# This doesn't make much sense, but it fails in dash so I'm adding it here: +testcase 'set -- "${w%${w#???}}"' '1|a b' + +testcase 'set -- ${p#/et[}' '1|c]/' +testcase 'set -- "${p#/et[}"' '1|c]/' +testcase 'set -- "${p%${p#????}}"' '1|/et[' + +testcase 'set -- ${b%'\'}\''}' '1|{{(#)}' + +testcase 'set -- ${c#\\}' '1|\\\' +testcase 'set -- ${c#\\\\}' '1|\\' +testcase 'set -- ${c#\\\\\\}' '1|\' +testcase 'set -- ${c#\\\\\\\\}' '0|' +testcase 'set -- "${c#\\}"' '1|\\\' +testcase 'set -- "${c#\\\\}"' '1|\\' +testcase 'set -- "${c#\\\\\\}"' '1|\' +testcase 'set -- "${c#\\\\\\\\}"' '1|' +testcase 'set -- "${c#"$c"}"' '1|' +testcase 'set -- ${c#"$c"}' '0|' +testcase 'set -- "${c%"$c"}"' '1|' +testcase 'set -- ${c%"$c"}' '0|' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/trim4.0 b/bin/1sh/tests/expansion/trim4.0 new file mode 100644 index 00000000..77986240 --- /dev/null +++ b/bin/1sh/tests/expansion/trim4.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim4.0 213814 2010-10-13 23:29:09Z obrien $ + +v1=/homes/SOME_USER +v2= +v3=C123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 + +# Trigger bug in VSTRIMRIGHT processing STADJUST() call in expand.c:subevalvar() +while [ ${#v2} -lt 2000 ]; do + v4="${v2} ${v1%/*} $v3" + if [ ${#v4} -ne $((${#v2} + ${#v3} + 8)) ]; then + echo bad: ${#v4} -ne $((${#v2} + ${#v3} + 8)) + fi + v2=x$v2 + v3=y$v3 +done diff --git a/bin/1sh/tests/expansion/trim5.0 b/bin/1sh/tests/expansion/trim5.0 new file mode 100644 index 00000000..cc3a477f --- /dev/null +++ b/bin/1sh/tests/expansion/trim5.0 @@ -0,0 +1,28 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim5.0 214490 2010-10-28 21:51:14Z jilles $ + +e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' +h='##' +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 -- "${b%'\'}\''}"' '1|{{(#)}' +testcase 'set -- ${b%"}"}' '1|{{(#)}' +testcase 'set -- "${b%"}"}"' '1|{{(#)}' + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/trim6.0 b/bin/1sh/tests/expansion/trim6.0 new file mode 100644 index 00000000..7a080018 --- /dev/null +++ b/bin/1sh/tests/expansion/trim6.0 @@ -0,0 +1,22 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim6.0 214524 2010-10-29 19:34:57Z jilles $ + +e= +for i in 0 1 2 3; do + for j in 0 1 2 3 4 5 6 7; do + for k in 0 1 2 3 4 5 6 7; do + case $i$j$k in + 000) continue ;; + esac + e="$e\\$i$j$k" + done + done +done +e=$(printf "$e") +v=@$e@$e@ +y=${v##*"$e"} +yq="${v##*"$e"}" +[ "$y" = @ ] || echo "error when unquoted in non-splitting context" +[ "$yq" = @ ] || echo "error when quoted in non-splitting context" +[ "${v##*"$e"}" = @ ] || echo "error when quoted in splitting context" +IFS= +[ ${v##*"$e"} = @ ] || echo "error when unquoted in splitting context" diff --git a/bin/1sh/tests/expansion/trim7.0 b/bin/1sh/tests/expansion/trim7.0 new file mode 100644 index 00000000..61ca3ab2 --- /dev/null +++ b/bin/1sh/tests/expansion/trim7.0 @@ -0,0 +1,16 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim7.0 219623 2011-03-13 20:02:39Z jilles $ + +set -- 1 2 3 4 5 6 7 8 9 10 11 12 13 +[ "${##1}" = 3 ] || echo '${##1} wrong' +[ "${###1}" = 3 ] || echo '${###1} wrong' +[ "${###}" = 13 ] || echo '${###} wrong' +[ "${#%3}" = 1 ] || echo '${#%3} wrong' +[ "${#%%3}" = 1 ] || echo '${#%%3} wrong' +[ "${#%%}" = 13 ] || echo '${#%%} wrong' +set -- +[ "${##0}" = "" ] || echo '${##0} wrong' +[ "${###0}" = "" ] || echo '${###0} wrong' +[ "${###}" = 0 ] || echo '${###} wrong' +[ "${#%0}" = "" ] || echo '${#%0} wrong' +[ "${#%%0}" = "" ] || echo '${#%%0} wrong' +[ "${#%%}" = 0 ] || echo '${#%%} wrong' diff --git a/bin/1sh/tests/expansion/trim8.0 b/bin/1sh/tests/expansion/trim8.0 new file mode 100644 index 00000000..7fd7d052 --- /dev/null +++ b/bin/1sh/tests/expansion/trim8.0 @@ -0,0 +1,75 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim8.0 221646 2011-05-08 11:32:20Z jilles $ + +unset LC_ALL +LC_CTYPE=en_US.UTF-8 +export LC_CTYPE + +c1=e +# a umlaut +c2=$(printf '\303\244') +# euro sign +c3=$(printf '\342\202\254') +# some sort of 't' outside BMP +c4=$(printf '\360\235\225\245') + +s=$c1$c2$c3$c4 + +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 -- "$s"' "1|$s" +testcase 'set -- "${s#$c2}"' "1|$s" +testcase 'set -- "${s#*}"' "1|$s" +testcase 'set -- "${s#$c1}"' "1|$c2$c3$c4" +testcase 'set -- "${s#$c1$c2}"' "1|$c3$c4" +testcase 'set -- "${s#$c1$c2$c3}"' "1|$c4" +testcase 'set -- "${s#$c1$c2$c3$c4}"' "1|" +testcase 'set -- "${s#?}"' "1|$c2$c3$c4" +testcase 'set -- "${s#??}"' "1|$c3$c4" +testcase 'set -- "${s#???}"' "1|$c4" +testcase 'set -- "${s#????}"' "1|" +testcase 'set -- "${s#*$c3}"' "1|$c4" +testcase 'set -- "${s%$c4}"' "1|$c1$c2$c3" +testcase 'set -- "${s%$c3$c4}"' "1|$c1$c2" +testcase 'set -- "${s%$c2$c3$c4}"' "1|$c1" +testcase 'set -- "${s%$c1$c2$c3$c4}"' "1|" +testcase 'set -- "${s%?}"' "1|$c1$c2$c3" +testcase 'set -- "${s%??}"' "1|$c1$c2" +testcase 'set -- "${s%???}"' "1|$c1" +testcase 'set -- "${s%????}"' "1|" +testcase 'set -- "${s%$c2*}"' "1|$c1" +testcase 'set -- "${s##$c2}"' "1|$s" +testcase 'set -- "${s##*}"' "1|" +testcase 'set -- "${s##$c1}"' "1|$c2$c3$c4" +testcase 'set -- "${s##$c1$c2}"' "1|$c3$c4" +testcase 'set -- "${s##$c1$c2$c3}"' "1|$c4" +testcase 'set -- "${s##$c1$c2$c3$c4}"' "1|" +testcase 'set -- "${s##?}"' "1|$c2$c3$c4" +testcase 'set -- "${s##??}"' "1|$c3$c4" +testcase 'set -- "${s##???}"' "1|$c4" +testcase 'set -- "${s##????}"' "1|" +testcase 'set -- "${s##*$c3}"' "1|$c4" +testcase 'set -- "${s%%$c4}"' "1|$c1$c2$c3" +testcase 'set -- "${s%%$c3$c4}"' "1|$c1$c2" +testcase 'set -- "${s%%$c2$c3$c4}"' "1|$c1" +testcase 'set -- "${s%%$c1$c2$c3$c4}"' "1|" +testcase 'set -- "${s%%?}"' "1|$c1$c2$c3" +testcase 'set -- "${s%%??}"' "1|$c1$c2" +testcase 'set -- "${s%%???}"' "1|$c1" +testcase 'set -- "${s%%????}"' "1|" +testcase 'set -- "${s%%$c2*}"' "1|$c1" + +test "x$failures" = x diff --git a/bin/1sh/tests/expansion/trim9.0 b/bin/1sh/tests/expansion/trim9.0 new file mode 100644 index 00000000..e83f3725 --- /dev/null +++ b/bin/1sh/tests/expansion/trim9.0 @@ -0,0 +1,61 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/expansion/trim9.0 292758 2015-12-26 22:27:48Z jilles $ + +# POSIX does not specify these but they occasionally occur in the wild. +# This just serves to keep working what currently works. + +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 -- "${*#Q}"' '1|' +testcase 'shift $#; set -- "${*##Q}"' '1|' +testcase 'shift $#; set -- "${*%Q}"' '1|' +testcase 'shift $#; set -- "${*%%Q}"' '1|' +testcase 'set -- Q R; set -- "${*#Q}"' '1| R' +testcase 'set -- Q R; set -- "${*##Q}"' '1| R' +testcase 'set -- Q R; set -- "${*%R}"' '1|Q ' +testcase 'set -- Q R; set -- "${*%%R}"' '1|Q ' +testcase 'set -- Q R; set -- "${*#S}"' '1|Q R' +testcase 'set -- Q R; set -- "${*##S}"' '1|Q R' +testcase 'set -- Q R; set -- "${*%S}"' '1|Q R' +testcase 'set -- Q R; set -- "${*%%S}"' '1|Q R' +testcase 'set -- Q R; set -- ${*#Q}' '1|R' +testcase 'set -- Q R; set -- ${*##Q}' '1|R' +testcase 'set -- Q R; set -- ${*%R}' '1|Q' +testcase 'set -- Q R; set -- ${*%%R}' '1|Q' +testcase 'set -- Q R; set -- ${*#S}' '2|Q|R' +testcase 'set -- Q R; set -- ${*##S}' '2|Q|R' +testcase 'set -- Q R; set -- ${*%S}' '2|Q|R' +testcase 'set -- Q R; set -- ${*%%S}' '2|Q|R' +testcase 'set -- Q R; set -- ${@#Q}' '1|R' +testcase 'set -- Q R; set -- ${@##Q}' '1|R' +testcase 'set -- Q R; set -- ${@%R}' '1|Q' +testcase 'set -- Q R; set -- ${@%%R}' '1|Q' +testcase 'set -- Q R; set -- ${@#S}' '2|Q|R' +testcase 'set -- Q R; set -- ${@##S}' '2|Q|R' +testcase 'set -- Q R; set -- ${@%S}' '2|Q|R' +testcase 'set -- Q R; set -- ${@%%S}' '2|Q|R' +testcase 'set -- Q R; set -- "${@#Q}"' '2||R' +testcase 'set -- Q R; set -- "${@%R}"' '2|Q|' +testcase 'set -- Q R; set -- "${@%%R}"' '2|Q|' +testcase 'set -- Q R; set -- "${@#S}"' '2|Q|R' +testcase 'set -- Q R; set -- "${@##S}"' '2|Q|R' +testcase 'set -- Q R; set -- "${@%S}"' '2|Q|R' +testcase 'set -- Q R; set -- "${@%%S}"' '2|Q|R' + +test "x$failures" = x diff --git a/bin/1sh/tests/functional_test.sh b/bin/1sh/tests/functional_test.sh new file mode 100755 index 00000000..19d1006a --- /dev/null +++ b/bin/1sh/tests/functional_test.sh @@ -0,0 +1,72 @@ +# +# Copyright 2014 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# $FreeBSD: releng/12.1/bin/sh/tests/functional_test.sh 270101 2014-08-17 14:26:12Z jilles $ + +SRCDIR=$(atf_get_srcdir) + +check() +{ + local tc=${1}; shift + + export SH=$(atf_config_get bin.sh.test_shell /bin/sh) + + local err_file="${SRCDIR}/${tc}.stderr" + [ -f "${err_file}" ] && err_flag="-e file:${err_file}" + local out_file="${SRCDIR}/${tc}.stdout" + [ -f "${out_file}" ] && out_flag="-o file:${out_file}" + + atf_check -s exit:${tc##*.} ${err_flag} ${out_flag} ${SH} "${SRCDIR}/${tc}" +} + +add_testcase() +{ + local tc=${1} + local tc_escaped word + + case "${tc%.*}" in + *-*) + local IFS="-" + for word in ${tc%.*}; do + tc_escaped="${tc_escaped:+${tc_escaped}_}${word}" + done + ;; + *) + tc_escaped=${tc%.*} + ;; + esac + + atf_test_case ${tc_escaped} + eval "${tc_escaped}_body() { check ${tc}; }" + atf_add_test_case ${tc_escaped} +} + +atf_init_test_cases() +{ + for path in $(find -Es "${SRCDIR}" -regex '.*\.[0-9]+$'); do + add_testcase ${path##*/} + done +} diff --git a/bin/1sh/tests/invocation/Makefile b/bin/1sh/tests/invocation/Makefile new file mode 100644 index 00000000..095fc46c --- /dev/null +++ b/bin/1sh/tests/invocation/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/invocation/Makefile 322455 2017-08-13 14:36:10Z jilles $ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +${PACKAGE}FILES+= sh-ac1.0 +${PACKAGE}FILES+= sh-c-missing1.0 +${PACKAGE}FILES+= sh-c1.0 +${PACKAGE}FILES+= sh-ca1.0 +${PACKAGE}FILES+= sh-fca1.0 + +.include <bsd.test.mk> diff --git a/bin/1sh/tests/invocation/Makefile.depend b/bin/1sh/tests/invocation/Makefile.depend new file mode 100644 index 00000000..cbec5fcc --- /dev/null +++ b/bin/1sh/tests/invocation/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/invocation/Makefile.depend 325187 2017-10-31 00:04:07Z 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/invocation/sh-ac1.0 b/bin/1sh/tests/invocation/sh-ac1.0 new file mode 100644 index 00000000..a0dd1cbb --- /dev/null +++ b/bin/1sh/tests/invocation/sh-ac1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/invocation/sh-ac1.0 322438 2017-08-12 19:17:48Z jilles $ +# Test that attached options before c are processed + +case `${SH} -ac 'echo $-:$0' moo` in +*a*:moo) true ;; +*) false ;; +esac diff --git a/bin/1sh/tests/invocation/sh-c-missing1.0 b/bin/1sh/tests/invocation/sh-c-missing1.0 new file mode 100644 index 00000000..15bf9488 --- /dev/null +++ b/bin/1sh/tests/invocation/sh-c-missing1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/invocation/sh-c-missing1.0 322455 2017-08-13 14:36:10Z jilles $ + +! echo echo bad | ${SH} -c 2>/dev/null diff --git a/bin/1sh/tests/invocation/sh-c1.0 b/bin/1sh/tests/invocation/sh-c1.0 new file mode 100644 index 00000000..a24e1b44 --- /dev/null +++ b/bin/1sh/tests/invocation/sh-c1.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/invocation/sh-c1.0 322438 2017-08-12 19:17:48Z jilles $ +# Test that -c executes command_string with the given name and arg + +${SH} -c 'echo $0 $@' moo foo | grep -qx -- "moo foo" diff --git a/bin/1sh/tests/invocation/sh-ca1.0 b/bin/1sh/tests/invocation/sh-ca1.0 new file mode 100644 index 00000000..8913e71b --- /dev/null +++ b/bin/1sh/tests/invocation/sh-ca1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/invocation/sh-ca1.0 322438 2017-08-12 19:17:48Z jilles $ +# Test that attached options after c are processed + +case `${SH} -ca 'echo $-:$0' moo` in +*a*:moo) true ;; +*) false ;; +esac diff --git a/bin/1sh/tests/invocation/sh-fca1.0 b/bin/1sh/tests/invocation/sh-fca1.0 new file mode 100644 index 00000000..c0a5082b --- /dev/null +++ b/bin/1sh/tests/invocation/sh-fca1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/invocation/sh-fca1.0 322438 2017-08-12 19:17:48Z jilles $ +# Test that attached options before and after c are processed + +case `${SH} -fca 'echo $-:$-:$0:$@' foo -bar` in +*f*:*a*:foo:-bar) true ;; +*) false ;; +esac 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" ] diff --git a/bin/1sh/tests/parser/Makefile b/bin/1sh/tests/parser/Makefile new file mode 100644 index 00000000..44322a35 --- /dev/null +++ b/bin/1sh/tests/parser/Makefile @@ -0,0 +1,89 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/Makefile 333507 2018-05-11 21:56:01Z jilles $ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +${PACKAGE}FILES+= alias1.0 +${PACKAGE}FILES+= alias2.0 +${PACKAGE}FILES+= alias3.0 +${PACKAGE}FILES+= alias4.0 +${PACKAGE}FILES+= alias5.0 +${PACKAGE}FILES+= alias6.0 +${PACKAGE}FILES+= alias7.0 +${PACKAGE}FILES+= alias8.0 +${PACKAGE}FILES+= alias9.0 +${PACKAGE}FILES+= alias10.0 +${PACKAGE}FILES+= alias11.0 +${PACKAGE}FILES+= alias12.0 +${PACKAGE}FILES+= alias13.0 +${PACKAGE}FILES+= alias14.0 +${PACKAGE}FILES+= alias15.0 alias15.0.stdout +${PACKAGE}FILES+= alias16.0 +${PACKAGE}FILES+= alias17.0 +${PACKAGE}FILES+= alias18.0 +${PACKAGE}FILES+= and-pipe-not.0 +${PACKAGE}FILES+= case1.0 +${PACKAGE}FILES+= case2.0 +${PACKAGE}FILES+= comment1.0 +${PACKAGE}FILES+= comment2.42 +${PACKAGE}FILES+= dollar-quote1.0 +${PACKAGE}FILES+= dollar-quote2.0 +${PACKAGE}FILES+= dollar-quote3.0 +${PACKAGE}FILES+= dollar-quote4.0 +${PACKAGE}FILES+= dollar-quote5.0 +${PACKAGE}FILES+= dollar-quote6.0 +${PACKAGE}FILES+= dollar-quote7.0 +${PACKAGE}FILES+= dollar-quote8.0 +${PACKAGE}FILES+= dollar-quote9.0 +${PACKAGE}FILES+= dollar-quote10.0 +${PACKAGE}FILES+= dollar-quote11.0 +${PACKAGE}FILES+= dollar-quote12.0 +${PACKAGE}FILES+= dollar-quote13.0 +${PACKAGE}FILES+= empty-braces1.0 +${PACKAGE}FILES+= empty-cmd1.0 +${PACKAGE}FILES+= for1.0 +${PACKAGE}FILES+= for2.0 +${PACKAGE}FILES+= func1.0 +${PACKAGE}FILES+= func2.0 +${PACKAGE}FILES+= func3.0 +${PACKAGE}FILES+= heredoc1.0 +${PACKAGE}FILES+= heredoc2.0 +${PACKAGE}FILES+= heredoc3.0 +${PACKAGE}FILES+= heredoc4.0 +${PACKAGE}FILES+= heredoc5.0 +${PACKAGE}FILES+= heredoc6.0 +${PACKAGE}FILES+= heredoc7.0 +${PACKAGE}FILES+= heredoc8.0 +${PACKAGE}FILES+= heredoc9.0 +${PACKAGE}FILES+= heredoc10.0 +${PACKAGE}FILES+= heredoc11.0 +${PACKAGE}FILES+= heredoc12.0 +${PACKAGE}FILES+= heredoc13.0 +${PACKAGE}FILES+= line-cont1.0 +${PACKAGE}FILES+= line-cont2.0 +${PACKAGE}FILES+= line-cont3.0 +${PACKAGE}FILES+= line-cont4.0 +${PACKAGE}FILES+= line-cont5.0 +${PACKAGE}FILES+= line-cont6.0 +${PACKAGE}FILES+= line-cont7.0 +${PACKAGE}FILES+= line-cont8.0 +${PACKAGE}FILES+= line-cont9.0 +${PACKAGE}FILES+= line-cont10.0 +${PACKAGE}FILES+= line-cont11.0 +${PACKAGE}FILES+= line-cont12.0 +${PACKAGE}FILES+= no-space1.0 +${PACKAGE}FILES+= no-space2.0 +${PACKAGE}FILES+= nul1.0 +${PACKAGE}FILES+= only-redir1.0 +${PACKAGE}FILES+= only-redir2.0 +${PACKAGE}FILES+= only-redir3.0 +${PACKAGE}FILES+= only-redir4.0 +${PACKAGE}FILES+= pipe-not1.0 +${PACKAGE}FILES+= set-v1.0 set-v1.0.stderr +${PACKAGE}FILES+= var-assign1.0 + +.include <bsd.test.mk> diff --git a/bin/1sh/tests/parser/Makefile.depend b/bin/1sh/tests/parser/Makefile.depend new file mode 100644 index 00000000..93ab5889 --- /dev/null +++ b/bin/1sh/tests/parser/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/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/parser/alias1.0 b/bin/1sh/tests/parser/alias1.0 new file mode 100644 index 00000000..2f20b05f --- /dev/null +++ b/bin/1sh/tests/parser/alias1.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias1.0 214280 2010-10-24 16:55:17Z jilles $ + +alias alias0=exit +eval 'alias0 0' +exit 1 diff --git a/bin/1sh/tests/parser/alias10.0 b/bin/1sh/tests/parser/alias10.0 new file mode 100644 index 00000000..bccf9d46 --- /dev/null +++ b/bin/1sh/tests/parser/alias10.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias10.0 243252 2012-11-18 23:15:22Z jilles $ + +# This test may start consuming memory indefinitely if it fails. +ulimit -t 5 2>/dev/null +ulimit -v 100000 2>/dev/null + +alias echo='echo' +alias echo='echo' +[ "`eval echo b`" = b ] diff --git a/bin/1sh/tests/parser/alias11.0 b/bin/1sh/tests/parser/alias11.0 new file mode 100644 index 00000000..1f8de0e3 --- /dev/null +++ b/bin/1sh/tests/parser/alias11.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias11.0 261141 2014-01-24 23:00:35Z jilles $ + +alias alias0=alias1 +alias alias1=exit +eval 'alias0 0' +exit 3 diff --git a/bin/1sh/tests/parser/alias12.0 b/bin/1sh/tests/parser/alias12.0 new file mode 100644 index 00000000..4763bf86 --- /dev/null +++ b/bin/1sh/tests/parser/alias12.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias12.0 261160 2014-01-25 14:59:08Z jilles $ + +unalias -a +alias alias0=command +alias true='echo bad' +eval 'alias0 true' diff --git a/bin/1sh/tests/parser/alias13.0 b/bin/1sh/tests/parser/alias13.0 new file mode 100644 index 00000000..ef370ee9 --- /dev/null +++ b/bin/1sh/tests/parser/alias13.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias13.0 261160 2014-01-25 14:59:08Z jilles $ + +unalias -a +alias command=command +alias true='echo bad' +eval 'command true' diff --git a/bin/1sh/tests/parser/alias14.0 b/bin/1sh/tests/parser/alias14.0 new file mode 100644 index 00000000..42a195ad --- /dev/null +++ b/bin/1sh/tests/parser/alias14.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias14.0 261192 2014-01-26 21:19:33Z jilles $ + +alias command='command ' +alias alias0=exit +eval 'command alias0 0' +exit 3 diff --git a/bin/1sh/tests/parser/alias15.0 b/bin/1sh/tests/parser/alias15.0 new file mode 100644 index 00000000..a070fd66 --- /dev/null +++ b/bin/1sh/tests/parser/alias15.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias15.0 261192 2014-01-26 21:19:33Z jilles $ + +f_echoanddo() { + printf '%s\n' "$*" + "$@" +} + +alias echoanddo='f_echoanddo ' +alias alias0='echo test2' +eval 'echoanddo echo test1' +eval 'echoanddo alias0' +exit 0 diff --git a/bin/1sh/tests/parser/alias15.0.stdout b/bin/1sh/tests/parser/alias15.0.stdout new file mode 100644 index 00000000..6dd179c0 --- /dev/null +++ b/bin/1sh/tests/parser/alias15.0.stdout @@ -0,0 +1,4 @@ +echo test1 +test1 +echo test2 +test2 diff --git a/bin/1sh/tests/parser/alias16.0 b/bin/1sh/tests/parser/alias16.0 new file mode 100644 index 00000000..a9dc4e60 --- /dev/null +++ b/bin/1sh/tests/parser/alias16.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias16.0 316646 2017-04-08 21:57:59Z jilles $ + +v=1 +alias a='unalias a +v=2' +eval a +[ "$v" = 2 ] diff --git a/bin/1sh/tests/parser/alias17.0 b/bin/1sh/tests/parser/alias17.0 new file mode 100644 index 00000000..bfd3d886 --- /dev/null +++ b/bin/1sh/tests/parser/alias17.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias17.0 317037 2017-04-16 21:42:43Z jilles $ + +v=1 +alias a='unalias -a +v=2' +eval a +[ "$v" = 2 ] diff --git a/bin/1sh/tests/parser/alias18.0 b/bin/1sh/tests/parser/alias18.0 new file mode 100644 index 00000000..1063b063 --- /dev/null +++ b/bin/1sh/tests/parser/alias18.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias18.0 317039 2017-04-16 22:10:02Z jilles $ + +v=1 +alias a='alias a=v=2 +v=3 +a' +eval a +[ "$v" = 2 ] diff --git a/bin/1sh/tests/parser/alias2.0 b/bin/1sh/tests/parser/alias2.0 new file mode 100644 index 00000000..8a966d7a --- /dev/null +++ b/bin/1sh/tests/parser/alias2.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias2.0 214280 2010-10-24 16:55:17Z jilles $ + +alias alias0=exit +x=alias0 +eval 'case $x in alias0) exit 0;; esac' +exit 1 diff --git a/bin/1sh/tests/parser/alias3.0 b/bin/1sh/tests/parser/alias3.0 new file mode 100644 index 00000000..3c6701c8 --- /dev/null +++ b/bin/1sh/tests/parser/alias3.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias3.0 214709 2010-11-02 23:44:29Z jilles $ + +alias alias0=exit +x=alias0 +eval 'case $x in "alias0") alias0 0;; esac' +exit 1 diff --git a/bin/1sh/tests/parser/alias4.0 b/bin/1sh/tests/parser/alias4.0 new file mode 100644 index 00000000..f2794aa6 --- /dev/null +++ b/bin/1sh/tests/parser/alias4.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias4.0 222165 2011-05-21 22:03:06Z jilles $ + +alias alias0=exit +eval 'x=1 alias0 0' +exit 1 diff --git a/bin/1sh/tests/parser/alias5.0 b/bin/1sh/tests/parser/alias5.0 new file mode 100644 index 00000000..b4c53500 --- /dev/null +++ b/bin/1sh/tests/parser/alias5.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias5.0 222165 2011-05-21 22:03:06Z jilles $ + +alias alias0=exit +eval '</dev/null alias0 0' +exit 1 diff --git a/bin/1sh/tests/parser/alias6.0 b/bin/1sh/tests/parser/alias6.0 new file mode 100644 index 00000000..7db847a3 --- /dev/null +++ b/bin/1sh/tests/parser/alias6.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias6.0 224104 2011-07-16 16:14:14Z jilles $ + +alias alias0='| cat >/dev/null' + +eval '{ echo bad; } alias0' +eval '(echo bad)alias0' diff --git a/bin/1sh/tests/parser/alias7.0 b/bin/1sh/tests/parser/alias7.0 new file mode 100644 index 00000000..2dbb19e6 --- /dev/null +++ b/bin/1sh/tests/parser/alias7.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias7.0 240825 2012-09-22 12:52:41Z jilles $ + +alias echo='echo a' +[ "`eval echo b`" = "a b" ] diff --git a/bin/1sh/tests/parser/alias8.0 b/bin/1sh/tests/parser/alias8.0 new file mode 100644 index 00000000..47d6b55a --- /dev/null +++ b/bin/1sh/tests/parser/alias8.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias8.0 240825 2012-09-22 12:52:41Z jilles $ + +alias echo='echo' +[ "`eval echo b`" = b ] diff --git a/bin/1sh/tests/parser/alias9.0 b/bin/1sh/tests/parser/alias9.0 new file mode 100644 index 00000000..06634702 --- /dev/null +++ b/bin/1sh/tests/parser/alias9.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/alias9.0 242721 2012-11-07 23:15:36Z jilles $ + +alias alias0=: +alias alias0=exit +eval 'alias0 0' +exit 1 diff --git a/bin/1sh/tests/parser/and-pipe-not.0 b/bin/1sh/tests/parser/and-pipe-not.0 new file mode 100644 index 00000000..bca8893e --- /dev/null +++ b/bin/1sh/tests/parser/and-pipe-not.0 @@ -0,0 +1,2 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/and-pipe-not.0 191010 2009-04-13 19:12:28Z stefanf $ +true && ! true | false diff --git a/bin/1sh/tests/parser/case1.0 b/bin/1sh/tests/parser/case1.0 new file mode 100644 index 00000000..521ca4a1 --- /dev/null +++ b/bin/1sh/tests/parser/case1.0 @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/case1.0 207824 2010-05-09 17:10:50Z jilles $ + +keywords='if then else elif fi while until for do done { } case esac ! in' + +# Keywords can be used unquoted in case statements, except the keyword +# esac as the first pattern of a '|' alternation without a starting '('. +# (POSIX doesn't seem to require (esac) to work.) +for k in $keywords; do + eval "case $k in (foo|$k) ;; *) echo bad ;; esac" + eval "case $k in ($k) ;; *) echo bad ;; esac" + eval "case $k in foo|$k) ;; *) echo bad ;; esac" + [ "$k" = esac ] && continue + eval "case $k in $k) ;; *) echo bad ;; esac" +done diff --git a/bin/1sh/tests/parser/case2.0 b/bin/1sh/tests/parser/case2.0 new file mode 100644 index 00000000..539ed0fe --- /dev/null +++ b/bin/1sh/tests/parser/case2.0 @@ -0,0 +1,32 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/case2.0 207824 2010-05-09 17:10:50Z jilles $ + +# Pretty much only ash derivatives can parse all of this. + +f1() { + x=$(case x in + (x|esac) ;; + (*) echo bad >&2 ;; + esac) +} +f1 +f2() { + x=$(case x in + (x|esac) ;; + (*) echo bad >&2 + esac) +} +f2 +f3() { + x=$(case x in + x|esac) ;; + *) echo bad >&2 ;; + esac) +} +f3 +f4() { + x=$(case x in + x|esac) ;; + *) echo bad >&2 + esac) +} +f4 diff --git a/bin/1sh/tests/parser/comment1.0 b/bin/1sh/tests/parser/comment1.0 new file mode 100644 index 00000000..aa475ac2 --- /dev/null +++ b/bin/1sh/tests/parser/comment1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/comment1.0 295818 2016-02-19 16:56:07Z jilles $ + +${SH} -c '#' diff --git a/bin/1sh/tests/parser/comment2.42 b/bin/1sh/tests/parser/comment2.42 new file mode 100644 index 00000000..a0b0d696 --- /dev/null +++ b/bin/1sh/tests/parser/comment2.42 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/comment2.42 295818 2016-02-19 16:56:07Z jilles $ + +${SH} -c '# +exit 42' diff --git a/bin/1sh/tests/parser/dollar-quote1.0 b/bin/1sh/tests/parser/dollar-quote1.0 new file mode 100644 index 00000000..12061417 --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote1.0 @@ -0,0 +1,12 @@ +# $FreeBSD$ + +set -e + +[ $'hi' = hi ] +[ $'hi +there' = 'hi +there' ] +[ $'\"\'\\\a\b\f\t\v' = "\"'\\$(printf "\a\b\f\t\v")" ] +[ $'hi\nthere' = 'hi +there' ] +[ $'a\rb' = "$(printf "a\rb")" ] diff --git a/bin/1sh/tests/parser/dollar-quote10.0 b/bin/1sh/tests/parser/dollar-quote10.0 new file mode 100644 index 00000000..fdcabbb3 --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote10.0 @@ -0,0 +1,10 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/dollar-quote10.0 221669 2011-05-08 17:40:10Z jilles $ + +# a umlaut +s=$(printf '\303\244') +# euro sign +s=$s$(printf '\342\202\254') + +# Start a new shell so the locale change is picked up. +ss="$(LC_ALL=en_US.UTF-8 ${SH} -c "printf %s \$'\u00e4\u20ac'")" +[ "$s" = "$ss" ] diff --git a/bin/1sh/tests/parser/dollar-quote11.0 b/bin/1sh/tests/parser/dollar-quote11.0 new file mode 100644 index 00000000..cab063f6 --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote11.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/dollar-quote11.0 221669 2011-05-08 17:40:10Z jilles $ + +# some sort of 't' outside BMP +s=$s$(printf '\360\235\225\245') + +# Start a new shell so the locale change is picked up. +ss="$(LC_ALL=en_US.UTF-8 ${SH} -c "printf %s \$'\U0001d565'")" +[ "$s" = "$ss" ] diff --git a/bin/1sh/tests/parser/dollar-quote12.0 b/bin/1sh/tests/parser/dollar-quote12.0 new file mode 100644 index 00000000..54f80b5a --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote12.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/dollar-quote12.0 286971 2015-08-20 21:31:36Z jilles $ + +# \u without any digits at all remains invalid. +# Our choice is a parse error. + +v=$( (eval ": \$'\u'") 2>&1 >/dev/null) +[ $? -ne 0 ] && [ -n "$v" ] diff --git a/bin/1sh/tests/parser/dollar-quote13.0 b/bin/1sh/tests/parser/dollar-quote13.0 new file mode 100644 index 00000000..436e1dc7 --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote13.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/dollar-quote13.0 286973 2015-08-20 22:05:55Z jilles $ + +# This Unicode escape sequence that has never been in range should either +# fail to expand or expand to a fallback. + +c=$(eval printf %s \$\'\\Uffffff41\' 2>/dev/null) +r=$(($? != 0)) +[ "$r.$c" = '1.' ] || [ "$r.$c" = '0.?' ] || [ "$r.$c" = $'0.\u2222' ] diff --git a/bin/1sh/tests/parser/dollar-quote2.0 b/bin/1sh/tests/parser/dollar-quote2.0 new file mode 100644 index 00000000..4617ed8d --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote2.0 @@ -0,0 +1,5 @@ +# $FreeBSD$ + +# This depends on the ASCII character set. + +[ $'\e' = "$(printf "\033")" ] diff --git a/bin/1sh/tests/parser/dollar-quote3.0 b/bin/1sh/tests/parser/dollar-quote3.0 new file mode 100644 index 00000000..a7e68527 --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote3.0 @@ -0,0 +1,22 @@ +# $FreeBSD$ + +unset LC_ALL +LC_CTYPE=en_US.ISO8859-1 +export LC_CTYPE + +e= +for i in 0 1 2 3; do + for j in 0 1 2 3 4 5 6 7; do + for k in 0 1 2 3 4 5 6 7; do + case $i$j$k in + 000) continue ;; + esac + e="$e\\$i$j$k" + done + done +done +ee=`printf "$e"` +[ "${#ee}" = 255 ] || echo length bad + +# Start a new shell so the locale change is picked up. +[ "$(${SH} -c "printf %s \$'$e'")" = "$ee" ] diff --git a/bin/1sh/tests/parser/dollar-quote4.0 b/bin/1sh/tests/parser/dollar-quote4.0 new file mode 100644 index 00000000..f620af5b --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote4.0 @@ -0,0 +1,19 @@ +# $FreeBSD$ + +unset LC_ALL +LC_CTYPE=en_US.ISO8859-1 +export LC_CTYPE + +e= +for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do + for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do + case $i$j in + 00) continue ;; + esac + e="$e\x$i$j" + done +done + +# Start a new shell so the locale change is picked up. +ee="$(${SH} -c "printf %s \$'$e'")" +[ "${#ee}" = 255 ] || echo length bad diff --git a/bin/1sh/tests/parser/dollar-quote5.0 b/bin/1sh/tests/parser/dollar-quote5.0 new file mode 100644 index 00000000..c2c44ca6 --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote5.0 @@ -0,0 +1,12 @@ +# $FreeBSD$ + +# This depends on the ASCII character set. + +set -e + +[ $'\ca\cb\cc\cd\ce\cf\cg\ch\ci\cj\ck\cl\cm\cn\co\cp\cq\cr\cs\ct\cu\cv\cw\cx\cy\cz' = $'\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032' ] +[ $'\cA\cB\cC\cD\cE\cF\cG\cH\cI\cJ\cK\cL\cM\cN\cO\cP\cQ\cR\cS\cT\cU\cV\cW\cX\cY\cZ' = $'\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032' ] +[ $'\c[' = $'\033' ] +[ $'\c]' = $'\035' ] +[ $'\c^' = $'\036' ] +[ $'\c_' = $'\037' ] diff --git a/bin/1sh/tests/parser/dollar-quote6.0 b/bin/1sh/tests/parser/dollar-quote6.0 new file mode 100644 index 00000000..a4b1e3f4 --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote6.0 @@ -0,0 +1,5 @@ +# $FreeBSD$ + +# This depends on the ASCII character set. + +[ $'\c\\' = $'\034' ] diff --git a/bin/1sh/tests/parser/dollar-quote7.0 b/bin/1sh/tests/parser/dollar-quote7.0 new file mode 100644 index 00000000..c866b1af --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote7.0 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +set -e + +[ $'\u0024\u0040\u0060' = '$@`' ] +[ $'\U00000024\U00000040\U00000060' = '$@`' ] diff --git a/bin/1sh/tests/parser/dollar-quote8.0 b/bin/1sh/tests/parser/dollar-quote8.0 new file mode 100644 index 00000000..8f0b41a0 --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote8.0 @@ -0,0 +1,11 @@ +# $FreeBSD$ + +[ $'hello\0' = hello ] +[ $'hello\0world' = hello ] +[ $'hello\0'$'world' = helloworld ] +[ $'hello\000' = hello ] +[ $'hello\000world' = hello ] +[ $'hello\000'$'world' = helloworld ] +[ $'hello\x00' = hello ] +[ $'hello\x00world' = hello ] +[ $'hello\x00'$'world' = helloworld ] diff --git a/bin/1sh/tests/parser/dollar-quote9.0 b/bin/1sh/tests/parser/dollar-quote9.0 new file mode 100644 index 00000000..df64b7df --- /dev/null +++ b/bin/1sh/tests/parser/dollar-quote9.0 @@ -0,0 +1,8 @@ +# $FreeBSD$ + +# POSIX and C99 say D800-DFFF are undefined in a universal character name. +# We reject this but many other shells expand to something that looks like +# CESU-8. + +v=$( (eval ": \$'\uD800'") 2>&1 >/dev/null) +[ $? -ne 0 ] && [ -n "$v" ] diff --git a/bin/1sh/tests/parser/empty-braces1.0 b/bin/1sh/tests/parser/empty-braces1.0 new file mode 100644 index 00000000..5b3b379b --- /dev/null +++ b/bin/1sh/tests/parser/empty-braces1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/empty-braces1.0 245382 2013-01-13 19:26:33Z jilles $ + +# Unfortunately, some scripts depend on the extension of allowing an empty +# pair of braces. + +{ } & +wait $! diff --git a/bin/1sh/tests/parser/empty-cmd1.0 b/bin/1sh/tests/parser/empty-cmd1.0 new file mode 100644 index 00000000..b2851e37 --- /dev/null +++ b/bin/1sh/tests/parser/empty-cmd1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/empty-cmd1.0 254843 2013-08-25 10:57:48Z jilles $ + +! (eval ': || f()') 2>/dev/null diff --git a/bin/1sh/tests/parser/for1.0 b/bin/1sh/tests/parser/for1.0 new file mode 100644 index 00000000..e2d36b15 --- /dev/null +++ b/bin/1sh/tests/parser/for1.0 @@ -0,0 +1,29 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/for1.0 218889 2011-02-20 14:18:58Z jilles $ + +nl=' +' +list=' a b c' +for s1 in "$nl" " "; do + for s2 in "$nl" ";" ";$nl"; do + for s3 in "$nl" " "; do + r='' + eval "for i${s1}in ${list}${s2}do${s3}r=\"\$r \$i\"; done" + [ "$r" = "$list" ] || exit 1 + done + done +done +set -- $list +for s2 in "$nl" " "; do + for s3 in "$nl" " "; do + r='' + eval "for i${s2}do${s3}r=\"\$r \$i\"; done" + [ "$r" = "$list" ] || exit 1 + done +done +for s1 in "$nl" " "; do + for s2 in "$nl" ";" ";$nl"; do + for s3 in "$nl" " "; do + eval "for i${s1}in${s2}do${s3}exit 1; done" + done + done +done diff --git a/bin/1sh/tests/parser/for2.0 b/bin/1sh/tests/parser/for2.0 new file mode 100644 index 00000000..fad4369c --- /dev/null +++ b/bin/1sh/tests/parser/for2.0 @@ -0,0 +1,15 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/for2.0 218889 2011-02-20 14:18:58Z jilles $ + +# Common extensions to the 'for' syntax. + +nl=' +' +list=' a b c' +set -- $list +for s2 in ";" ";$nl"; do + for s3 in "$nl" " "; do + r='' + eval "for i${s2}do${s3}r=\"\$r \$i\"; done" + [ "$r" = "$list" ] || exit 1 + done +done diff --git a/bin/1sh/tests/parser/func1.0 b/bin/1sh/tests/parser/func1.0 new file mode 100644 index 00000000..dd1d5487 --- /dev/null +++ b/bin/1sh/tests/parser/func1.0 @@ -0,0 +1,25 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/func1.0 214291 2010-10-24 20:45:13Z jilles $ +# POSIX does not require these bytes to work in function names, +# but making them all work seems a good goal. + +failures=0 +unset LC_ALL +export LC_CTYPE=en_US.ISO8859-1 +i=128 +set -f +while [ "$i" -le 255 ]; do + c=$(printf \\"$(printf %o "$i")") + ok=0 + eval "$c() { ok=1; }" + $c + ok1=$ok + ok=0 + "$c" + if [ "$ok" != 1 ] || [ "$ok1" != 1 ]; then + echo "Bad results for character $i" >&2 + : $((failures += 1)) + fi + unset -f $c + i=$((i+1)) +done +exit $((failures > 0)) diff --git a/bin/1sh/tests/parser/func2.0 b/bin/1sh/tests/parser/func2.0 new file mode 100644 index 00000000..7a71706a --- /dev/null +++ b/bin/1sh/tests/parser/func2.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/func2.0 222512 2011-05-30 21:49:59Z jilles $ + +f() { return 42; } +f() { return 3; } & +f +[ $? -eq 42 ] diff --git a/bin/1sh/tests/parser/func3.0 b/bin/1sh/tests/parser/func3.0 new file mode 100644 index 00000000..32646651 --- /dev/null +++ b/bin/1sh/tests/parser/func3.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/func3.0 222512 2011-05-30 21:49:59Z jilles $ + +name=/var/empty/nosuch +f() { true; } <$name +name=/dev/null +f diff --git a/bin/1sh/tests/parser/heredoc1.0 b/bin/1sh/tests/parser/heredoc1.0 new file mode 100644 index 00000000..dd7ad331 --- /dev/null +++ b/bin/1sh/tests/parser/heredoc1.0 @@ -0,0 +1,85 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc1.0 204836 2010-03-07 15:08:42Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '"$(cat <<EOF +hi +EOF +)" = hi' + +check '"$(cat <<EOF +${$+hi} +EOF +)" = hi' + +unset yy +check '"$(cat <<EOF +${yy-hi} +EOF +)" = hi' + +check '"$(cat <<EOF +${$+hi +there} +EOF +)" = "hi +there"' + +check '"$(cat <<EOF +$((1+1)) +EOF +)" = 2' + +check '"$(cat <<EOF +$(echo hi) +EOF +)" = hi' + +check '"$(cat <<EOF +`echo hi` +EOF +)" = hi' + +check '"$(cat <<\EOF +${$+hi} +EOF +)" = "\${\$+hi}"' + +check '"$(cat <<\EOF +$( +EOF +)" = \$\(' + +check '"$(cat <<\EOF +` +EOF +)" = \`' + +check '"$(cat <<EOF +" +EOF +)" = \"' + +check '"$(cat <<\EOF +" +EOF +)" = \"' + +check '"$(cat <<esac +'"'"' +esac +)" = "'"'"'"' + +check '"$(cat <<\) +'"'"' +) +)" = "'"'"'"' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/parser/heredoc10.0 b/bin/1sh/tests/parser/heredoc10.0 new file mode 100644 index 00000000..5ada3115 --- /dev/null +++ b/bin/1sh/tests/parser/heredoc10.0 @@ -0,0 +1,49 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc10.0 221887 2011-05-14 14:19:30Z jilles $ + +# It may be argued that +# x=$(cat <<EOF +# foo +# EOF) +# is a valid complete command that sets x to foo, because +# cat <<EOF +# foo +# EOF +# is a valid script even without the final newline. +# However, if the here-document is not within a new-style command substitution +# or there are other constructs nested inside the command substitution that +# need terminators, the delimiter at the start of a line followed by a close +# parenthesis is clearly a literal part of the here-document. + +# This file contains tests that may not work with simplistic $(...) parsers. +# The open parentheses in comments help mksh, but not zsh. + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '"$(cat <<EOF # ( +EOF ) +EOF +)" = "EOF )"' + +check '"$({ cat <<EOF # ( +EOF) +EOF +})" = "EOF)"' + +check '"$(if :; then cat <<EOF # ( +EOF) +EOF +fi)" = "EOF)"' + +check '"$( (cat <<EOF # ( +EOF) +EOF +))" = "EOF)"' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/parser/heredoc11.0 b/bin/1sh/tests/parser/heredoc11.0 new file mode 100644 index 00000000..ed255593 --- /dev/null +++ b/bin/1sh/tests/parser/heredoc11.0 @@ -0,0 +1,26 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc11.0 222134 2011-05-20 16:03:36Z jilles $ + +failures='' + +check() { + if eval "[ $* ]"; then + : + else + echo "Failed: $*" + failures=x$failures + fi +} + +check '`cat <<EOF +foo +EOF` = foo' + +check '"`cat <<EOF +foo +EOF`" = foo' + +check '`eval "cat <<EOF +foo +EOF"` = foo' + +test "x$failures" = x diff --git a/bin/1sh/tests/parser/heredoc12.0 b/bin/1sh/tests/parser/heredoc12.0 new file mode 100644 index 00000000..6a5eefdc --- /dev/null +++ b/bin/1sh/tests/parser/heredoc12.0 @@ -0,0 +1,47 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc12.0 271593 2014-09-14 16:46:30Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +longmark=`printf %01000d 4` +longmarkstripped=`printf %0999d 0` + +check '"$(cat <<'"$longmark +$longmark"' +echo yes)" = "yes"' + +check '"$(cat <<\'"$longmark +$longmark"' +echo yes)" = "yes"' + +check '"$(cat <<'"$longmark +yes +$longmark"' +)" = "yes"' + +check '"$(cat <<\'"$longmark +yes +$longmark"' +)" = "yes"' + +check '"$(cat <<'"$longmark +$longmarkstripped +$longmark. +$longmark"' +)" = "'"$longmarkstripped +$longmark."'"' + +check '"$(cat <<\'"$longmark +$longmarkstripped +$longmark. +$longmark"' +)" = "'"$longmarkstripped +$longmark."'"' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/parser/heredoc13.0 b/bin/1sh/tests/parser/heredoc13.0 new file mode 100644 index 00000000..705082bb --- /dev/null +++ b/bin/1sh/tests/parser/heredoc13.0 @@ -0,0 +1,21 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc13.0 287408 2015-09-02 19:49:55Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '"$(cat <<"" + +echo yes)" = "yes"' + +check '"$(cat <<"" +yes + +)" = "yes"' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/parser/heredoc2.0 b/bin/1sh/tests/parser/heredoc2.0 new file mode 100644 index 00000000..19314734 --- /dev/null +++ b/bin/1sh/tests/parser/heredoc2.0 @@ -0,0 +1,39 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc2.0 211405 2010-08-16 21:14:49Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +s='ast*que?non' sq=\' dq=\" + +check '"$(cat <<EOF +${s} +EOF +)" = "ast*que?non"' + +check '"$(cat <<EOF +${s+'$sq'x'$sq'} +EOF +)" = ${sq}x${sq}' + +check '"$(cat <<EOF +${s#ast} +EOF +)" = "*que?non"' + +check '"$(cat <<EOF +${s##"ast"} +EOF +)" = "*que?non"' + +check '"$(cat <<EOF +${s##'$sq'ast'$sq'} +EOF +)" = "*que?non"' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/parser/heredoc3.0 b/bin/1sh/tests/parser/heredoc3.0 new file mode 100644 index 00000000..f0c8d88a --- /dev/null +++ b/bin/1sh/tests/parser/heredoc3.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc3.0 207824 2010-05-09 17:10:50Z jilles $ + +# This may be expected to work, but pretty much only ash derivatives allow it. + +test "$(cat <<EOF)" = "hi there" +hi there +EOF diff --git a/bin/1sh/tests/parser/heredoc4.0 b/bin/1sh/tests/parser/heredoc4.0 new file mode 100644 index 00000000..1ea11a55 --- /dev/null +++ b/bin/1sh/tests/parser/heredoc4.0 @@ -0,0 +1,44 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc4.0 208655 2010-05-30 14:11:27Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +f() { + cat <<EOF && echo `echo bar` +foo +EOF +} +check '"`f`" = "foo +bar"' + +f() { + cat <<EOF && echo $(echo bar) +foo +EOF +} +check '"$(f)" = "foo +bar"' + +f() { + echo `echo bar` && cat <<EOF +foo +EOF +} +check '"`f`" = "bar +foo"' + +f() { + echo $(echo bar) && cat <<EOF +foo +EOF +} +check '"$(f)" = "bar +foo"' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/parser/heredoc5.0 b/bin/1sh/tests/parser/heredoc5.0 new file mode 100644 index 00000000..e261a2a3 --- /dev/null +++ b/bin/1sh/tests/parser/heredoc5.0 @@ -0,0 +1,56 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc5.0 208655 2010-05-30 14:11:27Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +f() { + cat <<EOF && echo `cat <<EOF +bar +EOF +` +foo +EOF +} +check '"`f`" = "foo +bar"' + +f() { + cat <<EOF && echo $(cat <<EOF +bar +EOF +) +foo +EOF +} +check '"$(f)" = "foo +bar"' + +f() { + echo `cat <<EOF +bar +EOF +` && cat <<EOF +foo +EOF +} +check '"`f`" = "bar +foo"' + +f() { + echo $(cat <<EOF +bar +EOF +) && cat <<EOF +foo +EOF +} +check '"$(f)" = "bar +foo"' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/parser/heredoc6.0 b/bin/1sh/tests/parser/heredoc6.0 new file mode 100644 index 00000000..9b791856 --- /dev/null +++ b/bin/1sh/tests/parser/heredoc6.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc6.0 208656 2010-05-30 14:20:32Z jilles $ + +r= +! command eval ": <<EOF; )" 2>/dev/null; command eval : hi \${r:=0} +exit ${r:-3} diff --git a/bin/1sh/tests/parser/heredoc7.0 b/bin/1sh/tests/parser/heredoc7.0 new file mode 100644 index 00000000..0296f663 --- /dev/null +++ b/bin/1sh/tests/parser/heredoc7.0 @@ -0,0 +1,19 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc7.0 210488 2010-07-25 22:25:52Z jilles $ + +# Some of these created malformed parse trees with null pointers for here +# documents, causing the here document writing process to segfault. +eval ': <<EOF' +eval ': <<EOF;' +eval '`: <<EOF`' +eval '`: <<EOF;`' +eval '`: <<EOF`;' +eval '`: <<EOF;`;' + +# Some of these created malformed parse trees with null pointers for here +# documents, causing sh to segfault. +eval ': <<\EOF' +eval ': <<\EOF;' +eval '`: <<\EOF`' +eval '`: <<\EOF;`' +eval '`: <<\EOF`;' +eval '`: <<\EOF;`;' diff --git a/bin/1sh/tests/parser/heredoc8.0 b/bin/1sh/tests/parser/heredoc8.0 new file mode 100644 index 00000000..1cb8c92c --- /dev/null +++ b/bin/1sh/tests/parser/heredoc8.0 @@ -0,0 +1,20 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc8.0 211405 2010-08-16 21:14:49Z jilles $ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +s='ast*que?non' sq=\' dq=\" + +# This is possibly useful but differs from other shells. +check '"$(cat <<EOF +${s+"x"} +EOF +)" = ${dq}x${dq}' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/parser/heredoc9.0 b/bin/1sh/tests/parser/heredoc9.0 new file mode 100644 index 00000000..f2958c72 --- /dev/null +++ b/bin/1sh/tests/parser/heredoc9.0 @@ -0,0 +1,58 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/heredoc9.0 221887 2011-05-14 14:19:30Z jilles $ + +# It may be argued that +# x=$(cat <<EOF +# foo +# EOF) +# is a valid complete command that sets x to foo, because +# cat <<EOF +# foo +# EOF +# is a valid script even without the final newline. +# However, if the here-document is not within a new-style command substitution +# or there are other constructs nested inside the command substitution that +# need terminators, the delimiter at the start of a line followed by a close +# parenthesis is clearly a literal part of the here-document. + +# This file contains tests that also work with simplistic $(...) parsers. + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '`${SH} -c "cat <<EOF +EOF) +EOF +"` = "EOF)"' + +check '`${SH} -c "(cat <<EOF +EOF) +EOF +)"` = "EOF)"' + +check '"`cat <<EOF +EOF x +EOF +`" = "EOF x"' + +check '"`cat <<EOF +EOF ) +EOF +`" = "EOF )"' + +check '"`cat <<EOF +EOF) +EOF +`" = "EOF)"' + +check '"$(cat <<EOF +EOF x +EOF +)" = "EOF x"' + +exit $((failures != 0)) diff --git a/bin/1sh/tests/parser/line-cont1.0 b/bin/1sh/tests/parser/line-cont1.0 new file mode 100644 index 00000000..be1673ac --- /dev/null +++ b/bin/1sh/tests/parser/line-cont1.0 @@ -0,0 +1,16 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont1.0 273243 2014-10-17 21:52:57Z jilles $ + +i\ +f +t\ +r\ +u\ +e +t\ +h\ +e\ +n +: +\ +f\ +i diff --git a/bin/1sh/tests/parser/line-cont10.0 b/bin/1sh/tests/parser/line-cont10.0 new file mode 100644 index 00000000..d79f182b --- /dev/null +++ b/bin/1sh/tests/parser/line-cont10.0 @@ -0,0 +1,18 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont10.0 273276 2014-10-19 11:59:15Z jilles $ + +v=XaaaXbbbX +[ "${v\ +#\ +*\ +a}.${v\ +#\ +#\ +*\ +a}.${v\ +%\ +b\ +*}.${v\ +%\ +%\ +b\ +*}" = aaXbbbX.XbbbX.XaaaXbb.XaaaX ] diff --git a/bin/1sh/tests/parser/line-cont11.0 b/bin/1sh/tests/parser/line-cont11.0 new file mode 100644 index 00000000..053d81d3 --- /dev/null +++ b/bin/1sh/tests/parser/line-cont11.0 @@ -0,0 +1,23 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont11.0 273276 2014-10-19 11:59:15Z jilles $ + +T=$(mktemp "${TMPDIR:-/tmp}/sh-test.XXXXXXXX") || exit +trap 'rm -f -- "$T"' 0 +w='#A' +# A naive pgetc_linecont() would push back two characters here, which +# fails if a new buffer is read between the two characters. +c='${w#\#}' +c=$c$c$c$c +c=$c$c$c$c +c=$c$c$c$c +c=$c$c$c$c +c=$c$c$c$c +c=$c$c$c$c +printf 'v=%s\n' "$c" >"$T" +. "$T" +if [ "${#v}" != 4096 ]; then + echo "Length is bad (${#v})" + exit 3 +fi +case $v in +*[!A]*) echo "Content is bad"; exit 3 ;; +esac diff --git a/bin/1sh/tests/parser/line-cont12.0 b/bin/1sh/tests/parser/line-cont12.0 new file mode 100644 index 00000000..916cec7b --- /dev/null +++ b/bin/1sh/tests/parser/line-cont12.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont12.0 333507 2018-05-11 21:56:01Z jilles $ + +[ '\ +' = "\\ +" ] diff --git a/bin/1sh/tests/parser/line-cont2.0 b/bin/1sh/tests/parser/line-cont2.0 new file mode 100644 index 00000000..0f058e15 --- /dev/null +++ b/bin/1sh/tests/parser/line-cont2.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont2.0 273243 2014-10-17 21:52:57Z jilles $ + +[ "a\ +b" = ab ] diff --git a/bin/1sh/tests/parser/line-cont3.0 b/bin/1sh/tests/parser/line-cont3.0 new file mode 100644 index 00000000..196d4203 --- /dev/null +++ b/bin/1sh/tests/parser/line-cont3.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont3.0 273243 2014-10-17 21:52:57Z jilles $ + +v=`printf %s 'a\ +b'` +w="`printf %s 'c\ +d'`" +[ "$v$w" = abcd ] diff --git a/bin/1sh/tests/parser/line-cont4.0 b/bin/1sh/tests/parser/line-cont4.0 new file mode 100644 index 00000000..47fc8410 --- /dev/null +++ b/bin/1sh/tests/parser/line-cont4.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont4.0 273276 2014-10-19 11:59:15Z jilles $ + +v=abcd +[ "$\ +v.$\ +{v}.${\ +v}.${v\ +}" = abcd.abcd.abcd.abcd ] diff --git a/bin/1sh/tests/parser/line-cont5.0 b/bin/1sh/tests/parser/line-cont5.0 new file mode 100644 index 00000000..b0037c80 --- /dev/null +++ b/bin/1sh/tests/parser/line-cont5.0 @@ -0,0 +1,14 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont5.0 273276 2014-10-19 11:59:15Z jilles $ + +bad=1 +case x in +x\ +) ;\ +; *) exit 7 +esac &\ +& bad= &\ +& : >\ +>/dev/null + +false |\ +| [ -z "$bad" ] diff --git a/bin/1sh/tests/parser/line-cont6.0 b/bin/1sh/tests/parser/line-cont6.0 new file mode 100644 index 00000000..824ed1a5 --- /dev/null +++ b/bin/1sh/tests/parser/line-cont6.0 @@ -0,0 +1,23 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont6.0 273276 2014-10-19 11:59:15Z jilles $ + +v0\ +=abc + +v=$(cat <\ +<\ +E\ +O\ +F +${v0}d +EOF +) + +w=$(cat <\ +<\ +-\ +EOF + efgh +EOF +) + +[ "$v.$w" = "abcd.efgh" ] diff --git a/bin/1sh/tests/parser/line-cont7.0 b/bin/1sh/tests/parser/line-cont7.0 new file mode 100644 index 00000000..0e512c3f --- /dev/null +++ b/bin/1sh/tests/parser/line-cont7.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont7.0 273276 2014-10-19 11:59:15Z jilles $ + +[ "$(\ +( +1\ ++ 1)\ +)" = 2 ] diff --git a/bin/1sh/tests/parser/line-cont8.0 b/bin/1sh/tests/parser/line-cont8.0 new file mode 100644 index 00000000..ce4a9714 --- /dev/null +++ b/bin/1sh/tests/parser/line-cont8.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont8.0 273276 2014-10-19 11:59:15Z jilles $ + +set -- a b c d e f g h i j +[ "${1\ +0\ +}" = j ] diff --git a/bin/1sh/tests/parser/line-cont9.0 b/bin/1sh/tests/parser/line-cont9.0 new file mode 100644 index 00000000..92e14b95 --- /dev/null +++ b/bin/1sh/tests/parser/line-cont9.0 @@ -0,0 +1,6 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/line-cont9.0 273276 2014-10-19 11:59:15Z jilles $ + +[ "${$\ +:\ ++\ +xyz}" = xyz ] diff --git a/bin/1sh/tests/parser/no-space1.0 b/bin/1sh/tests/parser/no-space1.0 new file mode 100644 index 00000000..9546f811 --- /dev/null +++ b/bin/1sh/tests/parser/no-space1.0 @@ -0,0 +1,18 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/no-space1.0 218891 2011-02-20 17:28:58Z jilles $ + +# These are ugly but are required to work. + +set -e + +while(false)do(:)done +if(false)then(:)fi +if(false)then(:)else(:)fi +(:&&:)||: +until(:)do(:)done +case x in(x);;*)exit 1;(:)esac +case x in(x);;*)exit 1;;esac +for i do(:)done +{(:)} +f(){(:)} +:|: +(:)|(:) diff --git a/bin/1sh/tests/parser/no-space2.0 b/bin/1sh/tests/parser/no-space2.0 new file mode 100644 index 00000000..2448d9af --- /dev/null +++ b/bin/1sh/tests/parser/no-space2.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/no-space2.0 218891 2011-02-20 17:28:58Z jilles $ + +# This conflicts with ksh extended patterns but occurs in the wild. + +set -e + +!(false) diff --git a/bin/1sh/tests/parser/nul1.0 b/bin/1sh/tests/parser/nul1.0 new file mode 100644 index 00000000..6919b3a4 --- /dev/null +++ b/bin/1sh/tests/parser/nul1.0 @@ -0,0 +1,12 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/nul1.0 295825 2016-02-19 21:53:12Z jilles $ +# Although POSIX does not specify the effect of NUL bytes in scripts, +# we ignore them. + +{ + printf 'v=%03000d\0%02000d' 7 2 + dd if=/dev/zero bs=1000 count=1 status=none + printf '1 w=%03000d%02000d1\0\n' 7 2 + printf '\0l\0v\0=\0$\0{\0#\0v\0}\n' + printf '\0l\0w\0=\0\0$\0{\0#\0w}\0\0\0\n' + printf '[ "$lv.$lw.$v" = "5001.5001.$w" ]\n' +} | ${SH} diff --git a/bin/1sh/tests/parser/only-redir1.0 b/bin/1sh/tests/parser/only-redir1.0 new file mode 100644 index 00000000..3479c3bb --- /dev/null +++ b/bin/1sh/tests/parser/only-redir1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/only-redir1.0 210221 2010-07-18 12:45:31Z jilles $ +</dev/null & +wait $! diff --git a/bin/1sh/tests/parser/only-redir2.0 b/bin/1sh/tests/parser/only-redir2.0 new file mode 100644 index 00000000..b0b3d2cc --- /dev/null +++ b/bin/1sh/tests/parser/only-redir2.0 @@ -0,0 +1,2 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/only-redir2.0 254335 2013-08-14 19:34:13Z jilles $ +</dev/null | : diff --git a/bin/1sh/tests/parser/only-redir3.0 b/bin/1sh/tests/parser/only-redir3.0 new file mode 100644 index 00000000..972c9aef --- /dev/null +++ b/bin/1sh/tests/parser/only-redir3.0 @@ -0,0 +1,2 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/only-redir3.0 254335 2013-08-14 19:34:13Z jilles $ +case x in x) </dev/null ;; esac diff --git a/bin/1sh/tests/parser/only-redir4.0 b/bin/1sh/tests/parser/only-redir4.0 new file mode 100644 index 00000000..9e7cda83 --- /dev/null +++ b/bin/1sh/tests/parser/only-redir4.0 @@ -0,0 +1,2 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/only-redir4.0 254335 2013-08-14 19:34:13Z jilles $ +case x in x) </dev/null ;& esac diff --git a/bin/1sh/tests/parser/pipe-not1.0 b/bin/1sh/tests/parser/pipe-not1.0 new file mode 100644 index 00000000..de83b6b2 --- /dev/null +++ b/bin/1sh/tests/parser/pipe-not1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/pipe-not1.0 214281 2010-10-24 17:06:49Z jilles $ + +: | ! : | false diff --git a/bin/1sh/tests/parser/set-v1.0 b/bin/1sh/tests/parser/set-v1.0 new file mode 100644 index 00000000..eb985e6b --- /dev/null +++ b/bin/1sh/tests/parser/set-v1.0 @@ -0,0 +1,8 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/set-v1.0 295937 2016-02-23 22:44:01Z jilles $ + +${SH} <<\EOF +echo one >&2 +set -v +echo two >&2 +echo three >&2 +EOF diff --git a/bin/1sh/tests/parser/set-v1.0.stderr b/bin/1sh/tests/parser/set-v1.0.stderr new file mode 100644 index 00000000..d904fa5f --- /dev/null +++ b/bin/1sh/tests/parser/set-v1.0.stderr @@ -0,0 +1,5 @@ +one +echo two >&2 +two +echo three >&2 +three diff --git a/bin/1sh/tests/parser/var-assign1.0 b/bin/1sh/tests/parser/var-assign1.0 new file mode 100644 index 00000000..244ccfc9 --- /dev/null +++ b/bin/1sh/tests/parser/var-assign1.0 @@ -0,0 +1,19 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/parser/var-assign1.0 257920 2013-11-10 18:46:59Z jilles $ +# In a variable assignment, both the name and the equals sign must be entirely +# unquoted. Therefore, there is only one assignment below; the other words +# containing equals signs are command words. + +abc=0 +\abc=1 2>/dev/null +a\bc=2 2>/dev/null +abc\=3 2>/dev/null +a\bc\=4 2>/dev/null +'abc'=5 2>/dev/null +a'b'c=6 2>/dev/null +abc'='7 2>/dev/null +'abc=8' 2>/dev/null +"abc"=9 2>/dev/null +a"b"c=10 2>/dev/null +abc"="11 2>/dev/null +"abc=12" 2>/dev/null +[ "$abc" = 0 ] diff --git a/bin/1sh/tests/set-e/Makefile b/bin/1sh/tests/set-e/Makefile new file mode 100644 index 00000000..d938300e --- /dev/null +++ b/bin/1sh/tests/set-e/Makefile @@ -0,0 +1,46 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/Makefile 299094 2016-05-04 23:20:53Z ngie $ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +${PACKAGE}FILES+= and1.0 +${PACKAGE}FILES+= and2.1 +${PACKAGE}FILES+= and3.0 +${PACKAGE}FILES+= and4.0 +${PACKAGE}FILES+= background1.0 +${PACKAGE}FILES+= cmd1.0 +${PACKAGE}FILES+= cmd2.1 +${PACKAGE}FILES+= elif1.0 +${PACKAGE}FILES+= elif2.0 +${PACKAGE}FILES+= eval1.0 +${PACKAGE}FILES+= eval2.1 +${PACKAGE}FILES+= for1.0 +${PACKAGE}FILES+= func1.0 +${PACKAGE}FILES+= func2.1 +${PACKAGE}FILES+= if1.0 +${PACKAGE}FILES+= if2.0 +${PACKAGE}FILES+= if3.0 +${PACKAGE}FILES+= not1.0 +${PACKAGE}FILES+= not2.0 +${PACKAGE}FILES+= or1.0 +${PACKAGE}FILES+= or2.0 +${PACKAGE}FILES+= or3.1 +${PACKAGE}FILES+= pipe1.1 +${PACKAGE}FILES+= pipe2.0 +${PACKAGE}FILES+= return1.0 +${PACKAGE}FILES+= semi1.1 +${PACKAGE}FILES+= semi2.1 +${PACKAGE}FILES+= subshell1.0 +${PACKAGE}FILES+= subshell2.1 +${PACKAGE}FILES+= until1.0 +${PACKAGE}FILES+= until2.0 +${PACKAGE}FILES+= until3.0 +${PACKAGE}FILES+= while1.0 +${PACKAGE}FILES+= while2.0 +${PACKAGE}FILES+= while3.0 + +.include <bsd.test.mk> diff --git a/bin/1sh/tests/set-e/Makefile.depend b/bin/1sh/tests/set-e/Makefile.depend new file mode 100644 index 00000000..110a72e1 --- /dev/null +++ b/bin/1sh/tests/set-e/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/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/set-e/and1.0 b/bin/1sh/tests/set-e/and1.0 new file mode 100644 index 00000000..dc5a0108 --- /dev/null +++ b/bin/1sh/tests/set-e/and1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/and1.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +true && true diff --git a/bin/1sh/tests/set-e/and2.1 b/bin/1sh/tests/set-e/and2.1 new file mode 100644 index 00000000..c964f3df --- /dev/null +++ b/bin/1sh/tests/set-e/and2.1 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/and2.1 149781 2005-09-04 11:59:59Z stefanf $ +set -e +true && false +exit 0 diff --git a/bin/1sh/tests/set-e/and3.0 b/bin/1sh/tests/set-e/and3.0 new file mode 100644 index 00000000..b3ef8b3d --- /dev/null +++ b/bin/1sh/tests/set-e/and3.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/and3.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +false && true +exit 0 diff --git a/bin/1sh/tests/set-e/and4.0 b/bin/1sh/tests/set-e/and4.0 new file mode 100644 index 00000000..356804dd --- /dev/null +++ b/bin/1sh/tests/set-e/and4.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/and4.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +false && false +exit 0 diff --git a/bin/1sh/tests/set-e/background1.0 b/bin/1sh/tests/set-e/background1.0 new file mode 100644 index 00000000..b7d70c7e --- /dev/null +++ b/bin/1sh/tests/set-e/background1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/background1.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +false & diff --git a/bin/1sh/tests/set-e/cmd1.0 b/bin/1sh/tests/set-e/cmd1.0 new file mode 100644 index 00000000..f88034f7 --- /dev/null +++ b/bin/1sh/tests/set-e/cmd1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/cmd1.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +true diff --git a/bin/1sh/tests/set-e/cmd2.1 b/bin/1sh/tests/set-e/cmd2.1 new file mode 100644 index 00000000..a8dbf64f --- /dev/null +++ b/bin/1sh/tests/set-e/cmd2.1 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/cmd2.1 149781 2005-09-04 11:59:59Z stefanf $ +set -e +false +exit 0 diff --git a/bin/1sh/tests/set-e/elif1.0 b/bin/1sh/tests/set-e/elif1.0 new file mode 100644 index 00000000..aa8ee945 --- /dev/null +++ b/bin/1sh/tests/set-e/elif1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/elif1.0 211399 2010-08-16 17:18:08Z jilles $ +set -e +if false; then + : +elif false; then + : +fi diff --git a/bin/1sh/tests/set-e/elif2.0 b/bin/1sh/tests/set-e/elif2.0 new file mode 100644 index 00000000..f742f81b --- /dev/null +++ b/bin/1sh/tests/set-e/elif2.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/elif2.0 211399 2010-08-16 17:18:08Z jilles $ +set -e +if false; then + : +elif false; false; then + : +fi diff --git a/bin/1sh/tests/set-e/eval1.0 b/bin/1sh/tests/set-e/eval1.0 new file mode 100644 index 00000000..257ccd06 --- /dev/null +++ b/bin/1sh/tests/set-e/eval1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/eval1.0 193178 2009-05-31 17:23:27Z stefanf $ +set -e +eval false || true diff --git a/bin/1sh/tests/set-e/eval2.1 b/bin/1sh/tests/set-e/eval2.1 new file mode 100644 index 00000000..c6f161b9 --- /dev/null +++ b/bin/1sh/tests/set-e/eval2.1 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/eval2.1 193178 2009-05-31 17:23:27Z stefanf $ +set -e +eval false +exit 0 diff --git a/bin/1sh/tests/set-e/for1.0 b/bin/1sh/tests/set-e/for1.0 new file mode 100644 index 00000000..344d851c --- /dev/null +++ b/bin/1sh/tests/set-e/for1.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/for1.0 149791 2005-09-05 09:42:10Z stefanf $ +set -e +f() { + for i in a b c; do + false + true + done +} +f || true diff --git a/bin/1sh/tests/set-e/func1.0 b/bin/1sh/tests/set-e/func1.0 new file mode 100644 index 00000000..a3435785 --- /dev/null +++ b/bin/1sh/tests/set-e/func1.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/func1.0 149791 2005-09-05 09:42:10Z stefanf $ +set -e +f() { + false + true +} +f || true diff --git a/bin/1sh/tests/set-e/func2.1 b/bin/1sh/tests/set-e/func2.1 new file mode 100644 index 00000000..1ac1b46f --- /dev/null +++ b/bin/1sh/tests/set-e/func2.1 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/func2.1 149791 2005-09-05 09:42:10Z stefanf $ +set -e +f() { + false + exit 0 +} +f diff --git a/bin/1sh/tests/set-e/if1.0 b/bin/1sh/tests/set-e/if1.0 new file mode 100644 index 00000000..19cf155f --- /dev/null +++ b/bin/1sh/tests/set-e/if1.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/if1.0 211399 2010-08-16 17:18:08Z jilles $ +set -e +if false; then + : +fi diff --git a/bin/1sh/tests/set-e/if2.0 b/bin/1sh/tests/set-e/if2.0 new file mode 100644 index 00000000..52e6e596 --- /dev/null +++ b/bin/1sh/tests/set-e/if2.0 @@ -0,0 +1,7 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/if2.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +# PR 28852 +if true; then + false && true +fi +exit 0 diff --git a/bin/1sh/tests/set-e/if3.0 b/bin/1sh/tests/set-e/if3.0 new file mode 100644 index 00000000..61598039 --- /dev/null +++ b/bin/1sh/tests/set-e/if3.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/if3.0 211399 2010-08-16 17:18:08Z jilles $ +set -e +if false; false; then + : +fi diff --git a/bin/1sh/tests/set-e/not1.0 b/bin/1sh/tests/set-e/not1.0 new file mode 100644 index 00000000..5421ab4a --- /dev/null +++ b/bin/1sh/tests/set-e/not1.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/not1.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +! true +exit 0 diff --git a/bin/1sh/tests/set-e/not2.0 b/bin/1sh/tests/set-e/not2.0 new file mode 100644 index 00000000..146f4949 --- /dev/null +++ b/bin/1sh/tests/set-e/not2.0 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/not2.0 193178 2009-05-31 17:23:27Z stefanf $ +set -e +! false +! eval false diff --git a/bin/1sh/tests/set-e/or1.0 b/bin/1sh/tests/set-e/or1.0 new file mode 100644 index 00000000..bdf99f7a --- /dev/null +++ b/bin/1sh/tests/set-e/or1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/or1.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +true || false diff --git a/bin/1sh/tests/set-e/or2.0 b/bin/1sh/tests/set-e/or2.0 new file mode 100644 index 00000000..d96ae4a7 --- /dev/null +++ b/bin/1sh/tests/set-e/or2.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/or2.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +false || true diff --git a/bin/1sh/tests/set-e/or3.1 b/bin/1sh/tests/set-e/or3.1 new file mode 100644 index 00000000..3cde1bff --- /dev/null +++ b/bin/1sh/tests/set-e/or3.1 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/or3.1 149781 2005-09-04 11:59:59Z stefanf $ +set -e +false || false +exit 0 diff --git a/bin/1sh/tests/set-e/pipe1.1 b/bin/1sh/tests/set-e/pipe1.1 new file mode 100644 index 00000000..b3937ad4 --- /dev/null +++ b/bin/1sh/tests/set-e/pipe1.1 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/pipe1.1 149781 2005-09-04 11:59:59Z stefanf $ +set -e +true | false +exit 0 diff --git a/bin/1sh/tests/set-e/pipe2.0 b/bin/1sh/tests/set-e/pipe2.0 new file mode 100644 index 00000000..50d90306 --- /dev/null +++ b/bin/1sh/tests/set-e/pipe2.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/pipe2.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +false | true diff --git a/bin/1sh/tests/set-e/return1.0 b/bin/1sh/tests/set-e/return1.0 new file mode 100644 index 00000000..39439b51 --- /dev/null +++ b/bin/1sh/tests/set-e/return1.0 @@ -0,0 +1,11 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/return1.0 149788 2005-09-04 21:29:09Z stefanf $ +set -e + +# PR 77067, 85267 +f() { + return 1 + true +} + +f || true +exit 0 diff --git a/bin/1sh/tests/set-e/semi1.1 b/bin/1sh/tests/set-e/semi1.1 new file mode 100644 index 00000000..624d4915 --- /dev/null +++ b/bin/1sh/tests/set-e/semi1.1 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/semi1.1 149781 2005-09-04 11:59:59Z stefanf $ +set -e +false; true +exit 0 diff --git a/bin/1sh/tests/set-e/semi2.1 b/bin/1sh/tests/set-e/semi2.1 new file mode 100644 index 00000000..f6c8d468 --- /dev/null +++ b/bin/1sh/tests/set-e/semi2.1 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/semi2.1 149781 2005-09-04 11:59:59Z stefanf $ +set -e +true; false +exit 0 diff --git a/bin/1sh/tests/set-e/subshell1.0 b/bin/1sh/tests/set-e/subshell1.0 new file mode 100644 index 00000000..7975eac9 --- /dev/null +++ b/bin/1sh/tests/set-e/subshell1.0 @@ -0,0 +1,3 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/subshell1.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +(true) diff --git a/bin/1sh/tests/set-e/subshell2.1 b/bin/1sh/tests/set-e/subshell2.1 new file mode 100644 index 00000000..6b441cd5 --- /dev/null +++ b/bin/1sh/tests/set-e/subshell2.1 @@ -0,0 +1,4 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/subshell2.1 149781 2005-09-04 11:59:59Z stefanf $ +set -e +(false) +exit 0 diff --git a/bin/1sh/tests/set-e/until1.0 b/bin/1sh/tests/set-e/until1.0 new file mode 100644 index 00000000..281b4617 --- /dev/null +++ b/bin/1sh/tests/set-e/until1.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/until1.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +until false; do + break +done diff --git a/bin/1sh/tests/set-e/until2.0 b/bin/1sh/tests/set-e/until2.0 new file mode 100644 index 00000000..8b571d31 --- /dev/null +++ b/bin/1sh/tests/set-e/until2.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/until2.0 149781 2005-09-04 11:59:59Z stefanf $ +set -e +until false; false; do + break +done diff --git a/bin/1sh/tests/set-e/until3.0 b/bin/1sh/tests/set-e/until3.0 new file mode 100644 index 00000000..cc39584c --- /dev/null +++ b/bin/1sh/tests/set-e/until3.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/until3.0 149791 2005-09-05 09:42:10Z stefanf $ +set -e +f() { + until false; do + false + break + done +} +f || true diff --git a/bin/1sh/tests/set-e/while1.0 b/bin/1sh/tests/set-e/while1.0 new file mode 100644 index 00000000..a60532c8 --- /dev/null +++ b/bin/1sh/tests/set-e/while1.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/while1.0 211399 2010-08-16 17:18:08Z jilles $ +set -e +while false; do + : +done diff --git a/bin/1sh/tests/set-e/while2.0 b/bin/1sh/tests/set-e/while2.0 new file mode 100644 index 00000000..d0e4f71a --- /dev/null +++ b/bin/1sh/tests/set-e/while2.0 @@ -0,0 +1,5 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/while2.0 211399 2010-08-16 17:18:08Z jilles $ +set -e +while false; false; do + : +done diff --git a/bin/1sh/tests/set-e/while3.0 b/bin/1sh/tests/set-e/while3.0 new file mode 100644 index 00000000..5a1b2695 --- /dev/null +++ b/bin/1sh/tests/set-e/while3.0 @@ -0,0 +1,9 @@ +# $FreeBSD: releng/12.1/bin/sh/tests/set-e/while3.0 149791 2005-09-05 09:42:10Z stefanf $ +set -e +f() { + while true; do + false + break + done +} +f || true |