aboutsummaryrefslogtreecommitdiff
path: root/shell/ash_test/ash-vars/param_expand_bash_substring.tests
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-25 14:55:05 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-25 14:55:05 +0200
commit64925384c9cf5e0d986e183577da286bb3207ce7 (patch)
tree47688edcf2c0d987800968a9e9d85fc2cd0741e5 /shell/ash_test/ash-vars/param_expand_bash_substring.tests
parent73c47f6c41c97fb452b4747088543f2c2166830a (diff)
downloadbusybox-64925384c9cf5e0d986e183577da286bb3207ce7.tar.gz
ash: add a few tests from hush-vars/*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash_test/ash-vars/param_expand_bash_substring.tests')
-rwxr-xr-xshell/ash_test/ash-vars/param_expand_bash_substring.tests84
1 files changed, 84 insertions, 0 deletions
diff --git a/shell/ash_test/ash-vars/param_expand_bash_substring.tests b/shell/ash_test/ash-vars/param_expand_bash_substring.tests
new file mode 100755
index 000000000..cce9f123e
--- /dev/null
+++ b/shell/ash_test/ash-vars/param_expand_bash_substring.tests
@@ -0,0 +1,84 @@
+# first try some invalid patterns
+# do all of these in subshells since it's supposed to error out
+# (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
+export var=0123456789
+"$THIS_SH" -c 'echo ${:}' SHELL
+"$THIS_SH" -c 'echo ${::}' SHELL
+"$THIS_SH" -c 'echo ${:1}' SHELL
+"$THIS_SH" -c 'echo ${::1}' SHELL
+
+#this also is not valid in bash, hush accepts it:
+"$THIS_SH" -c 'echo ${var:}' SHELL
+
+# then some funky ones
+# UNFIXED BUG: this should work: "$THIS_SH" -c 'echo ${?:0}'
+
+# now some valid ones
+set --; echo "1 =|${1}|"
+set --; echo "1:1 =|${1:1}|"
+set --; echo "1:1:2=|${1:1:2}|"
+set --; echo "1::2 =|${1::2}|"
+set --; echo "1:1: =|${1:1:}|"
+set --; echo "1:: =|${1::}|"
+
+set -- 0123; echo "1 =|${1}|"
+set -- 0123; echo "1:1 =|${1:1}|"
+set -- 0123; echo "1:1:2=|${1:1:2}|"
+set -- 0123; echo "1::2 =|${1::2}|"
+set -- 0123; echo "1:1: =|${1:1:}|"
+set -- 0123; echo "1:: =|${1::}|"
+
+unset f; echo "f =|$f|"
+unset f; echo "f:1 =|${f:1}|"
+unset f; echo "f:1:2=|${f:1:2}|"
+unset f; echo "f::2 =|${f::2}|"
+unset f; echo "f:1: =|${f:1:}|"
+unset f; echo "f:: =|${f::}|"
+
+f=; echo "f =|$f|"
+f=; echo "f:1 =|${f:1}|"
+f=; echo "f:1:2=|${f:1:2}|"
+f=; echo "f::2 =|${f::2}|"
+f=; echo "f:1: =|${f:1:}|"
+f=; echo "f:: =|${f::}|"
+
+f=a; echo "f =|$f|"
+f=a; echo "f:1 =|${f:1}|"
+f=a; echo "f:1:2=|${f:1:2}|"
+f=a; echo "f::2 =|${f::2}|"
+f=a; echo "f:1: =|${f:1:}|"
+f=a; echo "f:: =|${f::}|"
+
+f=0123456789; echo "f =|$f|"
+f=0123456789; echo "f:1 =|${f:1}|"
+f=0123456789; echo "f:1:2=|${f:1:2}|"
+f=0123456789; echo "f::2 =|${f::2}|"
+f=0123456789; echo "f:1: =|${f:1:}|"
+f=0123456789; echo "f:: =|${f::}|"
+
+echo "Substrings from special vars"
+echo '? '"=|$?|"
+echo '?:1 '"=|${?:1}|"
+echo '?:1:2'"=|${?:1:2}|"
+echo '?::2 '"=|${?::2}|"
+echo '?:1: '"=|${?:1:}|"
+echo '?:: '"=|${?::}|"
+set -- 1 2 3 4 5 6 7 8 9 10 11
+echo '# '"=|$#|"
+echo '#:1 '"=|${#:1}|"
+echo '#:1:2'"=|${#:1:2}|"
+echo '#::2 '"=|${#::2}|"
+echo '#:1: '"=|${#:1:}|"
+echo '#:: '"=|${#::}|"
+
+echo "Substrings with expressions"
+f=01234567; echo 'f '"=|$f|"
+f=01234567; echo 'f:1+1:2+2 '"=|${f:1+1:2+2}|"
+f=01234567; echo 'f:-1:2+2 '"=|${f:-1:2+2}|"
+f=01234567; echo 'f:1:f '"=|${f:1:f}|"
+f=01234567; echo 'f:1:$f '"=|${f:1:$f}|"
+f=01234567; echo 'f:1:${f} '"=|${f:1:${f}}|"
+f=01234567; echo 'f:1:${f:3:1} '"=|${f:1:${f:3:1}}|"
+f=01234567; echo 'f:1:1`echo 1`'"=|${f:1:`echo 1`}|"
+
+echo Done