aboutsummaryrefslogtreecommitdiffstats
path: root/shell_cmds/sh/tests/execution
diff options
context:
space:
mode:
Diffstat (limited to 'shell_cmds/sh/tests/execution')
-rw-r--r--shell_cmds/sh/tests/execution/Makefile57
-rw-r--r--shell_cmds/sh/tests/execution/Makefile.depend11
-rw-r--r--shell_cmds/sh/tests/execution/bg1.03
-rw-r--r--shell_cmds/sh/tests/execution/bg10.04
-rw-r--r--shell_cmds/sh/tests/execution/bg10.0.stdout1
-rw-r--r--shell_cmds/sh/tests/execution/bg2.05
-rw-r--r--shell_cmds/sh/tests/execution/bg3.05
-rw-r--r--shell_cmds/sh/tests/execution/bg4.06
-rw-r--r--shell_cmds/sh/tests/execution/bg5.04
-rw-r--r--shell_cmds/sh/tests/execution/bg6.04
-rw-r--r--shell_cmds/sh/tests/execution/bg6.0.stdout1
-rw-r--r--shell_cmds/sh/tests/execution/bg7.05
-rw-r--r--shell_cmds/sh/tests/execution/bg8.05
-rw-r--r--shell_cmds/sh/tests/execution/bg9.05
-rw-r--r--shell_cmds/sh/tests/execution/fork1.010
-rw-r--r--shell_cmds/sh/tests/execution/fork2.09
-rw-r--r--shell_cmds/sh/tests/execution/fork3.04
-rw-r--r--shell_cmds/sh/tests/execution/func1.04
-rw-r--r--shell_cmds/sh/tests/execution/func2.012
-rw-r--r--shell_cmds/sh/tests/execution/func3.07
-rw-r--r--shell_cmds/sh/tests/execution/hash1.012
-rw-r--r--shell_cmds/sh/tests/execution/int-cmd1.03
-rw-r--r--shell_cmds/sh/tests/execution/killed1.08
-rw-r--r--shell_cmds/sh/tests/execution/killed2.010
-rw-r--r--shell_cmds/sh/tests/execution/not1.04
-rw-r--r--shell_cmds/sh/tests/execution/not2.06
-rw-r--r--shell_cmds/sh/tests/execution/path1.015
-rw-r--r--shell_cmds/sh/tests/execution/redir1.027
-rw-r--r--shell_cmds/sh/tests/execution/redir2.029
-rw-r--r--shell_cmds/sh/tests/execution/redir3.03
-rw-r--r--shell_cmds/sh/tests/execution/redir4.04
-rw-r--r--shell_cmds/sh/tests/execution/redir5.03
-rw-r--r--shell_cmds/sh/tests/execution/redir6.021
-rw-r--r--shell_cmds/sh/tests/execution/redir7.021
-rw-r--r--shell_cmds/sh/tests/execution/set-C1.012
-rw-r--r--shell_cmds/sh/tests/execution/set-n1.07
-rw-r--r--shell_cmds/sh/tests/execution/set-n2.05
-rw-r--r--shell_cmds/sh/tests/execution/set-n3.04
-rw-r--r--shell_cmds/sh/tests/execution/set-n4.03
-rw-r--r--shell_cmds/sh/tests/execution/set-x1.08
-rw-r--r--shell_cmds/sh/tests/execution/set-x2.09
-rw-r--r--shell_cmds/sh/tests/execution/set-x3.09
-rw-r--r--shell_cmds/sh/tests/execution/set-x4.07
-rw-r--r--shell_cmds/sh/tests/execution/shellproc1.011
-rw-r--r--shell_cmds/sh/tests/execution/subshell1.06
-rw-r--r--shell_cmds/sh/tests/execution/subshell1.0.stdout2
-rw-r--r--shell_cmds/sh/tests/execution/subshell2.010
-rw-r--r--shell_cmds/sh/tests/execution/subshell3.04
-rw-r--r--shell_cmds/sh/tests/execution/subshell4.03
-rw-r--r--shell_cmds/sh/tests/execution/unknown1.029
-rw-r--r--shell_cmds/sh/tests/execution/var-assign1.03
51 files changed, 460 insertions, 0 deletions
diff --git a/shell_cmds/sh/tests/execution/Makefile b/shell_cmds/sh/tests/execution/Makefile
new file mode 100644
index 0000000..6e80719
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/Makefile
@@ -0,0 +1,57 @@
+# $FreeBSD: head/bin/sh/tests/execution/Makefile 308229 2016-11-02 22:33:37Z jilles $
+
+PACKAGE= tests
+
+TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T}
+
+.PATH: ${.CURDIR:H}
+ATF_TESTS_SH= functional_test
+
+${PACKAGE}FILES+= bg1.0
+${PACKAGE}FILES+= bg2.0
+${PACKAGE}FILES+= bg3.0
+${PACKAGE}FILES+= bg4.0
+${PACKAGE}FILES+= bg5.0
+${PACKAGE}FILES+= bg6.0 bg6.0.stdout
+${PACKAGE}FILES+= bg7.0
+${PACKAGE}FILES+= bg8.0
+${PACKAGE}FILES+= bg9.0
+${PACKAGE}FILES+= bg10.0 bg10.0.stdout
+${PACKAGE}FILES+= fork1.0
+${PACKAGE}FILES+= fork2.0
+${PACKAGE}FILES+= fork3.0
+${PACKAGE}FILES+= func1.0
+${PACKAGE}FILES+= func2.0
+${PACKAGE}FILES+= func3.0
+${PACKAGE}FILES+= hash1.0
+${PACKAGE}FILES+= int-cmd1.0
+${PACKAGE}FILES+= killed1.0
+${PACKAGE}FILES+= killed2.0
+${PACKAGE}FILES+= not1.0
+${PACKAGE}FILES+= not2.0
+${PACKAGE}FILES+= path1.0
+${PACKAGE}FILES+= redir1.0
+${PACKAGE}FILES+= redir2.0
+${PACKAGE}FILES+= redir3.0
+${PACKAGE}FILES+= redir4.0
+${PACKAGE}FILES+= redir5.0
+${PACKAGE}FILES+= redir6.0
+${PACKAGE}FILES+= redir7.0
+${PACKAGE}FILES+= set-C1.0
+${PACKAGE}FILES+= set-n1.0
+${PACKAGE}FILES+= set-n2.0
+${PACKAGE}FILES+= set-n3.0
+${PACKAGE}FILES+= set-n4.0
+${PACKAGE}FILES+= set-x1.0
+${PACKAGE}FILES+= set-x2.0
+${PACKAGE}FILES+= set-x3.0
+${PACKAGE}FILES+= set-x4.0
+${PACKAGE}FILES+= shellproc1.0
+${PACKAGE}FILES+= subshell1.0 subshell1.0.stdout
+${PACKAGE}FILES+= subshell2.0
+${PACKAGE}FILES+= subshell3.0
+${PACKAGE}FILES+= subshell4.0
+${PACKAGE}FILES+= unknown1.0
+${PACKAGE}FILES+= var-assign1.0
+
+.include <bsd.test.mk>
diff --git a/shell_cmds/sh/tests/execution/Makefile.depend b/shell_cmds/sh/tests/execution/Makefile.depend
new file mode 100644
index 0000000..fac3607
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/Makefile.depend
@@ -0,0 +1,11 @@
+# $FreeBSD: head/bin/sh/tests/execution/Makefile.depend 296587 2016-03-09 22:46:01Z bdrewery $
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/shell_cmds/sh/tests/execution/bg1.0 b/shell_cmds/sh/tests/execution/bg1.0
new file mode 100644
index 0000000..95b51c6
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg1.0
@@ -0,0 +1,3 @@
+# $FreeBSD: head/bin/sh/tests/execution/bg1.0 221027 2011-04-25 20:54:12Z jilles $
+
+: `false` &
diff --git a/shell_cmds/sh/tests/execution/bg10.0 b/shell_cmds/sh/tests/execution/bg10.0
new file mode 100644
index 0000000..06a27f4
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg10.0
@@ -0,0 +1,4 @@
+# $FreeBSD: head/bin/sh/tests/execution/bg10.0 258535 2013-11-24 23:12:13Z jilles $
+# The redirection overrides the </dev/null implicit in a background command.
+
+echo yes | ${SH} -c '{ cat & wait; } <&0'
diff --git a/shell_cmds/sh/tests/execution/bg10.0.stdout b/shell_cmds/sh/tests/execution/bg10.0.stdout
new file mode 100644
index 0000000..7cfab5b
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg10.0.stdout
@@ -0,0 +1 @@
+yes
diff --git a/shell_cmds/sh/tests/execution/bg2.0 b/shell_cmds/sh/tests/execution/bg2.0
new file mode 100644
index 0000000..74ee54a
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg2.0
@@ -0,0 +1,5 @@
+# $FreeBSD: head/bin/sh/tests/execution/bg2.0 221027 2011-04-25 20:54:12Z jilles $
+
+f() { return 42; }
+f
+: | : &
diff --git a/shell_cmds/sh/tests/execution/bg3.0 b/shell_cmds/sh/tests/execution/bg3.0
new file mode 100644
index 0000000..95f37d3
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg3.0
@@ -0,0 +1,5 @@
+# $FreeBSD: head/bin/sh/tests/execution/bg3.0 221027 2011-04-25 20:54:12Z jilles $
+
+f() { return 42; }
+f
+(:) &
diff --git a/shell_cmds/sh/tests/execution/bg4.0 b/shell_cmds/sh/tests/execution/bg4.0
new file mode 100644
index 0000000..1220fd3
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg4.0
@@ -0,0 +1,6 @@
+# $FreeBSD: head/bin/sh/tests/execution/bg4.0 223283 2011-06-19 00:00:36Z jilles $
+
+x=''
+: ${x:=1} &
+wait
+exit ${x:-0}
diff --git a/shell_cmds/sh/tests/execution/bg5.0 b/shell_cmds/sh/tests/execution/bg5.0
new file mode 100644
index 0000000..e820035
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg5.0
@@ -0,0 +1,4 @@
+# $FreeBSD: head/bin/sh/tests/execution/bg5.0 258489 2013-11-22 21:50:13Z jilles $
+# A background command has an implicit </dev/null redirection.
+
+echo bad | ${SH} -c '{ cat & wait; }'
diff --git a/shell_cmds/sh/tests/execution/bg6.0 b/shell_cmds/sh/tests/execution/bg6.0
new file mode 100644
index 0000000..466adc2
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg6.0
@@ -0,0 +1,4 @@
+# $FreeBSD: head/bin/sh/tests/execution/bg6.0 258489 2013-11-22 21:50:13Z jilles $
+# The redirection overrides the </dev/null implicit in a background command.
+
+echo yes | ${SH} -c '{ cat & wait; } </dev/stdin'
diff --git a/shell_cmds/sh/tests/execution/bg6.0.stdout b/shell_cmds/sh/tests/execution/bg6.0.stdout
new file mode 100644
index 0000000..7cfab5b
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg6.0.stdout
@@ -0,0 +1 @@
+yes
diff --git a/shell_cmds/sh/tests/execution/bg7.0 b/shell_cmds/sh/tests/execution/bg7.0
new file mode 100644
index 0000000..788161e
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg7.0
@@ -0,0 +1,5 @@
+# $FreeBSD: head/bin/sh/tests/execution/bg7.0 258533 2013-11-24 22:45:49Z jilles $
+# The redirection does not apply to the background command, and therefore
+# does not override the implicit </dev/null.
+
+echo bad | ${SH} -c '</dev/null; { cat & wait; }'
diff --git a/shell_cmds/sh/tests/execution/bg8.0 b/shell_cmds/sh/tests/execution/bg8.0
new file mode 100644
index 0000000..aa571dc
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg8.0
@@ -0,0 +1,5 @@
+# $FreeBSD: head/bin/sh/tests/execution/bg8.0 258533 2013-11-24 22:45:49Z jilles $
+# The redirection does not apply to the background command, and therefore
+# does not override the implicit </dev/null.
+
+echo bad | ${SH} -c 'command eval \) </dev/null 2>/dev/null; { cat & wait; }'
diff --git a/shell_cmds/sh/tests/execution/bg9.0 b/shell_cmds/sh/tests/execution/bg9.0
new file mode 100644
index 0000000..4af1bae
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/bg9.0
@@ -0,0 +1,5 @@
+# $FreeBSD: head/bin/sh/tests/execution/bg9.0 258533 2013-11-24 22:45:49Z jilles $
+# The redirection does not apply to the background command, and therefore
+# does not override the implicit </dev/null.
+
+echo bad | ${SH} -c 'command eval eval \\\) \</dev/null 2>/dev/null; { cat & wait; }'
diff --git a/shell_cmds/sh/tests/execution/fork1.0 b/shell_cmds/sh/tests/execution/fork1.0
new file mode 100644
index 0000000..80b013b
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/fork1.0
@@ -0,0 +1,10 @@
+# $FreeBSD: head/bin/sh/tests/execution/fork1.0 218850 2011-02-19 13:22:18Z jilles $
+
+shname=${SH%% *}
+shname=${shname##*/}
+
+result=$(${SH} -c 'ps -p $$ -o comm=')
+test "$result" = "ps" || exit 1
+
+result=$(${SH} -c 'ps -p $$ -o comm=; :')
+test "$result" = "$shname" || exit 1
diff --git a/shell_cmds/sh/tests/execution/fork2.0 b/shell_cmds/sh/tests/execution/fork2.0
new file mode 100644
index 0000000..2639165
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/fork2.0
@@ -0,0 +1,9 @@
+# $FreeBSD: head/bin/sh/tests/execution/fork2.0 213738 2010-10-12 18:20:38Z obrien $
+
+result=$(${SH} -c '(/bin/sleep 1)& sleep 0.1; ps -p $! -o comm=; kill $!')
+test "$result" = sleep || exit 1
+
+result=$(${SH} -c '{ trap "echo trapped" EXIT; (/usr/bin/true); } & wait')
+test "$result" = trapped || exit 1
+
+exit 0
diff --git a/shell_cmds/sh/tests/execution/fork3.0 b/shell_cmds/sh/tests/execution/fork3.0
new file mode 100644
index 0000000..008be7b
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/fork3.0
@@ -0,0 +1,4 @@
+# $FreeBSD: head/bin/sh/tests/execution/fork3.0 220978 2011-04-23 22:28:56Z jilles $
+
+result=$(${SH} -c 'f() { ps -p $$ -o comm=; }; f')
+test "$result" = "ps"
diff --git a/shell_cmds/sh/tests/execution/func1.0 b/shell_cmds/sh/tests/execution/func1.0
new file mode 100644
index 0000000..1af5495
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/func1.0
@@ -0,0 +1,4 @@
+# $FreeBSD: head/bin/sh/tests/execution/func1.0 213738 2010-10-12 18:20:38Z obrien $
+
+MALLOC_OPTIONS=J ${SH} -c 'g() { g() { :; }; :; }; g' &&
+MALLOC_OPTIONS=J ${SH} -c 'g() { unset -f g; :; }; g'
diff --git a/shell_cmds/sh/tests/execution/func2.0 b/shell_cmds/sh/tests/execution/func2.0
new file mode 100644
index 0000000..eb48cc8
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/func2.0
@@ -0,0 +1,12 @@
+# $FreeBSD: head/bin/sh/tests/execution/func2.0 211399 2010-08-16 17:18:08Z jilles $
+# The empty pairs of braces here are to test that this does not cause a crash.
+
+f() { }
+f
+hash -v f >/dev/null
+f() { { }; }
+f
+hash -v f >/dev/null
+f() { { } }
+f
+hash -v f >/dev/null
diff --git a/shell_cmds/sh/tests/execution/func3.0 b/shell_cmds/sh/tests/execution/func3.0
new file mode 100644
index 0000000..209e255
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/func3.0
@@ -0,0 +1,7 @@
+# $FreeBSD: head/bin/sh/tests/execution/func3.0 216398 2010-12-12 21:18:16Z jilles $
+
+# This may fail when parsing or when defining the function, or the definition
+# may silently do nothing. In no event may the function be executed.
+
+${SH} -c 'unset() { echo overriding function executed, bad; }; v=1; unset v; exit "${v-0}"' 2>/dev/null
+:
diff --git a/shell_cmds/sh/tests/execution/hash1.0 b/shell_cmds/sh/tests/execution/hash1.0
new file mode 100644
index 0000000..d019296
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/hash1.0
@@ -0,0 +1,12 @@
+# $FreeBSD: head/bin/sh/tests/execution/hash1.0 218323 2011-02-05 14:01:46Z jilles $
+
+T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit
+trap 'rm -rf "${T}"' 0
+PATH=$T:$PATH
+ls -ld . >/dev/null
+cat <<EOF >"$T/ls"
+:
+EOF
+chmod 755 "$T/ls"
+PATH=$PATH
+ls -ld .
diff --git a/shell_cmds/sh/tests/execution/int-cmd1.0 b/shell_cmds/sh/tests/execution/int-cmd1.0
new file mode 100644
index 0000000..e980461
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/int-cmd1.0
@@ -0,0 +1,3 @@
+# $FreeBSD: head/bin/sh/tests/execution/int-cmd1.0 253271 2013-07-12 15:29:41Z jilles $
+
+! echo echo bad | $SH -ic 'fi' 2>/dev/null
diff --git a/shell_cmds/sh/tests/execution/killed1.0 b/shell_cmds/sh/tests/execution/killed1.0
new file mode 100644
index 0000000..ef9221d
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/killed1.0
@@ -0,0 +1,8 @@
+# $FreeBSD: head/bin/sh/tests/execution/killed1.0 217557 2011-01-18 21:18:31Z jilles $
+# Sometimes the "Killed" message is not flushed soon enough and it
+# is redirected along with the output of a builtin.
+# Do not change the semicolon to a newline as it would hide the bug.
+
+exec 3>&1
+exec >/dev/null 2>&1
+${SH} -c 'kill -9 $$'; : >&3 2>&3
diff --git a/shell_cmds/sh/tests/execution/killed2.0 b/shell_cmds/sh/tests/execution/killed2.0
new file mode 100644
index 0000000..4d6de16
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/killed2.0
@@ -0,0 +1,10 @@
+# $FreeBSD: head/bin/sh/tests/execution/killed2.0 218105 2011-01-30 22:57:52Z jilles $
+# Most shells print a message when a foreground job is killed by a signal.
+# POSIX allows this, provided the message is sent to stderr, not stdout.
+# Some trickery is needed to capture the message as redirecting stderr of
+# the command itself does not affect it. The colon command ensures that
+# the subshell forks for ${SH}.
+
+exec 3>&1
+r=`(${SH} -c 'kill $$'; :) 2>&1 >&3`
+[ -n "$r" ]
diff --git a/shell_cmds/sh/tests/execution/not1.0 b/shell_cmds/sh/tests/execution/not1.0
new file mode 100644
index 0000000..c825e13
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/not1.0
@@ -0,0 +1,4 @@
+# $FreeBSD: head/bin/sh/tests/execution/not1.0 249407 2013-04-12 15:19:35Z jilles $
+
+f() { ! return $1; }
+f 0 && ! f 1
diff --git a/shell_cmds/sh/tests/execution/not2.0 b/shell_cmds/sh/tests/execution/not2.0
new file mode 100644
index 0000000..e4155a9
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/not2.0
@@ -0,0 +1,6 @@
+# $FreeBSD: head/bin/sh/tests/execution/not2.0 249407 2013-04-12 15:19:35Z jilles $
+
+while :; do
+ ! break
+ exit 3
+done
diff --git a/shell_cmds/sh/tests/execution/path1.0 b/shell_cmds/sh/tests/execution/path1.0
new file mode 100644
index 0000000..3d5c67b
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/path1.0
@@ -0,0 +1,15 @@
+# $FreeBSD: head/bin/sh/tests/execution/path1.0 217206 2011-01-09 21:07:30Z jilles $
+# Some builtins should not be overridable via PATH.
+
+set -e
+T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX)
+trap 'rm -rf ${T}' 0
+echo '#!/bin/sh
+echo bad' >"$T/cd"
+chmod 755 "$T/cd"
+cd /bin
+oPATH=$PATH
+PATH=$T:$PATH:%builtin
+cd /
+PATH=$oPATH
+[ "$(pwd)" = / ]
diff --git a/shell_cmds/sh/tests/execution/redir1.0 b/shell_cmds/sh/tests/execution/redir1.0
new file mode 100644
index 0000000..6310478
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/redir1.0
@@ -0,0 +1,27 @@
+# $FreeBSD: head/bin/sh/tests/execution/redir1.0 211408 2010-08-16 22:23:19Z jilles $
+trap ': $((brokenpipe+=1))' PIPE
+
+P=${TMPDIR:-/tmp}
+cd $P
+T=$(mktemp -d sh-test.XXXXXX)
+cd $T
+
+brokenpipe=0
+mkfifo fifo1 fifo2
+read dummy >fifo2 <fifo1 &
+{
+ exec 4>fifo2
+} 3<fifo2 # Formerly, sh would keep fd 3 and a duplicate of it open.
+echo dummy >fifo1
+if [ $brokenpipe -ne 0 ]; then
+ rc=3
+fi
+wait
+echo dummy >&4 2>/dev/null
+if [ $brokenpipe -eq 1 ]; then
+ : ${rc:=0}
+fi
+
+rm fifo1 fifo2
+rmdir ${P}/${T}
+exit ${rc:-3}
diff --git a/shell_cmds/sh/tests/execution/redir2.0 b/shell_cmds/sh/tests/execution/redir2.0
new file mode 100644
index 0000000..27509c7
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/redir2.0
@@ -0,0 +1,29 @@
+# $FreeBSD: head/bin/sh/tests/execution/redir2.0 213738 2010-10-12 18:20:38Z obrien $
+trap ': $((brokenpipe+=1))' PIPE
+
+P=${TMPDIR:-/tmp}
+cd $P
+T=$(mktemp -d sh-test.XXXXXX)
+cd $T
+
+brokenpipe=0
+mkfifo fifo1 fifo2
+{
+ {
+ exec ${SH} -c 'exec <fifo1; read dummy'
+ } 7<&- # fifo2 should be kept open, but not passed to programs
+ true
+} 7<fifo2 &
+
+exec 4>fifo2
+exec 3>fifo1
+echo dummy >&4 2>/dev/null
+if [ $brokenpipe -eq 1 ]; then
+ : ${rc:=0}
+fi
+echo dummy >&3
+wait
+
+rm fifo1 fifo2
+rmdir ${P}/${T}
+exit ${rc:-3}
diff --git a/shell_cmds/sh/tests/execution/redir3.0 b/shell_cmds/sh/tests/execution/redir3.0
new file mode 100644
index 0000000..1b72098
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/redir3.0
@@ -0,0 +1,3 @@
+# $FreeBSD: head/bin/sh/tests/execution/redir3.0 214289 2010-10-24 19:56:34Z jilles $
+
+3>&- 3>&-
diff --git a/shell_cmds/sh/tests/execution/redir4.0 b/shell_cmds/sh/tests/execution/redir4.0
new file mode 100644
index 0000000..01b1f87
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/redir4.0
@@ -0,0 +1,4 @@
+# $FreeBSD: head/bin/sh/tests/execution/redir4.0 214290 2010-10-24 20:09:49Z jilles $
+
+{ echo bad 0>&3; } 2>/dev/null 3>/dev/null 3>&-
+exit 0
diff --git a/shell_cmds/sh/tests/execution/redir5.0 b/shell_cmds/sh/tests/execution/redir5.0
new file mode 100644
index 0000000..346c132
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/redir5.0
@@ -0,0 +1,3 @@
+# $FreeBSD: head/bin/sh/tests/execution/redir5.0 218325 2011-02-05 15:02:19Z jilles $
+
+{ (echo bad) >/dev/null; } </dev/null
diff --git a/shell_cmds/sh/tests/execution/redir6.0 b/shell_cmds/sh/tests/execution/redir6.0
new file mode 100644
index 0000000..f663e51
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/redir6.0
@@ -0,0 +1,21 @@
+# $FreeBSD: head/bin/sh/tests/execution/redir6.0 220978 2011-04-23 22:28:56Z jilles $
+
+failures=0
+
+check() {
+ if [ "$2" != "$3" ]; then
+ echo "Failure at $1" >&2
+ failures=$((failures + 1))
+ fi
+}
+
+check $LINENO "$(trap "echo bye" EXIT; : >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; { :; } >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; (:) >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; (: >/dev/null))" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; : >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; { :; } >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; (:) >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; (: >/dev/null)')" bye
+
+exit $((failures > 0))
diff --git a/shell_cmds/sh/tests/execution/redir7.0 b/shell_cmds/sh/tests/execution/redir7.0
new file mode 100644
index 0000000..0e309a7
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/redir7.0
@@ -0,0 +1,21 @@
+# $FreeBSD: head/bin/sh/tests/execution/redir7.0 220978 2011-04-23 22:28:56Z jilles $
+
+failures=0
+
+check() {
+ if [ "$2" != "$3" ]; then
+ echo "Failure at $1" >&2
+ failures=$((failures + 1))
+ fi
+}
+
+check $LINENO "$(trap "echo bye" EXIT; f() { :; }; f >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; f() { :; }; { f; } >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; f() { :; }; (f) >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; f() { :; }; (f >/dev/null))" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; f >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; { f; } >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; (f) >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; (f >/dev/null)')" bye
+
+exit $((failures > 0))
diff --git a/shell_cmds/sh/tests/execution/set-C1.0 b/shell_cmds/sh/tests/execution/set-C1.0
new file mode 100644
index 0000000..b7d5a4c
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/set-C1.0
@@ -0,0 +1,12 @@
+# $FreeBSD: head/bin/sh/tests/execution/set-C1.0 308229 2016-11-02 22:33:37Z jilles $
+
+T=$(mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX") || exit
+trap 'rm -rf "$T"' 0
+
+set -C
+echo . >"$T/a" &&
+[ -s "$T/a" ] &&
+{ ! true >"$T/a"; } 2>/dev/null &&
+[ -s "$T/a" ] &&
+ln -s /dev/null "$T/b" &&
+true >"$T/b"
diff --git a/shell_cmds/sh/tests/execution/set-n1.0 b/shell_cmds/sh/tests/execution/set-n1.0
new file mode 100644
index 0000000..95eb98c
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/set-n1.0
@@ -0,0 +1,7 @@
+# $FreeBSD: head/bin/sh/tests/execution/set-n1.0 222661 2011-06-03 21:17:42Z jilles $
+
+v=$( ($SH -n <<'EOF'
+for
+EOF
+) 2>&1 >/dev/null)
+[ $? -ne 0 ] && [ -n "$v" ]
diff --git a/shell_cmds/sh/tests/execution/set-n2.0 b/shell_cmds/sh/tests/execution/set-n2.0
new file mode 100644
index 0000000..d64fcca
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/set-n2.0
@@ -0,0 +1,5 @@
+# $FreeBSD: head/bin/sh/tests/execution/set-n2.0 222661 2011-06-03 21:17:42Z jilles $
+
+$SH -n <<'EOF'
+echo bad
+EOF
diff --git a/shell_cmds/sh/tests/execution/set-n3.0 b/shell_cmds/sh/tests/execution/set-n3.0
new file mode 100644
index 0000000..5af1bc4
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/set-n3.0
@@ -0,0 +1,4 @@
+# $FreeBSD: head/bin/sh/tests/execution/set-n3.0 222661 2011-06-03 21:17:42Z jilles $
+
+v=$( ($SH -nc 'for') 2>&1 >/dev/null)
+[ $? -ne 0 ] && [ -n "$v" ]
diff --git a/shell_cmds/sh/tests/execution/set-n4.0 b/shell_cmds/sh/tests/execution/set-n4.0
new file mode 100644
index 0000000..2904a34
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/set-n4.0
@@ -0,0 +1,3 @@
+# $FreeBSD: head/bin/sh/tests/execution/set-n4.0 222676 2011-06-04 11:28:42Z jilles $
+
+$SH -nc 'echo bad'
diff --git a/shell_cmds/sh/tests/execution/set-x1.0 b/shell_cmds/sh/tests/execution/set-x1.0
new file mode 100644
index 0000000..e498a3f
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/set-x1.0
@@ -0,0 +1,8 @@
+# $FreeBSD: head/bin/sh/tests/execution/set-x1.0 222882 2011-06-08 21:58:19Z jilles $
+
+key='must_contain_this'
+{ r=`set -x; { : "$key"; } 2>&1 >/dev/null`; } 2>/dev/null
+case $r in
+*"$key"*) true ;;
+*) false ;;
+esac
diff --git a/shell_cmds/sh/tests/execution/set-x2.0 b/shell_cmds/sh/tests/execution/set-x2.0
new file mode 100644
index 0000000..42c66a6
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/set-x2.0
@@ -0,0 +1,9 @@
+# $FreeBSD: head/bin/sh/tests/execution/set-x2.0 222882 2011-06-08 21:58:19Z jilles $
+
+key='must contain this'
+PS4="$key+ "
+{ r=`set -x; { :; } 2>&1 >/dev/null`; } 2>/dev/null
+case $r in
+*"$key"*) true ;;
+*) false ;;
+esac
diff --git a/shell_cmds/sh/tests/execution/set-x3.0 b/shell_cmds/sh/tests/execution/set-x3.0
new file mode 100644
index 0000000..29a917e
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/set-x3.0
@@ -0,0 +1,9 @@
+# $FreeBSD: head/bin/sh/tests/execution/set-x3.0 222907 2011-06-09 23:12:23Z jilles $
+
+key='must contain this'
+PS4='$key+ '
+{ r=`set -x; { :; } 2>&1 >/dev/null`; } 2>/dev/null
+case $r in
+*"$key"*) true ;;
+*) false ;;
+esac
diff --git a/shell_cmds/sh/tests/execution/set-x4.0 b/shell_cmds/sh/tests/execution/set-x4.0
new file mode 100644
index 0000000..90dd59a
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/set-x4.0
@@ -0,0 +1,7 @@
+# $FreeBSD: head/bin/sh/tests/execution/set-x4.0 275766 2014-12-14 16:26:19Z jilles $
+
+key=`printf '\r\t\001\200\300'`
+r=`{ set -x; : "$key"; } 2>&1 >/dev/null`
+case $r in
+*[![:print:]]*) echo fail; exit 3
+esac
diff --git a/shell_cmds/sh/tests/execution/shellproc1.0 b/shell_cmds/sh/tests/execution/shellproc1.0
new file mode 100644
index 0000000..5150b73
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/shellproc1.0
@@ -0,0 +1,11 @@
+# $FreeBSD: head/bin/sh/tests/execution/shellproc1.0 218205 2011-02-02 22:03:18Z jilles $
+
+T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit
+trap 'rm -rf "${T}"' 0
+cat <<EOF >"$T/testshellproc"
+printf 'this '
+echo is a test
+EOF
+chmod 755 "$T/testshellproc"
+PATH=$T:$PATH
+[ "`testshellproc`" = "this is a test" ]
diff --git a/shell_cmds/sh/tests/execution/subshell1.0 b/shell_cmds/sh/tests/execution/subshell1.0
new file mode 100644
index 0000000..68b0123
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/subshell1.0
@@ -0,0 +1,6 @@
+# $FreeBSD: head/bin/sh/tests/execution/subshell1.0 245383 2013-01-13 19:39:13Z jilles $
+
+(eval "cd /
+v=$(printf %0100000d 1)
+echo \${#v}")
+echo end
diff --git a/shell_cmds/sh/tests/execution/subshell1.0.stdout b/shell_cmds/sh/tests/execution/subshell1.0.stdout
new file mode 100644
index 0000000..8c71af3
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/subshell1.0.stdout
@@ -0,0 +1,2 @@
+100000
+end
diff --git a/shell_cmds/sh/tests/execution/subshell2.0 b/shell_cmds/sh/tests/execution/subshell2.0
new file mode 100644
index 0000000..2d87730
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/subshell2.0
@@ -0,0 +1,10 @@
+# $FreeBSD: head/bin/sh/tests/execution/subshell2.0 245383 2013-01-13 19:39:13Z jilles $
+
+f() {
+ x=2
+}
+(
+ x=1
+ f
+ [ "$x" = 2 ]
+)
diff --git a/shell_cmds/sh/tests/execution/subshell3.0 b/shell_cmds/sh/tests/execution/subshell3.0
new file mode 100644
index 0000000..697ee0b
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/subshell3.0
@@ -0,0 +1,4 @@
+# $FreeBSD: head/bin/sh/tests/execution/subshell3.0 245383 2013-01-13 19:39:13Z jilles $
+
+(false; exit) && exit 3
+exit 0
diff --git a/shell_cmds/sh/tests/execution/subshell4.0 b/shell_cmds/sh/tests/execution/subshell4.0
new file mode 100644
index 0000000..009db3d
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/subshell4.0
@@ -0,0 +1,3 @@
+# $FreeBSD: head/bin/sh/tests/execution/subshell4.0 245383 2013-01-13 19:39:13Z jilles $
+
+(eval "set v=1"; false) && echo bad; :
diff --git a/shell_cmds/sh/tests/execution/unknown1.0 b/shell_cmds/sh/tests/execution/unknown1.0
new file mode 100644
index 0000000..dd4149e
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/unknown1.0
@@ -0,0 +1,29 @@
+# $FreeBSD: head/bin/sh/tests/execution/unknown1.0 197820 2009-10-06 22:00:14Z jilles $
+
+nosuchtool 2>/dev/null
+[ $? -ne 127 ] && exit 1
+/var/empty/nosuchtool 2>/dev/null
+[ $? -ne 127 ] && exit 1
+(nosuchtool) 2>/dev/null
+[ $? -ne 127 ] && exit 1
+(/var/empty/nosuchtool) 2>/dev/null
+[ $? -ne 127 ] && exit 1
+/ 2>/dev/null
+[ $? -ne 126 ] && exit 1
+PATH=/usr bin 2>/dev/null
+[ $? -ne 126 ] && exit 1
+
+dummy=$(nosuchtool 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$(/var/empty/nosuchtool 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$( (nosuchtool) 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$( (/var/empty/nosuchtool) 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$(/ 2>/dev/null)
+[ $? -ne 126 ] && exit 1
+dummy=$(PATH=/usr bin 2>/dev/null)
+[ $? -ne 126 ] && exit 1
+
+exit 0
diff --git a/shell_cmds/sh/tests/execution/var-assign1.0 b/shell_cmds/sh/tests/execution/var-assign1.0
new file mode 100644
index 0000000..b75f969
--- /dev/null
+++ b/shell_cmds/sh/tests/execution/var-assign1.0
@@ -0,0 +1,3 @@
+# $FreeBSD: head/bin/sh/tests/execution/var-assign1.0 212467 2010-09-11 14:15:50Z jilles $
+
+[ "$(HOME=/etc HOME=/ cd && pwd)" = / ]