summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-01-01 18:17:46 +0000
committerjilles <jilles@FreeBSD.org>2010-01-01 18:17:46 +0000
commit446838eef9a2c4d195b487b7b741e56c01af2470 (patch)
tree6198da26b9a8cb29d4142aca530e1a661605a331 /tools
parent4ce9cced3fd3f56de8a72297d2a0f0939d4bb2f9 (diff)
downloadFreeBSD-src-446838eef9a2c4d195b487b7b741e56c01af2470.zip
FreeBSD-src-446838eef9a2c4d195b487b7b741e56c01af2470.tar.gz
sh: Fix some bugs with backquoted builtins:
- correctly handle error output in $(builtin 2>&1), clarify out1/out2 vs output/errout in the code - treat all builtins as regular builtins so errors do not abort the shell and variable assignments do not persist - respect the caller's INTOFF Some bugs still exist: - expansion errors may still abort the shell - some side effects of expansions and builtins persist
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/bin/sh/expansion/cmdsubst1.048
1 files changed, 48 insertions, 0 deletions
diff --git a/tools/regression/bin/sh/expansion/cmdsubst1.0 b/tools/regression/bin/sh/expansion/cmdsubst1.0
new file mode 100644
index 0000000..515c7da
--- /dev/null
+++ b/tools/regression/bin/sh/expansion/cmdsubst1.0
@@ -0,0 +1,48 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+ if ! eval "[ $* ]"; then
+ echo "Failed: $*"
+ : $((failures += 1))
+ fi
+}
+
+check '"$(echo abcde)" = "abcde"'
+check '"$(echo abcde; :)" = "abcde"'
+
+check '"$(printf abcde)" = "abcde"'
+check '"$(printf abcde; :)" = "abcde"'
+
+# regular
+check '-n "$(umask)"'
+check '-n "$(umask; :)"'
+check '-n "$(umask 2>&1)"'
+check '-n "$(umask 2>&1; :)"'
+
+# special
+check '-n "$(times)"'
+check '-n "$(times; :)"'
+check '-n "$(times 2>&1)"'
+check '-n "$(times 2>&1; :)"'
+
+# regular
+check '".$(umask -@ 2>&1)." = ".umask: Illegal option -@."'
+check '".$(umask -@ 2>&1; :)." = ".umask: Illegal option -@."'
+check '".$({ umask -@; } 2>&1)." = ".umask: Illegal option -@."'
+
+# special
+check '".$(shift xyz 2>&1)." = ".shift: Illegal number: xyz."'
+check '".$(shift xyz 2>&1; :)." = ".shift: Illegal number: xyz."'
+check '".$({ shift xyz; } 2>&1)." = ".shift: Illegal number: xyz."'
+
+v=1
+check '-z "$(v=2 :)"'
+check '"$v" = 1'
+check '-z "$(v=3)"'
+check '"$v" = 1'
+check '"$(v=4 eval echo \$v)" = 4'
+check '"$v" = 1'
+
+exit $((failures > 0))
OpenPOWER on IntegriCloud