aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/tests/errors
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sh/tests/errors')
-rw-r--r--bin/sh/tests/errors/Makefile34
-rw-r--r--bin/sh/tests/errors/Makefile.depend10
-rw-r--r--bin/sh/tests/errors/assignment-error1.029
-rw-r--r--bin/sh/tests/errors/assignment-error2.07
-rw-r--r--bin/sh/tests/errors/backquote-error1.03
-rw-r--r--bin/sh/tests/errors/backquote-error2.06
-rw-r--r--bin/sh/tests/errors/bad-binary1.12611
-rw-r--r--bin/sh/tests/errors/bad-keyword1.03
-rw-r--r--bin/sh/tests/errors/bad-parm-exp1.06
-rw-r--r--bin/sh/tests/errors/bad-parm-exp2.21
-rw-r--r--bin/sh/tests/errors/bad-parm-exp2.2.stderr1
-rw-r--r--bin/sh/tests/errors/bad-parm-exp3.21
-rw-r--r--bin/sh/tests/errors/bad-parm-exp3.2.stderr1
-rw-r--r--bin/sh/tests/errors/bad-parm-exp4.21
-rw-r--r--bin/sh/tests/errors/bad-parm-exp4.2.stderr1
-rw-r--r--bin/sh/tests/errors/bad-parm-exp5.21
-rw-r--r--bin/sh/tests/errors/bad-parm-exp5.2.stderr1
-rw-r--r--bin/sh/tests/errors/bad-parm-exp6.21
-rw-r--r--bin/sh/tests/errors/bad-parm-exp6.2.stderr1
-rw-r--r--bin/sh/tests/errors/bad-parm-exp7.03
-rw-r--r--bin/sh/tests/errors/bad-parm-exp8.03
-rw-r--r--bin/sh/tests/errors/option-error.045
-rw-r--r--bin/sh/tests/errors/redirection-error.052
-rw-r--r--bin/sh/tests/errors/redirection-error2.23
-rw-r--r--bin/sh/tests/errors/redirection-error3.053
-rw-r--r--bin/sh/tests/errors/redirection-error4.06
-rw-r--r--bin/sh/tests/errors/redirection-error5.04
-rw-r--r--bin/sh/tests/errors/redirection-error6.011
-rw-r--r--bin/sh/tests/errors/redirection-error7.06
-rw-r--r--bin/sh/tests/errors/redirection-error8.04
-rw-r--r--bin/sh/tests/errors/script-error1.04
-rw-r--r--bin/sh/tests/errors/write-error1.02
32 files changed, 315 insertions, 0 deletions
diff --git a/bin/sh/tests/errors/Makefile b/bin/sh/tests/errors/Makefile
new file mode 100644
index 000000000000..26b1ccbef4ee
--- /dev/null
+++ b/bin/sh/tests/errors/Makefile
@@ -0,0 +1,34 @@
+PACKAGE= tests
+
+TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T}
+
+.PATH: ${.CURDIR:H}
+ATF_TESTS_SH= functional_test
+
+${PACKAGE}FILES+= assignment-error1.0
+${PACKAGE}FILES+= assignment-error2.0
+${PACKAGE}FILES+= backquote-error1.0
+${PACKAGE}FILES+= backquote-error2.0
+${PACKAGE}FILES+= bad-binary1.126
+${PACKAGE}FILES+= bad-keyword1.0
+${PACKAGE}FILES+= bad-parm-exp1.0
+${PACKAGE}FILES+= bad-parm-exp2.2 bad-parm-exp2.2.stderr
+${PACKAGE}FILES+= bad-parm-exp3.2 bad-parm-exp3.2.stderr
+${PACKAGE}FILES+= bad-parm-exp4.2 bad-parm-exp4.2.stderr
+${PACKAGE}FILES+= bad-parm-exp5.2 bad-parm-exp5.2.stderr
+${PACKAGE}FILES+= bad-parm-exp6.2 bad-parm-exp6.2.stderr
+${PACKAGE}FILES+= bad-parm-exp7.0
+${PACKAGE}FILES+= bad-parm-exp8.0
+${PACKAGE}FILES+= option-error.0
+${PACKAGE}FILES+= redirection-error.0
+${PACKAGE}FILES+= redirection-error2.2
+${PACKAGE}FILES+= redirection-error3.0
+${PACKAGE}FILES+= redirection-error4.0
+${PACKAGE}FILES+= redirection-error5.0
+${PACKAGE}FILES+= redirection-error6.0
+${PACKAGE}FILES+= redirection-error7.0
+${PACKAGE}FILES+= redirection-error8.0
+${PACKAGE}FILES+= script-error1.0
+${PACKAGE}FILES+= write-error1.0
+
+.include <bsd.test.mk>
diff --git a/bin/sh/tests/errors/Makefile.depend b/bin/sh/tests/errors/Makefile.depend
new file mode 100644
index 000000000000..11aba52f82cf
--- /dev/null
+++ b/bin/sh/tests/errors/Makefile.depend
@@ -0,0 +1,10 @@
+# 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/errors/assignment-error1.0 b/bin/sh/tests/errors/assignment-error1.0
new file mode 100644
index 000000000000..27f3b06fbc98
--- /dev/null
+++ b/bin/sh/tests/errors/assignment-error1.0
@@ -0,0 +1,29 @@
+IFS=,
+
+SPECIAL="break,\
+ :,\
+ continue,\
+ . /dev/null,\
+ eval,\
+ exec,\
+ export -p,\
+ readonly -p,\
+ set,\
+ shift,\
+ times,\
+ trap,\
+ unset foo"
+
+# If there is no command word, the shell must abort on an assignment error.
+${SH} -c "readonly a=0; a=2; exit 0" 2>/dev/null && exit 1
+
+# Special built-in utilities must abort on an assignment error.
+set -- ${SPECIAL}
+for cmd in "$@"
+do
+ ${SH} -c "readonly a=0; a=2 ${cmd}; exit 0" 2>/dev/null && exit 1
+done
+
+# Other utilities must not abort; we currently still execute them.
+${SH} -c 'readonly a=0; a=1 true; exit $a' 2>/dev/null || exit 1
+${SH} -c 'readonly a=0; a=1 command :; exit $a' 2>/dev/null || exit 1
diff --git a/bin/sh/tests/errors/assignment-error2.0 b/bin/sh/tests/errors/assignment-error2.0
new file mode 100644
index 000000000000..d9844b25cdc3
--- /dev/null
+++ b/bin/sh/tests/errors/assignment-error2.0
@@ -0,0 +1,7 @@
+
+set -e
+HOME=/
+readonly HOME
+cd /sbin
+{ HOME=/bin cd; } 2>/dev/null || :
+[ "$(pwd)" != /bin ]
diff --git a/bin/sh/tests/errors/backquote-error1.0 b/bin/sh/tests/errors/backquote-error1.0
new file mode 100644
index 000000000000..c4bdb6722dc4
--- /dev/null
+++ b/bin/sh/tests/errors/backquote-error1.0
@@ -0,0 +1,3 @@
+
+echo 'echo `for` echo ".BAD"CODE.' | ${SH} +m -i 2>&1 | grep -q BADCODE && exit 1
+exit 0
diff --git a/bin/sh/tests/errors/backquote-error2.0 b/bin/sh/tests/errors/backquote-error2.0
new file mode 100644
index 000000000000..05fcd96bb101
--- /dev/null
+++ b/bin/sh/tests/errors/backquote-error2.0
@@ -0,0 +1,6 @@
+
+${SH} -c 'echo `echo .BA"DCODE.`
+echo ".BAD"CODE.' 2>&1 | grep -q BADCODE && exit 1
+echo '`"`' | ${SH} -n 2>/dev/null && exit 1
+echo '`'"'"'`' | ${SH} -n 2>/dev/null && exit 1
+exit 0
diff --git a/bin/sh/tests/errors/bad-binary1.126 b/bin/sh/tests/errors/bad-binary1.126
new file mode 100644
index 000000000000..76ab2aa5a8fe
--- /dev/null
+++ b/bin/sh/tests/errors/bad-binary1.126
@@ -0,0 +1,11 @@
+# Checking for binary "scripts" without magic number is permitted but not
+# required by POSIX. However, it is preferable to getting errors like
+# Syntax error: word unexpected (expecting ")")
+# from trying to execute ELF binaries for the wrong architecture.
+
+T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit
+trap 'rm -rf "${T}"' 0
+printf '\0echo bad\n' >"$T/testshellproc"
+chmod 755 "$T/testshellproc"
+PATH=$T:$PATH
+testshellproc 2>/dev/null
diff --git a/bin/sh/tests/errors/bad-keyword1.0 b/bin/sh/tests/errors/bad-keyword1.0
new file mode 100644
index 000000000000..f754e02c122a
--- /dev/null
+++ b/bin/sh/tests/errors/bad-keyword1.0
@@ -0,0 +1,3 @@
+
+echo ':; fi' | ${SH} -n 2>/dev/null && exit 1
+exit 0
diff --git a/bin/sh/tests/errors/bad-parm-exp1.0 b/bin/sh/tests/errors/bad-parm-exp1.0
new file mode 100644
index 000000000000..0cefdac9ea5d
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp1.0
@@ -0,0 +1,6 @@
+false && {
+ ${}
+ ${foo/}
+ ${foo@bar}
+}
+:
diff --git a/bin/sh/tests/errors/bad-parm-exp2.2 b/bin/sh/tests/errors/bad-parm-exp2.2
new file mode 100644
index 000000000000..1de22a5c20d1
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp2.2
@@ -0,0 +1 @@
+eval '${}'
diff --git a/bin/sh/tests/errors/bad-parm-exp2.2.stderr b/bin/sh/tests/errors/bad-parm-exp2.2.stderr
new file mode 100644
index 000000000000..51ea69ca9709
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp2.2.stderr
@@ -0,0 +1 @@
+eval: ${}: Bad substitution
diff --git a/bin/sh/tests/errors/bad-parm-exp3.2 b/bin/sh/tests/errors/bad-parm-exp3.2
new file mode 100644
index 000000000000..6f7b9347567f
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp3.2
@@ -0,0 +1 @@
+eval '${foo/}'
diff --git a/bin/sh/tests/errors/bad-parm-exp3.2.stderr b/bin/sh/tests/errors/bad-parm-exp3.2.stderr
new file mode 100644
index 000000000000..70473f9a87b6
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp3.2.stderr
@@ -0,0 +1 @@
+eval: ${foo/}: Bad substitution
diff --git a/bin/sh/tests/errors/bad-parm-exp4.2 b/bin/sh/tests/errors/bad-parm-exp4.2
new file mode 100644
index 000000000000..9f4efa88c4b5
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp4.2
@@ -0,0 +1 @@
+eval '${foo:@abc}'
diff --git a/bin/sh/tests/errors/bad-parm-exp4.2.stderr b/bin/sh/tests/errors/bad-parm-exp4.2.stderr
new file mode 100644
index 000000000000..3363f5177f2f
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp4.2.stderr
@@ -0,0 +1 @@
+eval: ${foo:@...}: Bad substitution
diff --git a/bin/sh/tests/errors/bad-parm-exp5.2 b/bin/sh/tests/errors/bad-parm-exp5.2
new file mode 100644
index 000000000000..3c0d10296f6b
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp5.2
@@ -0,0 +1 @@
+eval '${/}'
diff --git a/bin/sh/tests/errors/bad-parm-exp5.2.stderr b/bin/sh/tests/errors/bad-parm-exp5.2.stderr
new file mode 100644
index 000000000000..13763f8ed9ca
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp5.2.stderr
@@ -0,0 +1 @@
+eval: ${/}: Bad substitution
diff --git a/bin/sh/tests/errors/bad-parm-exp6.2 b/bin/sh/tests/errors/bad-parm-exp6.2
new file mode 100644
index 000000000000..179aa5d06bb4
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp6.2
@@ -0,0 +1 @@
+eval '${#foo^}'
diff --git a/bin/sh/tests/errors/bad-parm-exp6.2.stderr b/bin/sh/tests/errors/bad-parm-exp6.2.stderr
new file mode 100644
index 000000000000..cc56f65b62ec
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp6.2.stderr
@@ -0,0 +1 @@
+eval: ${foo...}: Bad substitution
diff --git a/bin/sh/tests/errors/bad-parm-exp7.0 b/bin/sh/tests/errors/bad-parm-exp7.0
new file mode 100644
index 000000000000..d82b2eade819
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp7.0
@@ -0,0 +1,3 @@
+
+v=1
+eval ": $(printf '${v-${\372}}')"
diff --git a/bin/sh/tests/errors/bad-parm-exp8.0 b/bin/sh/tests/errors/bad-parm-exp8.0
new file mode 100644
index 000000000000..9f983f1dad55
--- /dev/null
+++ b/bin/sh/tests/errors/bad-parm-exp8.0
@@ -0,0 +1,3 @@
+
+v=1
+eval ": $(printf '${v-${w\372}}')"
diff --git a/bin/sh/tests/errors/option-error.0 b/bin/sh/tests/errors/option-error.0
new file mode 100644
index 000000000000..d5eac6f4c0c3
--- /dev/null
+++ b/bin/sh/tests/errors/option-error.0
@@ -0,0 +1,45 @@
+IFS=,
+
+SPECIAL="break abc,\
+ continue abc,\
+ .,
+ exit abc,
+ export -x,
+ readonly -x,
+ return abc,
+ set -z,
+ shift abc,
+ trap -y,
+ unset -y"
+
+UTILS="alias -y,\
+ cat -z,\
+ cd abc def,\
+ command break abc,\
+ expr 1 +,\
+ fc -z,\
+ getopts,\
+ hash -z,\
+ jobs -z,\
+ printf,\
+ pwd abc,\
+ read,\
+ test abc =,\
+ ulimit -z,\
+ umask -z,\
+ unalias -z,\
+ wait abc"
+
+# Special built-in utilities must abort on an option or operand error.
+set -- ${SPECIAL}
+for cmd in "$@"
+do
+ ${SH} -c "${cmd}; exit 0" 2>/dev/null && exit 1
+done
+
+# Other utilities must not abort.
+set -- ${UTILS}
+for cmd in "$@"
+do
+ ${SH} -c "${cmd}; exit 0" 2>/dev/null || exit 1
+done
diff --git a/bin/sh/tests/errors/redirection-error.0 b/bin/sh/tests/errors/redirection-error.0
new file mode 100644
index 000000000000..dfb9f1bfb100
--- /dev/null
+++ b/bin/sh/tests/errors/redirection-error.0
@@ -0,0 +1,52 @@
+IFS=,
+
+SPECIAL="break,\
+ :,\
+ continue,\
+ . /dev/null,
+ eval,
+ exec,
+ export -p,
+ readonly -p,
+ set,
+ shift,
+ times,
+ trap,
+ unset foo"
+
+UTILS="alias,\
+ bg,\
+ bind,\
+ cd,\
+ command echo,\
+ echo,\
+ false,\
+ fc -l,\
+ fg,\
+ getopts a -a,\
+ hash,\
+ jobs,\
+ printf a,\
+ pwd,\
+ read var < /dev/null,\
+ test,\
+ true,\
+ type ls,\
+ ulimit,\
+ umask,\
+ unalias -a,\
+ wait"
+
+# Special built-in utilities must abort on a redirection error.
+set -- ${SPECIAL}
+for cmd in "$@"
+do
+ ${SH} -c "${cmd} > /; exit 0" 2>/dev/null && exit 1
+done
+
+# Other utilities must not abort.
+set -- ${UTILS}
+for cmd in "$@"
+do
+ ${SH} -c "${cmd} > /; exit 0" 2>/dev/null || exit 1
+done
diff --git a/bin/sh/tests/errors/redirection-error2.2 b/bin/sh/tests/errors/redirection-error2.2
new file mode 100644
index 000000000000..0fb47d20917b
--- /dev/null
+++ b/bin/sh/tests/errors/redirection-error2.2
@@ -0,0 +1,3 @@
+
+# sh should fail gracefully on this bad redirect
+${SH} -c 'echo 1 >&$a' 2>/dev/null
diff --git a/bin/sh/tests/errors/redirection-error3.0 b/bin/sh/tests/errors/redirection-error3.0
new file mode 100644
index 000000000000..d37ba8213547
--- /dev/null
+++ b/bin/sh/tests/errors/redirection-error3.0
@@ -0,0 +1,53 @@
+IFS=,
+
+SPECIAL="break,\
+ :,\
+ continue,\
+ . /dev/null,\
+ eval,\
+ exec,\
+ export -p,\
+ readonly -p,\
+ set,\
+ shift,\
+ times,\
+ trap,\
+ unset foo"
+
+UTILS="alias,\
+ bg,\
+ bind,\
+ cd,\
+ command echo,\
+ echo,\
+ false,\
+ fc -l,\
+ fg,\
+ getopts a -a,\
+ hash,\
+ jobs,\
+ printf a,\
+ pwd,\
+ read var < /dev/null,\
+ test,\
+ true,\
+ type ls,\
+ ulimit,\
+ umask,\
+ unalias -a,\
+ wait"
+
+# When used with 'command', neither special built-in utilities nor other
+# utilities must abort on a redirection error.
+
+set -- ${SPECIAL}
+for cmd in "$@"
+do
+ ${SH} -c "command ${cmd} > /; exit 0" 2>/dev/null || exit 1
+done
+
+set -- ${UTILS}
+for cmd in "$@"
+do
+ ${SH} -c "command ${cmd} > /; exit 0" 2>/dev/null || exit 1
+done
diff --git a/bin/sh/tests/errors/redirection-error4.0 b/bin/sh/tests/errors/redirection-error4.0
new file mode 100644
index 000000000000..b7ce514a9fbc
--- /dev/null
+++ b/bin/sh/tests/errors/redirection-error4.0
@@ -0,0 +1,6 @@
+# A redirection error should not abort the shell if there is no command word.
+exec 2>/dev/null
+</var/empty/x
+</var/empty/x y=2
+y=2 </var/empty/x
+exit 0
diff --git a/bin/sh/tests/errors/redirection-error5.0 b/bin/sh/tests/errors/redirection-error5.0
new file mode 100644
index 000000000000..1af2937839c2
--- /dev/null
+++ b/bin/sh/tests/errors/redirection-error5.0
@@ -0,0 +1,4 @@
+# A redirection error on a subshell should not abort the shell.
+exec 2>/dev/null
+( echo bad ) </var/empty/x
+exit 0
diff --git a/bin/sh/tests/errors/redirection-error6.0 b/bin/sh/tests/errors/redirection-error6.0
new file mode 100644
index 000000000000..f0ac4a5025a5
--- /dev/null
+++ b/bin/sh/tests/errors/redirection-error6.0
@@ -0,0 +1,11 @@
+# A redirection error on a compound command should not abort the shell.
+exec 2>/dev/null
+{ echo bad; } </var/empty/x
+if :; then echo bad; fi </var/empty/x
+for i in 1; do echo bad; done </var/empty/x
+i=0
+while [ $i = 0 ]; do echo bad; i=1; done </var/empty/x
+i=0
+until [ $i != 0 ]; do echo bad; i=1; done </var/empty/x
+case i in *) echo bad ;; esac </var/empty/x
+exit 0
diff --git a/bin/sh/tests/errors/redirection-error7.0 b/bin/sh/tests/errors/redirection-error7.0
new file mode 100644
index 000000000000..d853aee52fe2
--- /dev/null
+++ b/bin/sh/tests/errors/redirection-error7.0
@@ -0,0 +1,6 @@
+
+! dummy=$(
+ exec 3>&1 >&2 2>&3
+ ulimit -n 9
+ exec 9<.
+) && [ -n "$dummy" ]
diff --git a/bin/sh/tests/errors/redirection-error8.0 b/bin/sh/tests/errors/redirection-error8.0
new file mode 100644
index 000000000000..4d2693f26319
--- /dev/null
+++ b/bin/sh/tests/errors/redirection-error8.0
@@ -0,0 +1,4 @@
+
+$SH -c '{ { :; } </var/empty/x; } 2>/dev/null || kill -INT $$; echo continued'
+r=$?
+[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ]
diff --git a/bin/sh/tests/errors/script-error1.0 b/bin/sh/tests/errors/script-error1.0
new file mode 100644
index 000000000000..0020218cfd24
--- /dev/null
+++ b/bin/sh/tests/errors/script-error1.0
@@ -0,0 +1,4 @@
+
+{ stderr=$(${SH} /var/empty/nosuchscript 2>&1 >&3); } 3>&1
+r=$?
+[ -n "$stderr" ] && [ "$r" = 127 ]
diff --git a/bin/sh/tests/errors/write-error1.0 b/bin/sh/tests/errors/write-error1.0
new file mode 100644
index 000000000000..027108f9ec51
--- /dev/null
+++ b/bin/sh/tests/errors/write-error1.0
@@ -0,0 +1,2 @@
+
+! echo >&- 2>/dev/null