aboutsummaryrefslogtreecommitdiff
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
parent73c47f6c41c97fb452b4747088543f2c2166830a (diff)
downloadbusybox-w32-64925384c9cf5e0d986e183577da286bb3207ce7.tar.gz
busybox-w32-64925384c9cf5e0d986e183577da286bb3207ce7.tar.bz2
busybox-w32-64925384c9cf5e0d986e183577da286bb3207ce7.zip
ash: add a few tests from hush-vars/*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash_test/ash-vars/param_expand_alt.right9
-rwxr-xr-xshell/ash_test/ash-vars/param_expand_alt.tests28
-rw-r--r--shell/ash_test/ash-vars/param_expand_assign.right27
-rwxr-xr-xshell/ash_test/ash-vars/param_expand_assign.tests39
-rw-r--r--shell/ash_test/ash-vars/param_expand_bash_substring.right64
-rwxr-xr-xshell/ash_test/ash-vars/param_expand_bash_substring.tests84
-rw-r--r--shell/hush_test/hush-vars/param_expand_alt.right1
-rwxr-xr-xshell/hush_test/hush-vars/param_expand_alt.tests14
-rwxr-xr-xshell/hush_test/hush-vars/param_expand_assign.tests27
-rwxr-xr-xshell/hush_test/hush-vars/param_expand_bash_substring.tests13
10 files changed, 283 insertions, 23 deletions
diff --git a/shell/ash_test/ash-vars/param_expand_alt.right b/shell/ash_test/ash-vars/param_expand_alt.right
new file mode 100644
index 000000000..c733c147a
--- /dev/null
+++ b/shell/ash_test/ash-vars/param_expand_alt.right
@@ -0,0 +1,9 @@
1SHELL: line 1: syntax error: bad substitution
2SHELL: line 1: syntax error: bad substitution
3_0_ __
4_z_ _z_
5_ _ _ _ _
6_aaaa _ _ _word _word
7_ _ _ _ _
8_ _ _ _word _
9_fff _ _ _word _word
diff --git a/shell/ash_test/ash-vars/param_expand_alt.tests b/shell/ash_test/ash-vars/param_expand_alt.tests
new file mode 100755
index 000000000..c9c4249af
--- /dev/null
+++ b/shell/ash_test/ash-vars/param_expand_alt.tests
@@ -0,0 +1,28 @@
1# First try some invalid patterns. Do in subshell due to parsing error.
2# (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
3"$THIS_SH" -c 'echo ${+} ; echo moo' SHELL
4"$THIS_SH" -c 'echo ${:+} ; echo moo' SHELL
5
6# now some funky ones.
7# ${V+word} "if V unset, then substitute nothing, else substitute word"
8# ${V:+word} "if V unset or '', then substitute nothing, else substitute word"
9# bash doesn't accept ${#+}. ash prints 0 (not $#).
10echo _${#+}_ _${#:+}_
11# Forms with non-empty word work as expected in both ash and bash.
12echo _${#+z}_ _${#:+z}_
13
14# now some valid ones
15set --
16echo _$1 _${1+} _${1:+} _${1+word} _${1:+word}
17
18set -- aaaa
19echo _$1 _${1+} _${1:+} _${1+word} _${1:+word}
20
21unset f
22echo _$f _${f+} _${f:+} _${f+word} _${f:+word}
23
24f=
25echo _$f _${f+} _${f:+} _${f+word} _${f:+word}
26
27f=fff
28echo _$f _${f+} _${f:+} _${f+word} _${f:+word}
diff --git a/shell/ash_test/ash-vars/param_expand_assign.right b/shell/ash_test/ash-vars/param_expand_assign.right
new file mode 100644
index 000000000..9b07d8cd4
--- /dev/null
+++ b/shell/ash_test/ash-vars/param_expand_assign.right
@@ -0,0 +1,27 @@
1SHELL: line 1: syntax error: bad substitution
2SHELL: line 1: syntax error: bad substitution
30
40
5SHELL: line 1: 1: bad variable name
6SHELL: line 1: 1: bad variable name
7SHELL: line 1: 1: bad variable name
8SHELL: line 1: 1: bad variable name
9_aa
10_aa
11_aa
12_aa
13_
14_
15_
16_word
17_word
18_
19_
20_
21_
22_word
23_fff
24_fff
25_fff
26_fff
27_fff
diff --git a/shell/ash_test/ash-vars/param_expand_assign.tests b/shell/ash_test/ash-vars/param_expand_assign.tests
new file mode 100755
index 000000000..79de95613
--- /dev/null
+++ b/shell/ash_test/ash-vars/param_expand_assign.tests
@@ -0,0 +1,39 @@
1# First try some invalid patterns. Do in subshell due to parsing error.
2# (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
3"$THIS_SH" -c 'echo ${=}' SHELL
4"$THIS_SH" -c 'echo ${:=}' SHELL
5
6# now some funky ones
7"$THIS_SH" -c 'echo ${#=}' SHELL
8"$THIS_SH" -c 'echo ${#:=}' SHELL
9
10# should error out
11"$THIS_SH" -c 'set --; echo _${1=}' SHELL
12"$THIS_SH" -c 'set --; echo _${1:=}' SHELL
13"$THIS_SH" -c 'set --; echo _${1=word}' SHELL
14"$THIS_SH" -c 'set --; echo _${1:=word}' SHELL
15
16# should not error
17"$THIS_SH" -c 'set aa; echo _${1=}' SHELL
18"$THIS_SH" -c 'set aa; echo _${1:=}' SHELL
19"$THIS_SH" -c 'set aa; echo _${1=word}' SHELL
20"$THIS_SH" -c 'set aa; echo _${1:=word}' SHELL
21
22# should work fine
23unset f; echo _$f
24unset f; echo _${f=}
25unset f; echo _${f:=}
26unset f; echo _${f=word}
27unset f; echo _${f:=word}
28
29f=; echo _$f
30f=; echo _${f=}
31f=; echo _${f:=}
32f=; echo _${f=word}
33f=; echo _${f:=word}
34
35f=fff; echo _$f
36f=fff; echo _${f=}
37f=fff; echo _${f:=}
38f=fff; echo _${f=word}
39f=fff; echo _${f:=word}
diff --git a/shell/ash_test/ash-vars/param_expand_bash_substring.right b/shell/ash_test/ash-vars/param_expand_bash_substring.right
new file mode 100644
index 000000000..9ad6dbcad
--- /dev/null
+++ b/shell/ash_test/ash-vars/param_expand_bash_substring.right
@@ -0,0 +1,64 @@
1SHELL: line 1: syntax error: bad substitution
2SHELL: line 1: syntax error: bad substitution
3SHELL: line 1: syntax error: bad substitution
4SHELL: line 1: syntax error: bad substitution
5SHELL: line 1: syntax error: missing '}'
61 =||
71:1 =||
81:1:2=||
91::2 =||
101:1: =||
111:: =||
121 =|0123|
131:1 =|123|
141:1:2=|12|
151::2 =|01|
161:1: =||
171:: =||
18f =||
19f:1 =||
20f:1:2=||
21f::2 =||
22f:1: =||
23f:: =||
24f =||
25f:1 =||
26f:1:2=||
27f::2 =||
28f:1: =||
29f:: =||
30f =|a|
31f:1 =||
32f:1:2=||
33f::2 =|a|
34f:1: =||
35f:: =||
36f =|0123456789|
37f:1 =|123456789|
38f:1:2=|12|
39f::2 =|01|
40f:1: =||
41f:: =||
42Substrings from special vars
43? =|0|
44?:1 =||
45?:1:2=||
46?::2 =|0|
47?:1: =||
48?:: =||
49# =|11|
50#:1 =|1|
51#:1:2=|1|
52#::2 =|11|
53#:1: =||
54#:: =||
55Substrings with expressions
56f =|01234567|
57f:1+1:2+2 =|2345|
58f:-1:2+2 =|01234567|
59f:1:f =|1234567|
60f:1:$f =|1234567|
61f:1:${f} =|1234567|
62f:1:${f:3:1} =|123|
63f:1:1`echo 1`=|1|
64Done
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 @@
1# first try some invalid patterns
2# do all of these in subshells since it's supposed to error out
3# (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
4export var=0123456789
5"$THIS_SH" -c 'echo ${:}' SHELL
6"$THIS_SH" -c 'echo ${::}' SHELL
7"$THIS_SH" -c 'echo ${:1}' SHELL
8"$THIS_SH" -c 'echo ${::1}' SHELL
9
10#this also is not valid in bash, hush accepts it:
11"$THIS_SH" -c 'echo ${var:}' SHELL
12
13# then some funky ones
14# UNFIXED BUG: this should work: "$THIS_SH" -c 'echo ${?:0}'
15
16# now some valid ones
17set --; echo "1 =|${1}|"
18set --; echo "1:1 =|${1:1}|"
19set --; echo "1:1:2=|${1:1:2}|"
20set --; echo "1::2 =|${1::2}|"
21set --; echo "1:1: =|${1:1:}|"
22set --; echo "1:: =|${1::}|"
23
24set -- 0123; echo "1 =|${1}|"
25set -- 0123; echo "1:1 =|${1:1}|"
26set -- 0123; echo "1:1:2=|${1:1:2}|"
27set -- 0123; echo "1::2 =|${1::2}|"
28set -- 0123; echo "1:1: =|${1:1:}|"
29set -- 0123; echo "1:: =|${1::}|"
30
31unset f; echo "f =|$f|"
32unset f; echo "f:1 =|${f:1}|"
33unset f; echo "f:1:2=|${f:1:2}|"
34unset f; echo "f::2 =|${f::2}|"
35unset f; echo "f:1: =|${f:1:}|"
36unset f; echo "f:: =|${f::}|"
37
38f=; echo "f =|$f|"
39f=; echo "f:1 =|${f:1}|"
40f=; echo "f:1:2=|${f:1:2}|"
41f=; echo "f::2 =|${f::2}|"
42f=; echo "f:1: =|${f:1:}|"
43f=; echo "f:: =|${f::}|"
44
45f=a; echo "f =|$f|"
46f=a; echo "f:1 =|${f:1}|"
47f=a; echo "f:1:2=|${f:1:2}|"
48f=a; echo "f::2 =|${f::2}|"
49f=a; echo "f:1: =|${f:1:}|"
50f=a; echo "f:: =|${f::}|"
51
52f=0123456789; echo "f =|$f|"
53f=0123456789; echo "f:1 =|${f:1}|"
54f=0123456789; echo "f:1:2=|${f:1:2}|"
55f=0123456789; echo "f::2 =|${f::2}|"
56f=0123456789; echo "f:1: =|${f:1:}|"
57f=0123456789; echo "f:: =|${f::}|"
58
59echo "Substrings from special vars"
60echo '? '"=|$?|"
61echo '?:1 '"=|${?:1}|"
62echo '?:1:2'"=|${?:1:2}|"
63echo '?::2 '"=|${?::2}|"
64echo '?:1: '"=|${?:1:}|"
65echo '?:: '"=|${?::}|"
66set -- 1 2 3 4 5 6 7 8 9 10 11
67echo '# '"=|$#|"
68echo '#:1 '"=|${#:1}|"
69echo '#:1:2'"=|${#:1:2}|"
70echo '#::2 '"=|${#::2}|"
71echo '#:1: '"=|${#:1:}|"
72echo '#:: '"=|${#::}|"
73
74echo "Substrings with expressions"
75f=01234567; echo 'f '"=|$f|"
76f=01234567; echo 'f:1+1:2+2 '"=|${f:1+1:2+2}|"
77f=01234567; echo 'f:-1:2+2 '"=|${f:-1:2+2}|"
78f=01234567; echo 'f:1:f '"=|${f:1:f}|"
79f=01234567; echo 'f:1:$f '"=|${f:1:$f}|"
80f=01234567; echo 'f:1:${f} '"=|${f:1:${f}}|"
81f=01234567; echo 'f:1:${f:3:1} '"=|${f:1:${f:3:1}}|"
82f=01234567; echo 'f:1:1`echo 1`'"=|${f:1:`echo 1`}|"
83
84echo Done
diff --git a/shell/hush_test/hush-vars/param_expand_alt.right b/shell/hush_test/hush-vars/param_expand_alt.right
index 67f18d69c..4f9eb2907 100644
--- a/shell/hush_test/hush-vars/param_expand_alt.right
+++ b/shell/hush_test/hush-vars/param_expand_alt.right
@@ -1,6 +1,7 @@
1hush: syntax error: unterminated ${name} 1hush: syntax error: unterminated ${name}
2hush: syntax error: unterminated ${name} 2hush: syntax error: unterminated ${name}
3__ __ 3__ __
4_z_ _z_
4_ _ _ _ _ 5_ _ _ _ _
5_aaaa _ _ _word _word 6_aaaa _ _ _word _word
6_ _ _ _ _ 7_ _ _ _ _
diff --git a/shell/hush_test/hush-vars/param_expand_alt.tests b/shell/hush_test/hush-vars/param_expand_alt.tests
index 3b646b142..c9c4249af 100755
--- a/shell/hush_test/hush-vars/param_expand_alt.tests
+++ b/shell/hush_test/hush-vars/param_expand_alt.tests
@@ -1,9 +1,15 @@
1# first try some invalid patterns (do in subshell due to parsing error) 1# First try some invalid patterns. Do in subshell due to parsing error.
2"$THIS_SH" -c 'echo ${+} ; echo moo' 2# (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
3"$THIS_SH" -c 'echo ${:+} ; echo moo' 3"$THIS_SH" -c 'echo ${+} ; echo moo' SHELL
4"$THIS_SH" -c 'echo ${:+} ; echo moo' SHELL
4 5
5# now some funky ones. (bash doesn't accept ${#+}) 6# now some funky ones.
7# ${V+word} "if V unset, then substitute nothing, else substitute word"
8# ${V:+word} "if V unset or '', then substitute nothing, else substitute word"
9# bash doesn't accept ${#+}. ash prints 0 (not $#).
6echo _${#+}_ _${#:+}_ 10echo _${#+}_ _${#:+}_
11# Forms with non-empty word work as expected in both ash and bash.
12echo _${#+z}_ _${#:+z}_
7 13
8# now some valid ones 14# now some valid ones
9set -- 15set --
diff --git a/shell/hush_test/hush-vars/param_expand_assign.tests b/shell/hush_test/hush-vars/param_expand_assign.tests
index 149cb20df..79de95613 100755
--- a/shell/hush_test/hush-vars/param_expand_assign.tests
+++ b/shell/hush_test/hush-vars/param_expand_assign.tests
@@ -1,22 +1,23 @@
1# first try some invalid patterns (do in subshell due to parsing error) 1# First try some invalid patterns. Do in subshell due to parsing error.
2"$THIS_SH" -c 'echo ${=}' 2# (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
3"$THIS_SH" -c 'echo ${:=}' 3"$THIS_SH" -c 'echo ${=}' SHELL
4"$THIS_SH" -c 'echo ${:=}' SHELL
4 5
5# now some funky ones 6# now some funky ones
6"$THIS_SH" -c 'echo ${#=}' 7"$THIS_SH" -c 'echo ${#=}' SHELL
7"$THIS_SH" -c 'echo ${#:=}' 8"$THIS_SH" -c 'echo ${#:=}' SHELL
8 9
9# should error out 10# should error out
10"$THIS_SH" -c 'set --; echo _${1=}' 11"$THIS_SH" -c 'set --; echo _${1=}' SHELL
11"$THIS_SH" -c 'set --; echo _${1:=}' 12"$THIS_SH" -c 'set --; echo _${1:=}' SHELL
12"$THIS_SH" -c 'set --; echo _${1=word}' 13"$THIS_SH" -c 'set --; echo _${1=word}' SHELL
13"$THIS_SH" -c 'set --; echo _${1:=word}' 14"$THIS_SH" -c 'set --; echo _${1:=word}' SHELL
14 15
15# should not error 16# should not error
16"$THIS_SH" -c 'set aa; echo _${1=}' 17"$THIS_SH" -c 'set aa; echo _${1=}' SHELL
17"$THIS_SH" -c 'set aa; echo _${1:=}' 18"$THIS_SH" -c 'set aa; echo _${1:=}' SHELL
18"$THIS_SH" -c 'set aa; echo _${1=word}' 19"$THIS_SH" -c 'set aa; echo _${1=word}' SHELL
19"$THIS_SH" -c 'set aa; echo _${1:=word}' 20"$THIS_SH" -c 'set aa; echo _${1:=word}' SHELL
20 21
21# should work fine 22# should work fine
22unset f; echo _$f 23unset f; echo _$f
diff --git a/shell/hush_test/hush-vars/param_expand_bash_substring.tests b/shell/hush_test/hush-vars/param_expand_bash_substring.tests
index 5c9552dba..cce9f123e 100755
--- a/shell/hush_test/hush-vars/param_expand_bash_substring.tests
+++ b/shell/hush_test/hush-vars/param_expand_bash_substring.tests
@@ -1,13 +1,14 @@
1# first try some invalid patterns 1# first try some invalid patterns
2# do all of these in subshells since it's supposed to error out 2# do all of these in subshells since it's supposed to error out
3# (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
3export var=0123456789 4export var=0123456789
4"$THIS_SH" -c 'echo ${:}' 5"$THIS_SH" -c 'echo ${:}' SHELL
5"$THIS_SH" -c 'echo ${::}' 6"$THIS_SH" -c 'echo ${::}' SHELL
6"$THIS_SH" -c 'echo ${:1}' 7"$THIS_SH" -c 'echo ${:1}' SHELL
7"$THIS_SH" -c 'echo ${::1}' 8"$THIS_SH" -c 'echo ${::1}' SHELL
8 9
9#this also is not valid in bash, but we accept it: 10#this also is not valid in bash, hush accepts it:
10"$THIS_SH" -c 'echo ${var:}' 11"$THIS_SH" -c 'echo ${var:}' SHELL
11 12
12# then some funky ones 13# then some funky ones
13# UNFIXED BUG: this should work: "$THIS_SH" -c 'echo ${?:0}' 14# UNFIXED BUG: this should work: "$THIS_SH" -c 'echo ${?:0}'