diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-25 14:55:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-25 14:55:05 +0200 |
commit | 64925384c9cf5e0d986e183577da286bb3207ce7 (patch) | |
tree | 47688edcf2c0d987800968a9e9d85fc2cd0741e5 | |
parent | 73c47f6c41c97fb452b4747088543f2c2166830a (diff) | |
download | busybox-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>
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 @@ | |||
1 | SHELL: line 1: syntax error: bad substitution | ||
2 | SHELL: 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 $#). | ||
10 | echo _${#+}_ _${#:+}_ | ||
11 | # Forms with non-empty word work as expected in both ash and bash. | ||
12 | echo _${#+z}_ _${#:+z}_ | ||
13 | |||
14 | # now some valid ones | ||
15 | set -- | ||
16 | echo _$1 _${1+} _${1:+} _${1+word} _${1:+word} | ||
17 | |||
18 | set -- aaaa | ||
19 | echo _$1 _${1+} _${1:+} _${1+word} _${1:+word} | ||
20 | |||
21 | unset f | ||
22 | echo _$f _${f+} _${f:+} _${f+word} _${f:+word} | ||
23 | |||
24 | f= | ||
25 | echo _$f _${f+} _${f:+} _${f+word} _${f:+word} | ||
26 | |||
27 | f=fff | ||
28 | echo _$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 @@ | |||
1 | SHELL: line 1: syntax error: bad substitution | ||
2 | SHELL: line 1: syntax error: bad substitution | ||
3 | 0 | ||
4 | 0 | ||
5 | SHELL: line 1: 1: bad variable name | ||
6 | SHELL: line 1: 1: bad variable name | ||
7 | SHELL: line 1: 1: bad variable name | ||
8 | SHELL: 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 | ||
23 | unset f; echo _$f | ||
24 | unset f; echo _${f=} | ||
25 | unset f; echo _${f:=} | ||
26 | unset f; echo _${f=word} | ||
27 | unset f; echo _${f:=word} | ||
28 | |||
29 | f=; echo _$f | ||
30 | f=; echo _${f=} | ||
31 | f=; echo _${f:=} | ||
32 | f=; echo _${f=word} | ||
33 | f=; echo _${f:=word} | ||
34 | |||
35 | f=fff; echo _$f | ||
36 | f=fff; echo _${f=} | ||
37 | f=fff; echo _${f:=} | ||
38 | f=fff; echo _${f=word} | ||
39 | f=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 @@ | |||
1 | SHELL: line 1: syntax error: bad substitution | ||
2 | SHELL: line 1: syntax error: bad substitution | ||
3 | SHELL: line 1: syntax error: bad substitution | ||
4 | SHELL: line 1: syntax error: bad substitution | ||
5 | SHELL: line 1: syntax error: missing '}' | ||
6 | 1 =|| | ||
7 | 1:1 =|| | ||
8 | 1:1:2=|| | ||
9 | 1::2 =|| | ||
10 | 1:1: =|| | ||
11 | 1:: =|| | ||
12 | 1 =|0123| | ||
13 | 1:1 =|123| | ||
14 | 1:1:2=|12| | ||
15 | 1::2 =|01| | ||
16 | 1:1: =|| | ||
17 | 1:: =|| | ||
18 | f =|| | ||
19 | f:1 =|| | ||
20 | f:1:2=|| | ||
21 | f::2 =|| | ||
22 | f:1: =|| | ||
23 | f:: =|| | ||
24 | f =|| | ||
25 | f:1 =|| | ||
26 | f:1:2=|| | ||
27 | f::2 =|| | ||
28 | f:1: =|| | ||
29 | f:: =|| | ||
30 | f =|a| | ||
31 | f:1 =|| | ||
32 | f:1:2=|| | ||
33 | f::2 =|a| | ||
34 | f:1: =|| | ||
35 | f:: =|| | ||
36 | f =|0123456789| | ||
37 | f:1 =|123456789| | ||
38 | f:1:2=|12| | ||
39 | f::2 =|01| | ||
40 | f:1: =|| | ||
41 | f:: =|| | ||
42 | Substrings 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 | #:: =|| | ||
55 | Substrings with expressions | ||
56 | f =|01234567| | ||
57 | f:1+1:2+2 =|2345| | ||
58 | f:-1:2+2 =|01234567| | ||
59 | f:1:f =|1234567| | ||
60 | f:1:$f =|1234567| | ||
61 | f:1:${f} =|1234567| | ||
62 | f:1:${f:3:1} =|123| | ||
63 | f:1:1`echo 1`=|1| | ||
64 | Done | ||
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) | ||
4 | export 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 | ||
17 | set --; echo "1 =|${1}|" | ||
18 | set --; echo "1:1 =|${1:1}|" | ||
19 | set --; echo "1:1:2=|${1:1:2}|" | ||
20 | set --; echo "1::2 =|${1::2}|" | ||
21 | set --; echo "1:1: =|${1:1:}|" | ||
22 | set --; echo "1:: =|${1::}|" | ||
23 | |||
24 | set -- 0123; echo "1 =|${1}|" | ||
25 | set -- 0123; echo "1:1 =|${1:1}|" | ||
26 | set -- 0123; echo "1:1:2=|${1:1:2}|" | ||
27 | set -- 0123; echo "1::2 =|${1::2}|" | ||
28 | set -- 0123; echo "1:1: =|${1:1:}|" | ||
29 | set -- 0123; echo "1:: =|${1::}|" | ||
30 | |||
31 | unset f; echo "f =|$f|" | ||
32 | unset f; echo "f:1 =|${f:1}|" | ||
33 | unset f; echo "f:1:2=|${f:1:2}|" | ||
34 | unset f; echo "f::2 =|${f::2}|" | ||
35 | unset f; echo "f:1: =|${f:1:}|" | ||
36 | unset f; echo "f:: =|${f::}|" | ||
37 | |||
38 | f=; echo "f =|$f|" | ||
39 | f=; echo "f:1 =|${f:1}|" | ||
40 | f=; echo "f:1:2=|${f:1:2}|" | ||
41 | f=; echo "f::2 =|${f::2}|" | ||
42 | f=; echo "f:1: =|${f:1:}|" | ||
43 | f=; echo "f:: =|${f::}|" | ||
44 | |||
45 | f=a; echo "f =|$f|" | ||
46 | f=a; echo "f:1 =|${f:1}|" | ||
47 | f=a; echo "f:1:2=|${f:1:2}|" | ||
48 | f=a; echo "f::2 =|${f::2}|" | ||
49 | f=a; echo "f:1: =|${f:1:}|" | ||
50 | f=a; echo "f:: =|${f::}|" | ||
51 | |||
52 | f=0123456789; echo "f =|$f|" | ||
53 | f=0123456789; echo "f:1 =|${f:1}|" | ||
54 | f=0123456789; echo "f:1:2=|${f:1:2}|" | ||
55 | f=0123456789; echo "f::2 =|${f::2}|" | ||
56 | f=0123456789; echo "f:1: =|${f:1:}|" | ||
57 | f=0123456789; echo "f:: =|${f::}|" | ||
58 | |||
59 | echo "Substrings from special vars" | ||
60 | echo '? '"=|$?|" | ||
61 | echo '?:1 '"=|${?:1}|" | ||
62 | echo '?:1:2'"=|${?:1:2}|" | ||
63 | echo '?::2 '"=|${?::2}|" | ||
64 | echo '?:1: '"=|${?:1:}|" | ||
65 | echo '?:: '"=|${?::}|" | ||
66 | set -- 1 2 3 4 5 6 7 8 9 10 11 | ||
67 | echo '# '"=|$#|" | ||
68 | echo '#:1 '"=|${#:1}|" | ||
69 | echo '#:1:2'"=|${#:1:2}|" | ||
70 | echo '#::2 '"=|${#::2}|" | ||
71 | echo '#:1: '"=|${#:1:}|" | ||
72 | echo '#:: '"=|${#::}|" | ||
73 | |||
74 | echo "Substrings with expressions" | ||
75 | f=01234567; echo 'f '"=|$f|" | ||
76 | f=01234567; echo 'f:1+1:2+2 '"=|${f:1+1:2+2}|" | ||
77 | f=01234567; echo 'f:-1:2+2 '"=|${f:-1:2+2}|" | ||
78 | f=01234567; echo 'f:1:f '"=|${f:1:f}|" | ||
79 | f=01234567; echo 'f:1:$f '"=|${f:1:$f}|" | ||
80 | f=01234567; echo 'f:1:${f} '"=|${f:1:${f}}|" | ||
81 | f=01234567; echo 'f:1:${f:3:1} '"=|${f:1:${f:3:1}}|" | ||
82 | f=01234567; echo 'f:1:1`echo 1`'"=|${f:1:`echo 1`}|" | ||
83 | |||
84 | echo 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 @@ | |||
1 | hush: syntax error: unterminated ${name} | 1 | hush: syntax error: unterminated ${name} |
2 | hush: syntax error: unterminated ${name} | 2 | hush: 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 $#). | ||
6 | echo _${#+}_ _${#:+}_ | 10 | echo _${#+}_ _${#:+}_ |
11 | # Forms with non-empty word work as expected in both ash and bash. | ||
12 | echo _${#+z}_ _${#:+z}_ | ||
7 | 13 | ||
8 | # now some valid ones | 14 | # now some valid ones |
9 | set -- | 15 | set -- |
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 |
22 | unset f; echo _$f | 23 | unset 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) | ||
3 | export var=0123456789 | 4 | export 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}' |