aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/tests/builtins
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sh/tests/builtins')
-rw-r--r--bin/sh/tests/builtins/Makefile187
-rw-r--r--bin/sh/tests/builtins/Makefile.depend11
-rw-r--r--bin/sh/tests/builtins/alias.09
-rw-r--r--bin/sh/tests/builtins/alias.0.stdout4
-rw-r--r--bin/sh/tests/builtins/alias.13
-rw-r--r--bin/sh/tests/builtins/alias.1.stderr1
-rw-r--r--bin/sh/tests/builtins/alias3.012
-rw-r--r--bin/sh/tests/builtins/alias3.0.stdout4
-rw-r--r--bin/sh/tests/builtins/alias4.04
-rw-r--r--bin/sh/tests/builtins/break1.016
-rw-r--r--bin/sh/tests/builtins/break2.012
-rw-r--r--bin/sh/tests/builtins/break2.0.stdout1
-rw-r--r--bin/sh/tests/builtins/break3.015
-rw-r--r--bin/sh/tests/builtins/break4.47
-rw-r--r--bin/sh/tests/builtins/break5.412
-rw-r--r--bin/sh/tests/builtins/break6.08
-rw-r--r--bin/sh/tests/builtins/builtin1.031
-rw-r--r--bin/sh/tests/builtins/case1.013
-rw-r--r--bin/sh/tests/builtins/case10.016
-rw-r--r--bin/sh/tests/builtins/case11.06
-rw-r--r--bin/sh/tests/builtins/case12.06
-rw-r--r--bin/sh/tests/builtins/case13.012
-rw-r--r--bin/sh/tests/builtins/case14.05
-rw-r--r--bin/sh/tests/builtins/case15.05
-rw-r--r--bin/sh/tests/builtins/case16.07
-rw-r--r--bin/sh/tests/builtins/case17.03
-rw-r--r--bin/sh/tests/builtins/case18.07
-rw-r--r--bin/sh/tests/builtins/case19.07
-rw-r--r--bin/sh/tests/builtins/case2.0106
-rw-r--r--bin/sh/tests/builtins/case20.09
-rw-r--r--bin/sh/tests/builtins/case21.010
-rw-r--r--bin/sh/tests/builtins/case22.010
-rw-r--r--bin/sh/tests/builtins/case23.05
-rw-r--r--bin/sh/tests/builtins/case3.095
-rw-r--r--bin/sh/tests/builtins/case4.06
-rw-r--r--bin/sh/tests/builtins/case5.057
-rw-r--r--bin/sh/tests/builtins/case6.052
-rw-r--r--bin/sh/tests/builtins/case7.024
-rw-r--r--bin/sh/tests/builtins/case8.032
-rw-r--r--bin/sh/tests/builtins/case9.039
-rw-r--r--bin/sh/tests/builtins/cd1.030
-rw-r--r--bin/sh/tests/builtins/cd10.06
-rw-r--r--bin/sh/tests/builtins/cd11.024
-rw-r--r--bin/sh/tests/builtins/cd2.016
-rw-r--r--bin/sh/tests/builtins/cd3.021
-rw-r--r--bin/sh/tests/builtins/cd4.038
-rw-r--r--bin/sh/tests/builtins/cd5.023
-rw-r--r--bin/sh/tests/builtins/cd6.010
-rw-r--r--bin/sh/tests/builtins/cd7.015
-rw-r--r--bin/sh/tests/builtins/cd8.026
-rw-r--r--bin/sh/tests/builtins/cd9.08
-rw-r--r--bin/sh/tests/builtins/cd9.0.stdout2
-rw-r--r--bin/sh/tests/builtins/command1.05
-rw-r--r--bin/sh/tests/builtins/command10.014
-rw-r--r--bin/sh/tests/builtins/command11.014
-rw-r--r--bin/sh/tests/builtins/command12.07
-rw-r--r--bin/sh/tests/builtins/command2.03
-rw-r--r--bin/sh/tests/builtins/command3.014
-rw-r--r--bin/sh/tests/builtins/command3.0.stdout7
-rw-r--r--bin/sh/tests/builtins/command4.02
-rw-r--r--bin/sh/tests/builtins/command5.015
-rw-r--r--bin/sh/tests/builtins/command5.0.stdout8
-rw-r--r--bin/sh/tests/builtins/command6.022
-rw-r--r--bin/sh/tests/builtins/command6.0.stdout7
-rw-r--r--bin/sh/tests/builtins/command7.034
-rw-r--r--bin/sh/tests/builtins/command8.045
-rw-r--r--bin/sh/tests/builtins/command9.014
-rw-r--r--bin/sh/tests/builtins/dot1.021
-rw-r--r--bin/sh/tests/builtins/dot2.021
-rw-r--r--bin/sh/tests/builtins/dot3.010
-rw-r--r--bin/sh/tests/builtins/dot4.012
-rw-r--r--bin/sh/tests/builtins/echo1.06
-rw-r--r--bin/sh/tests/builtins/echo2.07
-rw-r--r--bin/sh/tests/builtins/echo3.05
-rw-r--r--bin/sh/tests/builtins/eval1.09
-rw-r--r--bin/sh/tests/builtins/eval2.07
-rw-r--r--bin/sh/tests/builtins/eval3.09
-rw-r--r--bin/sh/tests/builtins/eval4.05
-rw-r--r--bin/sh/tests/builtins/eval5.04
-rw-r--r--bin/sh/tests/builtins/eval6.05
-rw-r--r--bin/sh/tests/builtins/eval7.09
-rw-r--r--bin/sh/tests/builtins/eval8.77
-rw-r--r--bin/sh/tests/builtins/exec1.025
-rw-r--r--bin/sh/tests/builtins/exec2.025
-rw-r--r--bin/sh/tests/builtins/exit1.06
-rw-r--r--bin/sh/tests/builtins/exit2.87
-rw-r--r--bin/sh/tests/builtins/exit3.05
-rw-r--r--bin/sh/tests/builtins/export1.03
-rw-r--r--bin/sh/tests/builtins/fc1.027
-rw-r--r--bin/sh/tests/builtins/fc2.034
-rw-r--r--bin/sh/tests/builtins/for1.04
-rw-r--r--bin/sh/tests/builtins/for2.09
-rw-r--r--bin/sh/tests/builtins/for3.08
-rw-r--r--bin/sh/tests/builtins/getopts1.025
-rw-r--r--bin/sh/tests/builtins/getopts1.0.stdout8
-rw-r--r--bin/sh/tests/builtins/getopts10.011
-rw-r--r--bin/sh/tests/builtins/getopts2.06
-rw-r--r--bin/sh/tests/builtins/getopts2.0.stdout1
-rw-r--r--bin/sh/tests/builtins/getopts3.06
-rw-r--r--bin/sh/tests/builtins/getopts4.010
-rw-r--r--bin/sh/tests/builtins/getopts5.010
-rw-r--r--bin/sh/tests/builtins/getopts6.07
-rw-r--r--bin/sh/tests/builtins/getopts7.06
-rw-r--r--bin/sh/tests/builtins/getopts8.08
-rw-r--r--bin/sh/tests/builtins/getopts8.0.stdout5
-rw-r--r--bin/sh/tests/builtins/getopts9.09
-rw-r--r--bin/sh/tests/builtins/getopts9.0.stdout3
-rw-r--r--bin/sh/tests/builtins/hash1.05
-rw-r--r--bin/sh/tests/builtins/hash1.0.stdout1
-rw-r--r--bin/sh/tests/builtins/hash2.04
-rw-r--r--bin/sh/tests/builtins/hash2.0.stdout1
-rw-r--r--bin/sh/tests/builtins/hash3.03
-rw-r--r--bin/sh/tests/builtins/hash3.0.stdout2
-rw-r--r--bin/sh/tests/builtins/hash4.06
-rw-r--r--bin/sh/tests/builtins/jobid1.07
-rw-r--r--bin/sh/tests/builtins/jobid2.09
-rw-r--r--bin/sh/tests/builtins/kill1.08
-rw-r--r--bin/sh/tests/builtins/kill2.07
-rw-r--r--bin/sh/tests/builtins/lineno.016
-rw-r--r--bin/sh/tests/builtins/lineno.0.stdout9
-rw-r--r--bin/sh/tests/builtins/lineno2.010
-rw-r--r--bin/sh/tests/builtins/lineno3.06
-rw-r--r--bin/sh/tests/builtins/lineno3.0.stdout2
-rw-r--r--bin/sh/tests/builtins/local1.013
-rw-r--r--bin/sh/tests/builtins/local2.017
-rw-r--r--bin/sh/tests/builtins/local3.026
-rw-r--r--bin/sh/tests/builtins/local4.012
-rw-r--r--bin/sh/tests/builtins/local5.015
-rw-r--r--bin/sh/tests/builtins/local6.010
-rw-r--r--bin/sh/tests/builtins/local7.010
-rw-r--r--bin/sh/tests/builtins/locale1.0134
-rw-r--r--bin/sh/tests/builtins/locale2.05
-rw-r--r--bin/sh/tests/builtins/printf1.03
-rw-r--r--bin/sh/tests/builtins/printf2.03
-rw-r--r--bin/sh/tests/builtins/printf3.05
-rw-r--r--bin/sh/tests/builtins/printf4.05
-rw-r--r--bin/sh/tests/builtins/read1.026
-rw-r--r--bin/sh/tests/builtins/read1.0.stdout20
-rw-r--r--bin/sh/tests/builtins/read2.031
-rw-r--r--bin/sh/tests/builtins/read3.011
-rw-r--r--bin/sh/tests/builtins/read3.0.stdout9
-rw-r--r--bin/sh/tests/builtins/read4.010
-rw-r--r--bin/sh/tests/builtins/read4.0.stdout8
-rw-r--r--bin/sh/tests/builtins/read5.032
-rw-r--r--bin/sh/tests/builtins/read6.05
-rw-r--r--bin/sh/tests/builtins/read7.05
-rw-r--r--bin/sh/tests/builtins/read8.017
-rw-r--r--bin/sh/tests/builtins/read9.010
-rw-r--r--bin/sh/tests/builtins/return1.07
-rw-r--r--bin/sh/tests/builtins/return2.17
-rw-r--r--bin/sh/tests/builtins/return3.13
-rw-r--r--bin/sh/tests/builtins/return4.016
-rw-r--r--bin/sh/tests/builtins/return5.017
-rw-r--r--bin/sh/tests/builtins/return6.43
-rw-r--r--bin/sh/tests/builtins/return7.46
-rw-r--r--bin/sh/tests/builtins/return8.013
-rw-r--r--bin/sh/tests/builtins/set1.032
-rw-r--r--bin/sh/tests/builtins/set2.03
-rw-r--r--bin/sh/tests/builtins/set3.04
-rw-r--r--bin/sh/tests/builtins/trap1.022
-rw-r--r--bin/sh/tests/builtins/trap10.06
-rw-r--r--bin/sh/tests/builtins/trap11.08
-rw-r--r--bin/sh/tests/builtins/trap12.010
-rw-r--r--bin/sh/tests/builtins/trap13.08
-rw-r--r--bin/sh/tests/builtins/trap14.010
-rw-r--r--bin/sh/tests/builtins/trap15.05
-rw-r--r--bin/sh/tests/builtins/trap16.020
-rw-r--r--bin/sh/tests/builtins/trap17.010
-rw-r--r--bin/sh/tests/builtins/trap2.052
-rw-r--r--bin/sh/tests/builtins/trap3.011
-rw-r--r--bin/sh/tests/builtins/trap4.017
-rw-r--r--bin/sh/tests/builtins/trap5.019
-rw-r--r--bin/sh/tests/builtins/trap6.09
-rw-r--r--bin/sh/tests/builtins/trap7.03
-rw-r--r--bin/sh/tests/builtins/trap8.07
-rw-r--r--bin/sh/tests/builtins/trap9.03
-rw-r--r--bin/sh/tests/builtins/type1.08
-rw-r--r--bin/sh/tests/builtins/type1.0.stderr4
-rw-r--r--bin/sh/tests/builtins/type2.026
-rw-r--r--bin/sh/tests/builtins/type3.03
-rw-r--r--bin/sh/tests/builtins/unalias.021
-rw-r--r--bin/sh/tests/builtins/var-assign.055
-rw-r--r--bin/sh/tests/builtins/var-assign2.055
-rw-r--r--bin/sh/tests/builtins/wait1.023
-rw-r--r--bin/sh/tests/builtins/wait10.05
-rw-r--r--bin/sh/tests/builtins/wait2.015
-rw-r--r--bin/sh/tests/builtins/wait3.021
-rw-r--r--bin/sh/tests/builtins/wait4.012
-rw-r--r--bin/sh/tests/builtins/wait5.012
-rw-r--r--bin/sh/tests/builtins/wait6.03
-rw-r--r--bin/sh/tests/builtins/wait7.04
-rw-r--r--bin/sh/tests/builtins/wait8.07
-rw-r--r--bin/sh/tests/builtins/wait9.1273
193 files changed, 2850 insertions, 0 deletions
diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile
new file mode 100644
index 000000000000..1cce8755a726
--- /dev/null
+++ b/bin/sh/tests/builtins/Makefile
@@ -0,0 +1,187 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/Makefile.depend b/bin/sh/tests/builtins/Makefile.depend
new file mode 100644
index 000000000000..f80275d86ab1
--- /dev/null
+++ b/bin/sh/tests/builtins/Makefile.depend
@@ -0,0 +1,11 @@
+# $FreeBSD$
+# 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/sh/tests/builtins/alias.0 b/bin/sh/tests/builtins/alias.0
new file mode 100644
index 000000000000..d9b27969cfd6
--- /dev/null
+++ b/bin/sh/tests/builtins/alias.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+set -e
+
+unalias -a
+alias foo=bar
+alias bar=
+alias quux="1 2 3"
+alias
+alias foo
diff --git a/bin/sh/tests/builtins/alias.0.stdout b/bin/sh/tests/builtins/alias.0.stdout
new file mode 100644
index 000000000000..52efaf0b72e7
--- /dev/null
+++ b/bin/sh/tests/builtins/alias.0.stdout
@@ -0,0 +1,4 @@
+bar=''
+foo=bar
+quux='1 2 3'
+foo=bar
diff --git a/bin/sh/tests/builtins/alias.1 b/bin/sh/tests/builtins/alias.1
new file mode 100644
index 000000000000..31403dc760bf
--- /dev/null
+++ b/bin/sh/tests/builtins/alias.1
@@ -0,0 +1,3 @@
+# $FreeBSD$
+unalias -a
+alias foo
diff --git a/bin/sh/tests/builtins/alias.1.stderr b/bin/sh/tests/builtins/alias.1.stderr
new file mode 100644
index 000000000000..c9f4011bea00
--- /dev/null
+++ b/bin/sh/tests/builtins/alias.1.stderr
@@ -0,0 +1 @@
+alias: foo: not found
diff --git a/bin/sh/tests/builtins/alias3.0 b/bin/sh/tests/builtins/alias3.0
new file mode 100644
index 000000000000..fe65e31f5f03
--- /dev/null
+++ b/bin/sh/tests/builtins/alias3.0
@@ -0,0 +1,12 @@
+# $FreeBSD$
+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/sh/tests/builtins/alias3.0.stdout b/bin/sh/tests/builtins/alias3.0.stdout
new file mode 100644
index 000000000000..52efaf0b72e7
--- /dev/null
+++ b/bin/sh/tests/builtins/alias3.0.stdout
@@ -0,0 +1,4 @@
+bar=''
+foo=bar
+quux='1 2 3'
+foo=bar
diff --git a/bin/sh/tests/builtins/alias4.0 b/bin/sh/tests/builtins/alias4.0
new file mode 100644
index 000000000000..3d5efeccf2c7
--- /dev/null
+++ b/bin/sh/tests/builtins/alias4.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+unalias -a
+alias --
diff --git a/bin/sh/tests/builtins/break1.0 b/bin/sh/tests/builtins/break1.0
new file mode 100644
index 000000000000..ba0cbb4bd268
--- /dev/null
+++ b/bin/sh/tests/builtins/break1.0
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/break2.0 b/bin/sh/tests/builtins/break2.0
new file mode 100644
index 000000000000..ff52dd321469
--- /dev/null
+++ b/bin/sh/tests/builtins/break2.0
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/break2.0.stdout b/bin/sh/tests/builtins/break2.0.stdout
new file mode 100644
index 000000000000..12799ccbe7ce
--- /dev/null
+++ b/bin/sh/tests/builtins/break2.0.stdout
@@ -0,0 +1 @@
+good
diff --git a/bin/sh/tests/builtins/break3.0 b/bin/sh/tests/builtins/break3.0
new file mode 100644
index 000000000000..10a5ca88edff
--- /dev/null
+++ b/bin/sh/tests/builtins/break3.0
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/break4.4 b/bin/sh/tests/builtins/break4.4
new file mode 100644
index 000000000000..d52ff52be4d4
--- /dev/null
+++ b/bin/sh/tests/builtins/break4.4
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/break5.4 b/bin/sh/tests/builtins/break5.4
new file mode 100644
index 000000000000..7df8e186311c
--- /dev/null
+++ b/bin/sh/tests/builtins/break5.4
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/break6.0 b/bin/sh/tests/builtins/break6.0
new file mode 100644
index 000000000000..09fc0d85eaa3
--- /dev/null
+++ b/bin/sh/tests/builtins/break6.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+# Per POSIX, this need only work if LONG_MAX > 4294967295.
+
+while :; do
+ break 4294967296
+ echo bad
+ exit 3
+done
diff --git a/bin/sh/tests/builtins/builtin1.0 b/bin/sh/tests/builtins/builtin1.0
new file mode 100644
index 000000000000..b6083858f671
--- /dev/null
+++ b/bin/sh/tests/builtins/builtin1.0
@@ -0,0 +1,31 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/case1.0 b/bin/sh/tests/builtins/case1.0
new file mode 100644
index 000000000000..860fc67dacda
--- /dev/null
+++ b/bin/sh/tests/builtins/case1.0
@@ -0,0 +1,13 @@
+#$FreeBSD$
+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/sh/tests/builtins/case10.0 b/bin/sh/tests/builtins/case10.0
new file mode 100644
index 000000000000..a627b5cd996f
--- /dev/null
+++ b/bin/sh/tests/builtins/case10.0
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/case11.0 b/bin/sh/tests/builtins/case11.0
new file mode 100644
index 000000000000..0e66e11f0dee
--- /dev/null
+++ b/bin/sh/tests/builtins/case11.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+false
+case x in
+*)
+esac
diff --git a/bin/sh/tests/builtins/case12.0 b/bin/sh/tests/builtins/case12.0
new file mode 100644
index 000000000000..2a442ba7993a
--- /dev/null
+++ b/bin/sh/tests/builtins/case12.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+false
+case x in
+y)
+esac
diff --git a/bin/sh/tests/builtins/case13.0 b/bin/sh/tests/builtins/case13.0
new file mode 100644
index 000000000000..78f4e9bdffde
--- /dev/null
+++ b/bin/sh/tests/builtins/case13.0
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+case ^ in
+[\^^]) ;;
+*) echo Failed at $LINENO ;;
+esac
+
+case s in
+[\^^]) echo Failed at $LINENO ;;
+[s\]]) ;;
+*) echo Failed at $LINENO ;;
+esac
diff --git a/bin/sh/tests/builtins/case14.0 b/bin/sh/tests/builtins/case14.0
new file mode 100644
index 000000000000..0338e8a224e3
--- /dev/null
+++ b/bin/sh/tests/builtins/case14.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+case `false` in
+no) exit 3 ;;
+esac
diff --git a/bin/sh/tests/builtins/case15.0 b/bin/sh/tests/builtins/case15.0
new file mode 100644
index 000000000000..09b0e1133544
--- /dev/null
+++ b/bin/sh/tests/builtins/case15.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+case x in
+`false`) exit 3 ;;
+esac
diff --git a/bin/sh/tests/builtins/case16.0 b/bin/sh/tests/builtins/case16.0
new file mode 100644
index 000000000000..24303027ba91
--- /dev/null
+++ b/bin/sh/tests/builtins/case16.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+f() { return 42; }
+f
+case x in
+x) [ $? = 42 ] ;;
+esac
diff --git a/bin/sh/tests/builtins/case17.0 b/bin/sh/tests/builtins/case17.0
new file mode 100644
index 000000000000..ed1d25f0277a
--- /dev/null
+++ b/bin/sh/tests/builtins/case17.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+! case x in x) false ;& y) esac
diff --git a/bin/sh/tests/builtins/case18.0 b/bin/sh/tests/builtins/case18.0
new file mode 100644
index 000000000000..470253f622ea
--- /dev/null
+++ b/bin/sh/tests/builtins/case18.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+case x$(false) in
+x) ;&
+y) [ $? != 0 ] ;;
+z) false ;;
+esac
diff --git a/bin/sh/tests/builtins/case19.0 b/bin/sh/tests/builtins/case19.0
new file mode 100644
index 000000000000..215066ad6321
--- /dev/null
+++ b/bin/sh/tests/builtins/case19.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+[ "`case x in
+x) false ;&
+y) ;&
+z) echo $? ;;
+esac`" != 0 ]
diff --git a/bin/sh/tests/builtins/case2.0 b/bin/sh/tests/builtins/case2.0
new file mode 100644
index 000000000000..e319148cdf5d
--- /dev/null
+++ b/bin/sh/tests/builtins/case2.0
@@ -0,0 +1,106 @@
+# Generated by ./test-fnmatch -s 1, do not edit.
+# $FreeBSD$
+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/sh/tests/builtins/case20.0 b/bin/sh/tests/builtins/case20.0
new file mode 100644
index 000000000000..03a4eb2c9a23
--- /dev/null
+++ b/bin/sh/tests/builtins/case20.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/case21.0 b/bin/sh/tests/builtins/case21.0
new file mode 100644
index 000000000000..ea7fb054a546
--- /dev/null
+++ b/bin/sh/tests/builtins/case21.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+case 5 in
+[0$((-9))]) ;;
+*) echo bad1 ;;
+esac
+
+case - in
+[0$((-9))]) echo bad2 ;;
+esac
diff --git a/bin/sh/tests/builtins/case22.0 b/bin/sh/tests/builtins/case22.0
new file mode 100644
index 000000000000..ddc80051fa0a
--- /dev/null
+++ b/bin/sh/tests/builtins/case22.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+case 5 in
+[0"$((-9))"]) echo bad1 ;;
+esac
+
+case - in
+[0"$((-9))"]) ;;
+*) echo bad2 ;;
+esac
diff --git a/bin/sh/tests/builtins/case23.0 b/bin/sh/tests/builtins/case23.0
new file mode 100644
index 000000000000..ce03cf96d62e
--- /dev/null
+++ b/bin/sh/tests/builtins/case23.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+case [ in
+[[:alpha:]]) echo bad
+esac
diff --git a/bin/sh/tests/builtins/case3.0 b/bin/sh/tests/builtins/case3.0
new file mode 100644
index 000000000000..42e53d62a3cb
--- /dev/null
+++ b/bin/sh/tests/builtins/case3.0
@@ -0,0 +1,95 @@
+# Generated by ./test-fnmatch -s 2, do not edit.
+# $FreeBSD$
+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/sh/tests/builtins/case4.0 b/bin/sh/tests/builtins/case4.0
new file mode 100644
index 000000000000..18219f51ee09
--- /dev/null
+++ b/bin/sh/tests/builtins/case4.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -- "*"
+case x in
+"$1") echo failed ;;
+esac
diff --git a/bin/sh/tests/builtins/case5.0 b/bin/sh/tests/builtins/case5.0
new file mode 100644
index 000000000000..8c6db5ab8e57
--- /dev/null
+++ b/bin/sh/tests/builtins/case5.0
@@ -0,0 +1,57 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/case6.0 b/bin/sh/tests/builtins/case6.0
new file mode 100644
index 000000000000..8d791831c3d8
--- /dev/null
+++ b/bin/sh/tests/builtins/case6.0
@@ -0,0 +1,52 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/case7.0 b/bin/sh/tests/builtins/case7.0
new file mode 100644
index 000000000000..96b9de66fe27
--- /dev/null
+++ b/bin/sh/tests/builtins/case7.0
@@ -0,0 +1,24 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/case8.0 b/bin/sh/tests/builtins/case8.0
new file mode 100644
index 000000000000..8d9f8b604d88
--- /dev/null
+++ b/bin/sh/tests/builtins/case8.0
@@ -0,0 +1,32 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/case9.0 b/bin/sh/tests/builtins/case9.0
new file mode 100644
index 000000000000..476caec261ba
--- /dev/null
+++ b/bin/sh/tests/builtins/case9.0
@@ -0,0 +1,39 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/cd1.0 b/bin/sh/tests/builtins/cd1.0
new file mode 100644
index 000000000000..bc5108e6be3b
--- /dev/null
+++ b/bin/sh/tests/builtins/cd1.0
@@ -0,0 +1,30 @@
+# $FreeBSD$
+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/sh/tests/builtins/cd10.0 b/bin/sh/tests/builtins/cd10.0
new file mode 100644
index 000000000000..f4b5e0ffca5c
--- /dev/null
+++ b/bin/sh/tests/builtins/cd10.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+# Precondition
+(cd /bin) || exit
+# Verify write error is ignored.
+$SH +m -ic 'CDPATH=/:; cd bin 1</dev/null'
diff --git a/bin/sh/tests/builtins/cd11.0 b/bin/sh/tests/builtins/cd11.0
new file mode 100644
index 000000000000..53e63f736f30
--- /dev/null
+++ b/bin/sh/tests/builtins/cd11.0
@@ -0,0 +1,24 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/cd2.0 b/bin/sh/tests/builtins/cd2.0
new file mode 100644
index 000000000000..f2b6416a12ec
--- /dev/null
+++ b/bin/sh/tests/builtins/cd2.0
@@ -0,0 +1,16 @@
+# $FreeBSD$
+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/sh/tests/builtins/cd3.0 b/bin/sh/tests/builtins/cd3.0
new file mode 100644
index 000000000000..7729c54a6895
--- /dev/null
+++ b/bin/sh/tests/builtins/cd3.0
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/cd4.0 b/bin/sh/tests/builtins/cd4.0
new file mode 100644
index 000000000000..df3a9a48961c
--- /dev/null
+++ b/bin/sh/tests/builtins/cd4.0
@@ -0,0 +1,38 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/cd5.0 b/bin/sh/tests/builtins/cd5.0
new file mode 100644
index 000000000000..3dff604583c9
--- /dev/null
+++ b/bin/sh/tests/builtins/cd5.0
@@ -0,0 +1,23 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/cd6.0 b/bin/sh/tests/builtins/cd6.0
new file mode 100644
index 000000000000..083a06190e64
--- /dev/null
+++ b/bin/sh/tests/builtins/cd6.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+set -e
+cd -P /bin
+d=$PWD
+CDPATH=/:
+cd -P .
+[ "$d" = "$PWD" ]
+cd -P ./
+[ "$d" = "$PWD" ]
diff --git a/bin/sh/tests/builtins/cd7.0 b/bin/sh/tests/builtins/cd7.0
new file mode 100644
index 000000000000..9adda86c1aed
--- /dev/null
+++ b/bin/sh/tests/builtins/cd7.0
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/cd8.0 b/bin/sh/tests/builtins/cd8.0
new file mode 100644
index 000000000000..a68f77f26f75
--- /dev/null
+++ b/bin/sh/tests/builtins/cd8.0
@@ -0,0 +1,26 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/cd9.0 b/bin/sh/tests/builtins/cd9.0
new file mode 100644
index 000000000000..78bcdff9a933
--- /dev/null
+++ b/bin/sh/tests/builtins/cd9.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+cd /dev
+cd /bin
+cd - >/dev/null
+pwd
+cd - >/dev/null
+pwd
diff --git a/bin/sh/tests/builtins/cd9.0.stdout b/bin/sh/tests/builtins/cd9.0.stdout
new file mode 100644
index 000000000000..dac16a768d5e
--- /dev/null
+++ b/bin/sh/tests/builtins/cd9.0.stdout
@@ -0,0 +1,2 @@
+/dev
+/bin
diff --git a/bin/sh/tests/builtins/command1.0 b/bin/sh/tests/builtins/command1.0
new file mode 100644
index 000000000000..fd0afdfa0300
--- /dev/null
+++ b/bin/sh/tests/builtins/command1.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+true() {
+ false
+}
+command true
diff --git a/bin/sh/tests/builtins/command10.0 b/bin/sh/tests/builtins/command10.0
new file mode 100644
index 000000000000..2c1adf1eb0bd
--- /dev/null
+++ b/bin/sh/tests/builtins/command10.0
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/command11.0 b/bin/sh/tests/builtins/command11.0
new file mode 100644
index 000000000000..10c86479d81b
--- /dev/null
+++ b/bin/sh/tests/builtins/command11.0
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/command12.0 b/bin/sh/tests/builtins/command12.0
new file mode 100644
index 000000000000..f981db324946
--- /dev/null
+++ b/bin/sh/tests/builtins/command12.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+alias aa=echo\ \'\"\'
+cmd=$(command -v aa)
+alias aa=echo\ bad
+eval "$cmd"
+[ "$(eval aa)" = \" ]
diff --git a/bin/sh/tests/builtins/command2.0 b/bin/sh/tests/builtins/command2.0
new file mode 100644
index 000000000000..ff7b5f2c8dc8
--- /dev/null
+++ b/bin/sh/tests/builtins/command2.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+PATH=
+command -p cat < /dev/null
diff --git a/bin/sh/tests/builtins/command3.0 b/bin/sh/tests/builtins/command3.0
new file mode 100644
index 000000000000..9d4ae89e0e2e
--- /dev/null
+++ b/bin/sh/tests/builtins/command3.0
@@ -0,0 +1,14 @@
+# $FreeBSD$
+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/sh/tests/builtins/command3.0.stdout b/bin/sh/tests/builtins/command3.0.stdout
new file mode 100644
index 000000000000..67b869156a75
--- /dev/null
+++ b/bin/sh/tests/builtins/command3.0.stdout
@@ -0,0 +1,7 @@
+/bin/ls
+true
+/bin/ls
+fun
+break
+if
+alias foo=bar
diff --git a/bin/sh/tests/builtins/command4.0 b/bin/sh/tests/builtins/command4.0
new file mode 100644
index 000000000000..3e496137ff58
--- /dev/null
+++ b/bin/sh/tests/builtins/command4.0
@@ -0,0 +1,2 @@
+# $FreeBSD$
+! command -v nonexisting
diff --git a/bin/sh/tests/builtins/command5.0 b/bin/sh/tests/builtins/command5.0
new file mode 100644
index 000000000000..13b3fe1fe3f4
--- /dev/null
+++ b/bin/sh/tests/builtins/command5.0
@@ -0,0 +1,15 @@
+# $FreeBSD$
+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/sh/tests/builtins/command5.0.stdout b/bin/sh/tests/builtins/command5.0.stdout
new file mode 100644
index 000000000000..523f7b22a187
--- /dev/null
+++ b/bin/sh/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/sh/tests/builtins/command6.0 b/bin/sh/tests/builtins/command6.0
new file mode 100644
index 000000000000..5b63bfecc0f0
--- /dev/null
+++ b/bin/sh/tests/builtins/command6.0
@@ -0,0 +1,22 @@
+# $FreeBSD$
+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/sh/tests/builtins/command6.0.stdout b/bin/sh/tests/builtins/command6.0.stdout
new file mode 100644
index 000000000000..3180207a4e2b
--- /dev/null
+++ b/bin/sh/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/sh/tests/builtins/command7.0 b/bin/sh/tests/builtins/command7.0
new file mode 100644
index 000000000000..fc652f207584
--- /dev/null
+++ b/bin/sh/tests/builtins/command7.0
@@ -0,0 +1,34 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/command8.0 b/bin/sh/tests/builtins/command8.0
new file mode 100644
index 000000000000..9e3a2b645fbb
--- /dev/null
+++ b/bin/sh/tests/builtins/command8.0
@@ -0,0 +1,45 @@
+# $FreeBSD$
+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/sh/tests/builtins/command9.0 b/bin/sh/tests/builtins/command9.0
new file mode 100644
index 000000000000..212e52aafc98
--- /dev/null
+++ b/bin/sh/tests/builtins/command9.0
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/dot1.0 b/bin/sh/tests/builtins/dot1.0
new file mode 100644
index 000000000000..43eab0ddeb33
--- /dev/null
+++ b/bin/sh/tests/builtins/dot1.0
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+failures=
+failure() {
+ echo "Error at line $1" >&2
+ failures=x$failures
+}
+
+T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) || 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/sh/tests/builtins/dot2.0 b/bin/sh/tests/builtins/dot2.0
new file mode 100644
index 000000000000..ed6379b993c3
--- /dev/null
+++ b/bin/sh/tests/builtins/dot2.0
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+failures=
+failure() {
+ echo "Error at line $1" >&2
+ failures=x$failures
+}
+
+T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) || 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/sh/tests/builtins/dot3.0 b/bin/sh/tests/builtins/dot3.0
new file mode 100644
index 000000000000..b337f0f6d338
--- /dev/null
+++ b/bin/sh/tests/builtins/dot3.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+# . should return 0 if no command was executed.
+
+if false; then
+ exit 3
+else
+ . /dev/null
+ exit $?
+fi
diff --git a/bin/sh/tests/builtins/dot4.0 b/bin/sh/tests/builtins/dot4.0
new file mode 100644
index 000000000000..b898131c0e1c
--- /dev/null
+++ b/bin/sh/tests/builtins/dot4.0
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/echo1.0 b/bin/sh/tests/builtins/echo1.0
new file mode 100644
index 000000000000..75ed8fbbc45f
--- /dev/null
+++ b/bin/sh/tests/builtins/echo1.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+# Not specified by POSIX.
+
+[ "`echo -n a b; echo c d; echo e f`" = "a bc d
+e f" ]
diff --git a/bin/sh/tests/builtins/echo2.0 b/bin/sh/tests/builtins/echo2.0
new file mode 100644
index 000000000000..254b5c4dca4f
--- /dev/null
+++ b/bin/sh/tests/builtins/echo2.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/echo3.0 b/bin/sh/tests/builtins/echo3.0
new file mode 100644
index 000000000000..ff8f6c2f26e4
--- /dev/null
+++ b/bin/sh/tests/builtins/echo3.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+# Not specified by POSIX.
+
+[ "`echo -e 'a\cb' c; echo d`" = "ad" ]
diff --git a/bin/sh/tests/builtins/eval1.0 b/bin/sh/tests/builtins/eval1.0
new file mode 100644
index 000000000000..04606a4a87fe
--- /dev/null
+++ b/bin/sh/tests/builtins/eval1.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+set -e
+
+eval
+eval "" ""
+eval "true"
+! eval "false
+
+"
diff --git a/bin/sh/tests/builtins/eval2.0 b/bin/sh/tests/builtins/eval2.0
new file mode 100644
index 000000000000..bf06b6e14e0c
--- /dev/null
+++ b/bin/sh/tests/builtins/eval2.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+eval '
+false
+
+' && exit 1
+exit 0
diff --git a/bin/sh/tests/builtins/eval3.0 b/bin/sh/tests/builtins/eval3.0
new file mode 100644
index 000000000000..dfb8357c727c
--- /dev/null
+++ b/bin/sh/tests/builtins/eval3.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+eval 'false;' && exit 1
+eval 'true;' || exit 1
+eval 'false;
+' && exit 1
+eval 'true;
+' || exit 1
+exit 0
diff --git a/bin/sh/tests/builtins/eval4.0 b/bin/sh/tests/builtins/eval4.0
new file mode 100644
index 000000000000..67da2f5c832d
--- /dev/null
+++ b/bin/sh/tests/builtins/eval4.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+# eval should preserve $? from command substitutions when starting
+# the parsed command.
+[ $(eval 'echo $?' $(false)) = 1 ]
diff --git a/bin/sh/tests/builtins/eval5.0 b/bin/sh/tests/builtins/eval5.0
new file mode 100644
index 000000000000..3e86de92fbae
--- /dev/null
+++ b/bin/sh/tests/builtins/eval5.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+# eval should return 0 if no command was executed.
+eval $(false)
diff --git a/bin/sh/tests/builtins/eval6.0 b/bin/sh/tests/builtins/eval6.0
new file mode 100644
index 000000000000..6752bb65ad4d
--- /dev/null
+++ b/bin/sh/tests/builtins/eval6.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+# eval should preserve $? from command substitutions when starting
+# the parsed command.
+[ $(false; eval 'echo $?' $(:)) = 0 ]
diff --git a/bin/sh/tests/builtins/eval7.0 b/bin/sh/tests/builtins/eval7.0
new file mode 100644
index 000000000000..a309c917b102
--- /dev/null
+++ b/bin/sh/tests/builtins/eval7.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+# 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/sh/tests/builtins/eval8.7 b/bin/sh/tests/builtins/eval8.7
new file mode 100644
index 000000000000..af6064c388df
--- /dev/null
+++ b/bin/sh/tests/builtins/eval8.7
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+f() {
+ eval "return 7
+echo bad2"
+}
+f
diff --git a/bin/sh/tests/builtins/exec1.0 b/bin/sh/tests/builtins/exec1.0
new file mode 100644
index 000000000000..dd30a4c9aa93
--- /dev/null
+++ b/bin/sh/tests/builtins/exec1.0
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/exec2.0 b/bin/sh/tests/builtins/exec2.0
new file mode 100644
index 000000000000..3dcb6c41156a
--- /dev/null
+++ b/bin/sh/tests/builtins/exec2.0
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/exit1.0 b/bin/sh/tests/builtins/exit1.0
new file mode 100644
index 000000000000..496d448761cc
--- /dev/null
+++ b/bin/sh/tests/builtins/exit1.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+# exit with an argument should overwrite the exit status in an EXIT trap.
+
+trap 'true; exit $?' 0
+false
diff --git a/bin/sh/tests/builtins/exit2.8 b/bin/sh/tests/builtins/exit2.8
new file mode 100644
index 000000000000..124c32e01a3c
--- /dev/null
+++ b/bin/sh/tests/builtins/exit2.8
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+# exit without arguments is the same as exit $? outside a trap.
+
+trap 'true; true' 0
+(exit 8)
+exit
diff --git a/bin/sh/tests/builtins/exit3.0 b/bin/sh/tests/builtins/exit3.0
new file mode 100644
index 000000000000..80655ac539c5
--- /dev/null
+++ b/bin/sh/tests/builtins/exit3.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+# exit without arguments differs from exit $? in an EXIT trap.
+
+trap 'false; exit' 0
diff --git a/bin/sh/tests/builtins/export1.0 b/bin/sh/tests/builtins/export1.0
new file mode 100644
index 000000000000..7b08c9de4349
--- /dev/null
+++ b/bin/sh/tests/builtins/export1.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+env @badness=1 ${SH} -c 'v=`export -p`; eval "$v"'
diff --git a/bin/sh/tests/builtins/fc1.0 b/bin/sh/tests/builtins/fc1.0
new file mode 100644
index 000000000000..ab7a387b5077
--- /dev/null
+++ b/bin/sh/tests/builtins/fc1.0
@@ -0,0 +1,27 @@
+# $FreeBSD$
+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/sh/tests/builtins/fc2.0 b/bin/sh/tests/builtins/fc2.0
new file mode 100644
index 000000000000..7eb92acc2cdf
--- /dev/null
+++ b/bin/sh/tests/builtins/fc2.0
@@ -0,0 +1,34 @@
+# $FreeBSD$
+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/sh/tests/builtins/for1.0 b/bin/sh/tests/builtins/for1.0
new file mode 100644
index 000000000000..cd55e2ca029e
--- /dev/null
+++ b/bin/sh/tests/builtins/for1.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+false
+for i in `false`; do exit 3; done
diff --git a/bin/sh/tests/builtins/for2.0 b/bin/sh/tests/builtins/for2.0
new file mode 100644
index 000000000000..48c22ce71119
--- /dev/null
+++ b/bin/sh/tests/builtins/for2.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+r=x
+f() { return 42; }
+f
+for i in x; do
+ r=$?
+done
+[ "$r" = 42 ]
diff --git a/bin/sh/tests/builtins/for3.0 b/bin/sh/tests/builtins/for3.0
new file mode 100644
index 000000000000..cc37238abbc6
--- /dev/null
+++ b/bin/sh/tests/builtins/for3.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+r=x
+f() { return 42; }
+for i in x`f`; do
+ r=$?
+done
+[ "$r" = 42 ]
diff --git a/bin/sh/tests/builtins/getopts1.0 b/bin/sh/tests/builtins/getopts1.0
new file mode 100644
index 000000000000..10d2b59208e5
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts1.0
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/getopts1.0.stdout b/bin/sh/tests/builtins/getopts1.0.stdout
new file mode 100644
index 000000000000..a0a347eea8f8
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts1.0.stdout
@@ -0,0 +1,8 @@
+-1-
+a
+-2-
+a
+No arg for -b option
+?
+-3-
+?
diff --git a/bin/sh/tests/builtins/getopts10.0 b/bin/sh/tests/builtins/getopts10.0
new file mode 100644
index 000000000000..a88e6ca3e85e
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts10.0
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/getopts2.0 b/bin/sh/tests/builtins/getopts2.0
new file mode 100644
index 000000000000..1bd2c32db81c
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts2.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+set - -ax
+getopts ax option
+set -C
+getopts ax option
+printf '%s\n' "$option"
diff --git a/bin/sh/tests/builtins/getopts2.0.stdout b/bin/sh/tests/builtins/getopts2.0.stdout
new file mode 100644
index 000000000000..587be6b4c3f9
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts2.0.stdout
@@ -0,0 +1 @@
+x
diff --git a/bin/sh/tests/builtins/getopts3.0 b/bin/sh/tests/builtins/getopts3.0
new file mode 100644
index 000000000000..d02469b20469
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts3.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+shift $#
+getopts x opt
+r=$?
+[ "$r" != 0 ] && [ "$OPTIND" = 1 ]
diff --git a/bin/sh/tests/builtins/getopts4.0 b/bin/sh/tests/builtins/getopts4.0
new file mode 100644
index 000000000000..61d5c2b6b15c
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts4.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/getopts5.0 b/bin/sh/tests/builtins/getopts5.0
new file mode 100644
index 000000000000..666ee7652de5
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts5.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/getopts6.0 b/bin/sh/tests/builtins/getopts6.0
new file mode 100644
index 000000000000..1d3c39ba953e
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts6.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+set -- -x -y
+getopts :x var || echo "First getopts bad: $?"
+getopts :x var
+r=$?
+[ r != 0 ] && [ "$OPTIND" = 3 ]
diff --git a/bin/sh/tests/builtins/getopts7.0 b/bin/sh/tests/builtins/getopts7.0
new file mode 100644
index 000000000000..3745555f8c1a
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts7.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -- -x
+getopts :x: var
+r=$?
+[ r != 0 ] && [ "$OPTIND" = 2 ]
diff --git a/bin/sh/tests/builtins/getopts8.0 b/bin/sh/tests/builtins/getopts8.0
new file mode 100644
index 000000000000..da4af6bd0b56
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts8.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+set -- -yz -wx
+opt=wrong1 OPTARG=wrong2
+while getopts :x opt; do
+ echo "$opt:${OPTARG-unset}"
+done
+echo "OPTIND=$OPTIND"
diff --git a/bin/sh/tests/builtins/getopts8.0.stdout b/bin/sh/tests/builtins/getopts8.0.stdout
new file mode 100644
index 000000000000..f10cefcd8c1b
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts8.0.stdout
@@ -0,0 +1,5 @@
+?:y
+?:z
+?:w
+x:unset
+OPTIND=3
diff --git a/bin/sh/tests/builtins/getopts9.0 b/bin/sh/tests/builtins/getopts9.0
new file mode 100644
index 000000000000..1c35fc68c2d1
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts9.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/getopts9.0.stdout b/bin/sh/tests/builtins/getopts9.0.stdout
new file mode 100644
index 000000000000..4d32063faa4d
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts9.0.stdout
@@ -0,0 +1,3 @@
+0:a:
+0:b:
+1:?:
diff --git a/bin/sh/tests/builtins/hash1.0 b/bin/sh/tests/builtins/hash1.0
new file mode 100644
index 000000000000..45cc3003fb59
--- /dev/null
+++ b/bin/sh/tests/builtins/hash1.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+cat /dev/null
+hash
+hash -r
+hash
diff --git a/bin/sh/tests/builtins/hash1.0.stdout b/bin/sh/tests/builtins/hash1.0.stdout
new file mode 100644
index 000000000000..3afc3e7b3839
--- /dev/null
+++ b/bin/sh/tests/builtins/hash1.0.stdout
@@ -0,0 +1 @@
+/bin/cat
diff --git a/bin/sh/tests/builtins/hash2.0 b/bin/sh/tests/builtins/hash2.0
new file mode 100644
index 000000000000..e5cd21bc57dd
--- /dev/null
+++ b/bin/sh/tests/builtins/hash2.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+hash
+hash cat
+hash
diff --git a/bin/sh/tests/builtins/hash2.0.stdout b/bin/sh/tests/builtins/hash2.0.stdout
new file mode 100644
index 000000000000..3afc3e7b3839
--- /dev/null
+++ b/bin/sh/tests/builtins/hash2.0.stdout
@@ -0,0 +1 @@
+/bin/cat
diff --git a/bin/sh/tests/builtins/hash3.0 b/bin/sh/tests/builtins/hash3.0
new file mode 100644
index 000000000000..eade0b319546
--- /dev/null
+++ b/bin/sh/tests/builtins/hash3.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+hash -v cat
+hash
diff --git a/bin/sh/tests/builtins/hash3.0.stdout b/bin/sh/tests/builtins/hash3.0.stdout
new file mode 100644
index 000000000000..a34864cd6dff
--- /dev/null
+++ b/bin/sh/tests/builtins/hash3.0.stdout
@@ -0,0 +1,2 @@
+/bin/cat
+/bin/cat
diff --git a/bin/sh/tests/builtins/hash4.0 b/bin/sh/tests/builtins/hash4.0
new file mode 100644
index 000000000000..dec584c4538f
--- /dev/null
+++ b/bin/sh/tests/builtins/hash4.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+exec 3>&1
+m=`hash nosuchtool 2>&1 >&3`
+r=$?
+[ "$r" != 0 ] && [ -n "$m" ]
diff --git a/bin/sh/tests/builtins/jobid1.0 b/bin/sh/tests/builtins/jobid1.0
new file mode 100644
index 000000000000..483fda20743c
--- /dev/null
+++ b/bin/sh/tests/builtins/jobid1.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+# Non-standard builtin.
+
+: &
+p1=$!
+p2=$(jobid)
+[ "${p1:?}" = "${p2:?}" ]
diff --git a/bin/sh/tests/builtins/jobid2.0 b/bin/sh/tests/builtins/jobid2.0
new file mode 100644
index 000000000000..101831a2e4b8
--- /dev/null
+++ b/bin/sh/tests/builtins/jobid2.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+: &
+p1=$(jobid)
+p2=$(jobid --)
+p3=$(jobid %+)
+p4=$(jobid -- %+)
+[ "${p1:?}" = "${p2:?}" ] && [ "${p2:?}" = "${p3:?}" ] &&
+[ "${p3:?}" = "${p4:?}" ] && [ "${p4:?}" = "${p1:?}" ]
diff --git a/bin/sh/tests/builtins/kill1.0 b/bin/sh/tests/builtins/kill1.0
new file mode 100644
index 000000000000..c1b85503848e
--- /dev/null
+++ b/bin/sh/tests/builtins/kill1.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+: &
+p1=$!
+: &
+p2=$!
+wait $p2
+kill %1
diff --git a/bin/sh/tests/builtins/kill2.0 b/bin/sh/tests/builtins/kill2.0
new file mode 100644
index 000000000000..31e0ba362b80
--- /dev/null
+++ b/bin/sh/tests/builtins/kill2.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+sleep 1 | sleep 1 &
+kill %+
+wait "$!"
+r=$?
+[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = TERM ]
diff --git a/bin/sh/tests/builtins/lineno.0 b/bin/sh/tests/builtins/lineno.0
new file mode 100644
index 000000000000..c9311f82d253
--- /dev/null
+++ b/bin/sh/tests/builtins/lineno.0
@@ -0,0 +1,16 @@
+# $FreeBSD$
+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/sh/tests/builtins/lineno.0.stdout b/bin/sh/tests/builtins/lineno.0.stdout
new file mode 100644
index 000000000000..82583a93c82e
--- /dev/null
+++ b/bin/sh/tests/builtins/lineno.0.stdout
@@ -0,0 +1,9 @@
+2
+3
+2
+3
+12
+13
+foo
+foo
+2
diff --git a/bin/sh/tests/builtins/lineno2.0 b/bin/sh/tests/builtins/lineno2.0
new file mode 100644
index 000000000000..ddbd10433a36
--- /dev/null
+++ b/bin/sh/tests/builtins/lineno2.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+f() {
+ : ${LINENO+${x?}}
+}
+
+unset -v x
+command eval f 2>/dev/null && exit 3
+x=1
+f
diff --git a/bin/sh/tests/builtins/lineno3.0 b/bin/sh/tests/builtins/lineno3.0
new file mode 100644
index 000000000000..eb8f9ab7db94
--- /dev/null
+++ b/bin/sh/tests/builtins/lineno3.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+echo before: $LINENO
+dummy=$'a\0
+'
+echo after: $LINENO
diff --git a/bin/sh/tests/builtins/lineno3.0.stdout b/bin/sh/tests/builtins/lineno3.0.stdout
new file mode 100644
index 000000000000..6e0e4ac8ca57
--- /dev/null
+++ b/bin/sh/tests/builtins/lineno3.0.stdout
@@ -0,0 +1,2 @@
+before: 3
+after: 6
diff --git a/bin/sh/tests/builtins/local1.0 b/bin/sh/tests/builtins/local1.0
new file mode 100644
index 000000000000..b28837ec005f
--- /dev/null
+++ b/bin/sh/tests/builtins/local1.0
@@ -0,0 +1,13 @@
+# $FreeBSD$
+# 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/sh/tests/builtins/local2.0 b/bin/sh/tests/builtins/local2.0
new file mode 100644
index 000000000000..cc8c10f40618
--- /dev/null
+++ b/bin/sh/tests/builtins/local2.0
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/local3.0 b/bin/sh/tests/builtins/local3.0
new file mode 100644
index 000000000000..39ee370099e7
--- /dev/null
+++ b/bin/sh/tests/builtins/local3.0
@@ -0,0 +1,26 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/local4.0 b/bin/sh/tests/builtins/local4.0
new file mode 100644
index 000000000000..3955aaa12f1a
--- /dev/null
+++ b/bin/sh/tests/builtins/local4.0
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/local5.0 b/bin/sh/tests/builtins/local5.0
new file mode 100644
index 000000000000..2f2a14e110ae
--- /dev/null
+++ b/bin/sh/tests/builtins/local5.0
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/local6.0 b/bin/sh/tests/builtins/local6.0
new file mode 100644
index 000000000000..017bb1234c8c
--- /dev/null
+++ b/bin/sh/tests/builtins/local6.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+f() {
+ local x
+ readonly x=2
+}
+x=3
+f
+x=4
+[ "$x" = 4 ]
diff --git a/bin/sh/tests/builtins/local7.0 b/bin/sh/tests/builtins/local7.0
new file mode 100644
index 000000000000..f7e6fc0aae97
--- /dev/null
+++ b/bin/sh/tests/builtins/local7.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+f() {
+ local x
+ readonly x=2
+}
+unset x
+f
+x=4
+[ "$x" = 4 ]
diff --git a/bin/sh/tests/builtins/locale1.0 b/bin/sh/tests/builtins/locale1.0
new file mode 100644
index 000000000000..90b10944c5a5
--- /dev/null
+++ b/bin/sh/tests/builtins/locale1.0
@@ -0,0 +1,134 @@
+# $FreeBSD$
+# 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/sh/tests/builtins/locale2.0 b/bin/sh/tests/builtins/locale2.0
new file mode 100644
index 000000000000..86dd237ff54a
--- /dev/null
+++ b/bin/sh/tests/builtins/locale2.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+$SH -c 'LC_ALL=C true; kill -INT $$; echo continued'
+r=$?
+[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ]
diff --git a/bin/sh/tests/builtins/printf1.0 b/bin/sh/tests/builtins/printf1.0
new file mode 100644
index 000000000000..99a82d014794
--- /dev/null
+++ b/bin/sh/tests/builtins/printf1.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+[ "$(printf '%c\0%s%d' x '\' 010 | tr '\0' Z)" = 'xZ\8' ]
diff --git a/bin/sh/tests/builtins/printf2.0 b/bin/sh/tests/builtins/printf2.0
new file mode 100644
index 000000000000..7763d6fe9636
--- /dev/null
+++ b/bin/sh/tests/builtins/printf2.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+[ "$(printf '%cZ%s%d' x '\' 010)" = 'xZ\8' ]
diff --git a/bin/sh/tests/builtins/printf3.0 b/bin/sh/tests/builtins/printf3.0
new file mode 100644
index 000000000000..0e7ea85cddb4
--- /dev/null
+++ b/bin/sh/tests/builtins/printf3.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+set -e
+v=$(! printf "%d" @wrong 2>/dev/null)
+[ "$v" = "0" ]
diff --git a/bin/sh/tests/builtins/printf4.0 b/bin/sh/tests/builtins/printf4.0
new file mode 100644
index 000000000000..2dd3e729574a
--- /dev/null
+++ b/bin/sh/tests/builtins/printf4.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+set -e
+v=$(! printf "%d" 4wrong 2>/dev/null)
+[ "$v" = "4" ]
diff --git a/bin/sh/tests/builtins/read1.0 b/bin/sh/tests/builtins/read1.0
new file mode 100644
index 000000000000..06a68faa32a3
--- /dev/null
+++ b/bin/sh/tests/builtins/read1.0
@@ -0,0 +1,26 @@
+# $FreeBSD$
+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/sh/tests/builtins/read1.0.stdout b/bin/sh/tests/builtins/read1.0.stdout
new file mode 100644
index 000000000000..dbcb1af9bae7
--- /dev/null
+++ b/bin/sh/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/sh/tests/builtins/read2.0 b/bin/sh/tests/builtins/read2.0
new file mode 100644
index 000000000000..fc7451191586
--- /dev/null
+++ b/bin/sh/tests/builtins/read2.0
@@ -0,0 +1,31 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/read3.0 b/bin/sh/tests/builtins/read3.0
new file mode 100644
index 000000000000..c6ae9c1023c0
--- /dev/null
+++ b/bin/sh/tests/builtins/read3.0
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/read3.0.stdout b/bin/sh/tests/builtins/read3.0.stdout
new file mode 100644
index 000000000000..8ed98ca9d86e
--- /dev/null
+++ b/bin/sh/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/sh/tests/builtins/read4.0 b/bin/sh/tests/builtins/read4.0
new file mode 100644
index 000000000000..7204a35aa0a5
--- /dev/null
+++ b/bin/sh/tests/builtins/read4.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/read4.0.stdout b/bin/sh/tests/builtins/read4.0.stdout
new file mode 100644
index 000000000000..a8747a46ffeb
--- /dev/null
+++ b/bin/sh/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/sh/tests/builtins/read5.0 b/bin/sh/tests/builtins/read5.0
new file mode 100644
index 000000000000..7d83391cba22
--- /dev/null
+++ b/bin/sh/tests/builtins/read5.0
@@ -0,0 +1,32 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/read6.0 b/bin/sh/tests/builtins/read6.0
new file mode 100644
index 000000000000..2168e10c841a
--- /dev/null
+++ b/bin/sh/tests/builtins/read6.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+: | read x
+r=$?
+[ "$r" = 1 ]
diff --git a/bin/sh/tests/builtins/read7.0 b/bin/sh/tests/builtins/read7.0
new file mode 100644
index 000000000000..e78f887b60b4
--- /dev/null
+++ b/bin/sh/tests/builtins/read7.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+{ errmsg=`read x <&- 2>&1 >&3`; } 3>&1
+r=$?
+[ "$r" -ge 2 ] && [ "$r" -le 128 ] && [ -n "$errmsg" ]
diff --git a/bin/sh/tests/builtins/read8.0 b/bin/sh/tests/builtins/read8.0
new file mode 100644
index 000000000000..fb786ff008b9
--- /dev/null
+++ b/bin/sh/tests/builtins/read8.0
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+read a b c <<\EOF
+\
+A\
+ \
+ \
+ \
+B\
+ \
+ \
+C\
+ \
+ \
+ \
+EOF
+[ "$a.$b.$c" = "A.B.C" ]
diff --git a/bin/sh/tests/builtins/read9.0 b/bin/sh/tests/builtins/read9.0
new file mode 100644
index 000000000000..080549889839
--- /dev/null
+++ b/bin/sh/tests/builtins/read9.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/return1.0 b/bin/sh/tests/builtins/return1.0
new file mode 100644
index 000000000000..787e892a7698
--- /dev/null
+++ b/bin/sh/tests/builtins/return1.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+f() {
+ return 0
+ exit 1
+}
+
+f
diff --git a/bin/sh/tests/builtins/return2.1 b/bin/sh/tests/builtins/return2.1
new file mode 100644
index 000000000000..0ef817179d73
--- /dev/null
+++ b/bin/sh/tests/builtins/return2.1
@@ -0,0 +1,7 @@
+# $FreeBSD$
+f() {
+ true && return 1
+ return 0
+}
+
+f
diff --git a/bin/sh/tests/builtins/return3.1 b/bin/sh/tests/builtins/return3.1
new file mode 100644
index 000000000000..605ec680d66a
--- /dev/null
+++ b/bin/sh/tests/builtins/return3.1
@@ -0,0 +1,3 @@
+# $FreeBSD$
+return 1
+exit 0
diff --git a/bin/sh/tests/builtins/return4.0 b/bin/sh/tests/builtins/return4.0
new file mode 100644
index 000000000000..be5582b458b4
--- /dev/null
+++ b/bin/sh/tests/builtins/return4.0
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/return5.0 b/bin/sh/tests/builtins/return5.0
new file mode 100644
index 000000000000..6e4b7bd751a8
--- /dev/null
+++ b/bin/sh/tests/builtins/return5.0
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/return6.4 b/bin/sh/tests/builtins/return6.4
new file mode 100644
index 000000000000..e4d8e0d641a1
--- /dev/null
+++ b/bin/sh/tests/builtins/return6.4
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+while return 4; do exit 3; done
diff --git a/bin/sh/tests/builtins/return7.4 b/bin/sh/tests/builtins/return7.4
new file mode 100644
index 000000000000..2047373473ab
--- /dev/null
+++ b/bin/sh/tests/builtins/return7.4
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+f() {
+ while return 4; do exit 3; done
+}
+f
diff --git a/bin/sh/tests/builtins/return8.0 b/bin/sh/tests/builtins/return8.0
new file mode 100644
index 000000000000..f00e859a74ce
--- /dev/null
+++ b/bin/sh/tests/builtins/return8.0
@@ -0,0 +1,13 @@
+# $FreeBSD$
+
+if [ "$1" = nested ]; then
+ return 17
+fi
+
+f() {
+ set -- nested
+ . "$0"
+ return $(($? ^ 1))
+}
+f
+exit $(($? ^ 16))
diff --git a/bin/sh/tests/builtins/set1.0 b/bin/sh/tests/builtins/set1.0
new file mode 100644
index 000000000000..fc39fade6270
--- /dev/null
+++ b/bin/sh/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/sh/tests/builtins/set2.0 b/bin/sh/tests/builtins/set2.0
new file mode 100644
index 000000000000..ad13eab0a7b8
--- /dev/null
+++ b/bin/sh/tests/builtins/set2.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+! env @badness=1 ${SH} -c 'v=`set`; eval "$v"' 2>&1 | grep @badness
diff --git a/bin/sh/tests/builtins/set3.0 b/bin/sh/tests/builtins/set3.0
new file mode 100644
index 000000000000..c5536e96b7a1
--- /dev/null
+++ b/bin/sh/tests/builtins/set3.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+settings1=$(set +o) && set -o nolog && settings2=$(set +o) &&
+[ "$settings1" != "$settings2" ]
diff --git a/bin/sh/tests/builtins/trap1.0 b/bin/sh/tests/builtins/trap1.0
new file mode 100644
index 000000000000..313f6a387678
--- /dev/null
+++ b/bin/sh/tests/builtins/trap1.0
@@ -0,0 +1,22 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/trap10.0 b/bin/sh/tests/builtins/trap10.0
new file mode 100644
index 000000000000..fa0e35d6a6b2
--- /dev/null
+++ b/bin/sh/tests/builtins/trap10.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/trap11.0 b/bin/sh/tests/builtins/trap11.0
new file mode 100644
index 000000000000..cfeea9ed9ded
--- /dev/null
+++ b/bin/sh/tests/builtins/trap11.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/trap12.0 b/bin/sh/tests/builtins/trap12.0
new file mode 100644
index 000000000000..8c62ffd2b570
--- /dev/null
+++ b/bin/sh/tests/builtins/trap12.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+f() {
+ trap 'return 42' USR1
+ kill -USR1 $$
+ return 3
+}
+f
+r=$?
+[ "$r" = 42 ]
diff --git a/bin/sh/tests/builtins/trap13.0 b/bin/sh/tests/builtins/trap13.0
new file mode 100644
index 000000000000..d90eb08eb242
--- /dev/null
+++ b/bin/sh/tests/builtins/trap13.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+{
+ trap 'exit 0' INT
+ ${SH} -c 'kill -INT $PPID'
+ exit 3
+} &
+wait $!
diff --git a/bin/sh/tests/builtins/trap14.0 b/bin/sh/tests/builtins/trap14.0
new file mode 100644
index 000000000000..97cce8d0d244
--- /dev/null
+++ b/bin/sh/tests/builtins/trap14.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+{
+ trap - INT
+ ${SH} -c 'kill -INT $PPID' &
+ wait
+} &
+wait $!
+r=$?
+[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ]
diff --git a/bin/sh/tests/builtins/trap15.0 b/bin/sh/tests/builtins/trap15.0
new file mode 100644
index 000000000000..6b9857df3d1a
--- /dev/null
+++ b/bin/sh/tests/builtins/trap15.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+(${SH} -c 'term(){ exit 5;}; trap term TERM; kill -TERM $$') &
+wait >/dev/null 2>&1 $!
+[ $? -eq 5 ]
diff --git a/bin/sh/tests/builtins/trap16.0 b/bin/sh/tests/builtins/trap16.0
new file mode 100644
index 000000000000..3d70cce8a721
--- /dev/null
+++ b/bin/sh/tests/builtins/trap16.0
@@ -0,0 +1,20 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/trap17.0 b/bin/sh/tests/builtins/trap17.0
new file mode 100644
index 000000000000..89be893edd1a
--- /dev/null
+++ b/bin/sh/tests/builtins/trap17.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+# 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/sh/tests/builtins/trap2.0 b/bin/sh/tests/builtins/trap2.0
new file mode 100644
index 000000000000..a05287a16771
--- /dev/null
+++ b/bin/sh/tests/builtins/trap2.0
@@ -0,0 +1,52 @@
+# $FreeBSD$
+# 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/sh/tests/builtins/trap3.0 b/bin/sh/tests/builtins/trap3.0
new file mode 100644
index 000000000000..81607293531e
--- /dev/null
+++ b/bin/sh/tests/builtins/trap3.0
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+{
+ 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/sh/tests/builtins/trap4.0 b/bin/sh/tests/builtins/trap4.0
new file mode 100644
index 000000000000..7f2080ee4dca
--- /dev/null
+++ b/bin/sh/tests/builtins/trap4.0
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/trap5.0 b/bin/sh/tests/builtins/trap5.0
new file mode 100644
index 000000000000..56e0fb1b89fe
--- /dev/null
+++ b/bin/sh/tests/builtins/trap5.0
@@ -0,0 +1,19 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/trap6.0 b/bin/sh/tests/builtins/trap6.0
new file mode 100644
index 000000000000..bd2bf7efe769
--- /dev/null
+++ b/bin/sh/tests/builtins/trap6.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/trap7.0 b/bin/sh/tests/builtins/trap7.0
new file mode 100644
index 000000000000..35529b80f4bf
--- /dev/null
+++ b/bin/sh/tests/builtins/trap7.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+[ "$(trap 'echo trapped' EXIT)" = trapped ]
diff --git a/bin/sh/tests/builtins/trap8.0 b/bin/sh/tests/builtins/trap8.0
new file mode 100644
index 000000000000..cdce976e36da
--- /dev/null
+++ b/bin/sh/tests/builtins/trap8.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+# 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/sh/tests/builtins/trap9.0 b/bin/sh/tests/builtins/trap9.0
new file mode 100644
index 000000000000..0f584ecec584
--- /dev/null
+++ b/bin/sh/tests/builtins/trap9.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+test "$(trap 'printf trap; echo ped' EXIT; f() { :; }; f)" = trapped || exit 1
diff --git a/bin/sh/tests/builtins/type1.0 b/bin/sh/tests/builtins/type1.0
new file mode 100644
index 000000000000..c5e456437946
--- /dev/null
+++ b/bin/sh/tests/builtins/type1.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+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/sh/tests/builtins/type1.0.stderr b/bin/sh/tests/builtins/type1.0.stderr
new file mode 100644
index 000000000000..7853418a4827
--- /dev/null
+++ b/bin/sh/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/sh/tests/builtins/type2.0 b/bin/sh/tests/builtins/type2.0
new file mode 100644
index 000000000000..fe44d957fc0a
--- /dev/null
+++ b/bin/sh/tests/builtins/type2.0
@@ -0,0 +1,26 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/type3.0 b/bin/sh/tests/builtins/type3.0
new file mode 100644
index 000000000000..87cccdd812cc
--- /dev/null
+++ b/bin/sh/tests/builtins/type3.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+[ "$(type type)" = "$(type -- type)" ]
diff --git a/bin/sh/tests/builtins/unalias.0 b/bin/sh/tests/builtins/unalias.0
new file mode 100644
index 000000000000..34d8d6e07d2e
--- /dev/null
+++ b/bin/sh/tests/builtins/unalias.0
@@ -0,0 +1,21 @@
+# $FreeBSD$
+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/sh/tests/builtins/var-assign.0 b/bin/sh/tests/builtins/var-assign.0
new file mode 100644
index 000000000000..efeb4bd130ac
--- /dev/null
+++ b/bin/sh/tests/builtins/var-assign.0
@@ -0,0 +1,55 @@
+# $FreeBSD$
+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/sh/tests/builtins/var-assign2.0 b/bin/sh/tests/builtins/var-assign2.0
new file mode 100644
index 000000000000..eafec89a681b
--- /dev/null
+++ b/bin/sh/tests/builtins/var-assign2.0
@@ -0,0 +1,55 @@
+# $FreeBSD$
+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/sh/tests/builtins/wait1.0 b/bin/sh/tests/builtins/wait1.0
new file mode 100644
index 000000000000..1ca85308c9ac
--- /dev/null
+++ b/bin/sh/tests/builtins/wait1.0
@@ -0,0 +1,23 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/wait10.0 b/bin/sh/tests/builtins/wait10.0
new file mode 100644
index 000000000000..864fc7817276
--- /dev/null
+++ b/bin/sh/tests/builtins/wait10.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+# Init cannot be a child of the shell.
+exit 49 & p49=$!
+wait 1 "$p49"
+[ "$?" = 49 ]
diff --git a/bin/sh/tests/builtins/wait2.0 b/bin/sh/tests/builtins/wait2.0
new file mode 100644
index 000000000000..e61455cf5f0e
--- /dev/null
+++ b/bin/sh/tests/builtins/wait2.0
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/wait3.0 b/bin/sh/tests/builtins/wait3.0
new file mode 100644
index 000000000000..1ed52999630d
--- /dev/null
+++ b/bin/sh/tests/builtins/wait3.0
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+failures=
+failure() {
+ echo "Error at line $1" >&2
+ failures=x$failures
+}
+
+T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX)
+trap 'rm -rf $T' 0
+cd $T || exit 3
+mkfifo fifo1
+for i in 1 2 3 4 5 6 7 8 9 10; do
+ exit $i 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/sh/tests/builtins/wait4.0 b/bin/sh/tests/builtins/wait4.0
new file mode 100644
index 000000000000..79351315d384
--- /dev/null
+++ b/bin/sh/tests/builtins/wait4.0
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/wait5.0 b/bin/sh/tests/builtins/wait5.0
new file mode 100644
index 000000000000..6874bf669302
--- /dev/null
+++ b/bin/sh/tests/builtins/wait5.0
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+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/sh/tests/builtins/wait6.0 b/bin/sh/tests/builtins/wait6.0
new file mode 100644
index 000000000000..20e3c6808679
--- /dev/null
+++ b/bin/sh/tests/builtins/wait6.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+wait --
diff --git a/bin/sh/tests/builtins/wait7.0 b/bin/sh/tests/builtins/wait7.0
new file mode 100644
index 000000000000..0fb092f8f614
--- /dev/null
+++ b/bin/sh/tests/builtins/wait7.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+: &
+wait -- $!
diff --git a/bin/sh/tests/builtins/wait8.0 b/bin/sh/tests/builtins/wait8.0
new file mode 100644
index 000000000000..b59ff59622eb
--- /dev/null
+++ b/bin/sh/tests/builtins/wait8.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+exit 44 & p44=$!
+exit 45 & p45=$!
+exit 7 & p7=$!
+wait "$p44" "$p7" "$p45"
+[ "$?" = 45 ]
diff --git a/bin/sh/tests/builtins/wait9.127 b/bin/sh/tests/builtins/wait9.127
new file mode 100644
index 000000000000..661f275421f8
--- /dev/null
+++ b/bin/sh/tests/builtins/wait9.127
@@ -0,0 +1,3 @@
+# $FreeBSD$
+# Init cannot be a child of the shell.
+wait 1