diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-10-31 03:34:07 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-10-31 03:34:07 +0100 |
commit | d2241f59022c38d4b171e56eea42e216ecccfdd9 (patch) | |
tree | edb75c2530f493c9e3f193f346d8125fe79c107f /shell/hush_test | |
parent | 112453acf24520b4655f9f36da41d8ac591b1a60 (diff) | |
download | busybox-w32-d2241f59022c38d4b171e56eea42e216ecccfdd9.tar.gz busybox-w32-d2241f59022c38d4b171e56eea42e216ecccfdd9.tar.bz2 busybox-w32-d2241f59022c38d4b171e56eea42e216ecccfdd9.zip |
shell: better support of [[ ]] bashism
Still rather rudimentary for ash
function old new delta
binop 433 589 +156
check_operator 65 101 +36
done_word 736 769 +33
test_main 405 418 +13
parse_stream 2227 2238 +11
ops_texts 124 133 +9
ops_table 80 86 +6
run_pipe 1557 1562 +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/0 up/down: 269/0) Total: 269 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush_test')
-rw-r--r-- | shell/hush_test/hush-test2/andor1.right | 6 | ||||
-rwxr-xr-x | shell/hush_test/hush-test2/andor1.tests | 7 | ||||
-rw-r--r-- | shell/hush_test/hush-test2/noglob1.right | 2 | ||||
-rwxr-xr-x | shell/hush_test/hush-test2/noglob1.tests | 3 | ||||
-rw-r--r-- | shell/hush_test/hush-test2/strops1.right | 8 | ||||
-rwxr-xr-x | shell/hush_test/hush-test2/strops1.tests | 15 | ||||
-rw-r--r-- | shell/hush_test/hush-test2/strops2.right | 6 | ||||
-rwxr-xr-x | shell/hush_test/hush-test2/strops2.tests | 12 | ||||
-rw-r--r-- | shell/hush_test/hush-test2/strops3.right | 7 | ||||
-rwxr-xr-x | shell/hush_test/hush-test2/strops3.tests | 13 |
10 files changed, 79 insertions, 0 deletions
diff --git a/shell/hush_test/hush-test2/andor1.right b/shell/hush_test/hush-test2/andor1.right new file mode 100644 index 000000000..038c7a681 --- /dev/null +++ b/shell/hush_test/hush-test2/andor1.right | |||
@@ -0,0 +1,6 @@ | |||
1 | 1:YES | ||
2 | 2:no | ||
3 | 3:YES | ||
4 | 4:YES | ||
5 | 5:no | ||
6 | 6:no | ||
diff --git a/shell/hush_test/hush-test2/andor1.tests b/shell/hush_test/hush-test2/andor1.tests new file mode 100755 index 000000000..c449de7e6 --- /dev/null +++ b/shell/hush_test/hush-test2/andor1.tests | |||
@@ -0,0 +1,7 @@ | |||
1 | e='' | ||
2 | [[ a && b ]] && echo 1:YES | ||
3 | [[ a && '' ]] || echo 2:no | ||
4 | [[ a || b ]] && echo 3:YES | ||
5 | [[ '' || b ]] && echo 4:YES | ||
6 | [[ "" || "$e" ]] || echo 5:no | ||
7 | [[ "" || $e ]] || echo 6:no | ||
diff --git a/shell/hush_test/hush-test2/noglob1.right b/shell/hush_test/hush-test2/noglob1.right new file mode 100644 index 000000000..d0c3f1d8e --- /dev/null +++ b/shell/hush_test/hush-test2/noglob1.right | |||
@@ -0,0 +1,2 @@ | |||
1 | 1:YES:0 | ||
2 | 2:YES:0 | ||
diff --git a/shell/hush_test/hush-test2/noglob1.tests b/shell/hush_test/hush-test2/noglob1.tests new file mode 100755 index 000000000..963bacbd3 --- /dev/null +++ b/shell/hush_test/hush-test2/noglob1.tests | |||
@@ -0,0 +1,3 @@ | |||
1 | v='*.tests' | ||
2 | [[ *.tests ]]; echo 1:YES:$? | ||
3 | [[ $v ]]; echo 2:YES:$? | ||
diff --git a/shell/hush_test/hush-test2/strops1.right b/shell/hush_test/hush-test2/strops1.right new file mode 100644 index 000000000..590496301 --- /dev/null +++ b/shell/hush_test/hush-test2/strops1.right | |||
@@ -0,0 +1,8 @@ | |||
1 | 1:YES:0 | ||
2 | 2:YES:0 | ||
3 | 3:YES:0 | ||
4 | 4:YES:0 | ||
5 | 5:YES:0 | ||
6 | 6:YES:0 | ||
7 | 7:YES:0 | ||
8 | 8:no:1 | ||
diff --git a/shell/hush_test/hush-test2/strops1.tests b/shell/hush_test/hush-test2/strops1.tests new file mode 100755 index 000000000..bb24e2a2f --- /dev/null +++ b/shell/hush_test/hush-test2/strops1.tests | |||
@@ -0,0 +1,15 @@ | |||
1 | v='*.z' | ||
2 | [[ a.z = *.z ]]; echo 1:YES:$? | ||
3 | [[ a.z == $v ]]; echo 2:YES:$? | ||
4 | |||
5 | # wildcards can match a slash | ||
6 | [[ a/b = a*b ]]; echo 3:YES:$? | ||
7 | [[ a/b == a?b ]]; echo 4:YES:$? | ||
8 | |||
9 | # wildcards can match a leading dot | ||
10 | [[ a/.b = a/*b ]]; echo 5:YES:$? | ||
11 | [[ a/.b == a/?b ]]; echo 6:YES:$? | ||
12 | |||
13 | # wildcards can be escaped | ||
14 | [[ abc = a*c ]]; echo 7:YES:$? | ||
15 | [[ abc == a\*c ]]; echo 8:no:$? | ||
diff --git a/shell/hush_test/hush-test2/strops2.right b/shell/hush_test/hush-test2/strops2.right new file mode 100644 index 000000000..8ddb4b0f0 --- /dev/null +++ b/shell/hush_test/hush-test2/strops2.right | |||
@@ -0,0 +1,6 @@ | |||
1 | 1:ERR2:2 | ||
2 | 2:YES:0 | ||
3 | 3:YES:0 | ||
4 | 4:YES:0 | ||
5 | 5:no:1 | ||
6 | 6:YES:0 | ||
diff --git a/shell/hush_test/hush-test2/strops2.tests b/shell/hush_test/hush-test2/strops2.tests new file mode 100755 index 000000000..ab325bc9f --- /dev/null +++ b/shell/hush_test/hush-test2/strops2.tests | |||
@@ -0,0 +1,12 @@ | |||
1 | # malformed regex | ||
2 | [[ a =~ * ]]; echo 1:ERR2:$? | ||
3 | |||
4 | [[ a/b =~ a.b ]]; echo 2:YES:$? | ||
5 | [[ a/b =~ /*b ]]; echo 3:YES:$? | ||
6 | |||
7 | v='[]b.-]' | ||
8 | [[ a/.b] =~ $v ]]; echo 4:YES:$? | ||
9 | |||
10 | v=']b.-' | ||
11 | [[ a/.b] =~ $v ]]; echo 5:no:$? | ||
12 | [[ a/.b] =~ [$v] ]]; echo 6:YES:$? | ||
diff --git a/shell/hush_test/hush-test2/strops3.right b/shell/hush_test/hush-test2/strops3.right new file mode 100644 index 000000000..14cc04fdc --- /dev/null +++ b/shell/hush_test/hush-test2/strops3.right | |||
@@ -0,0 +1,7 @@ | |||
1 | 1:YES:0 | ||
2 | 2:YES:0 | ||
3 | 3:no:1 | ||
4 | 4:YES:0 | ||
5 | 2u:YES:0 | ||
6 | 3u:YES:0 | ||
7 | 4u:YES:0 | ||
diff --git a/shell/hush_test/hush-test2/strops3.tests b/shell/hush_test/hush-test2/strops3.tests new file mode 100755 index 000000000..927476671 --- /dev/null +++ b/shell/hush_test/hush-test2/strops3.tests | |||
@@ -0,0 +1,13 @@ | |||
1 | # regex should accept '+' operator | ||
2 | [[ abcdef =~ a[b-z]+ ]]; echo 1:YES:$? | ||
3 | |||
4 | # newline matches by "match any" patterns | ||
5 | v=' | ||
6 | ' | ||
7 | [[ "$v" =~ . ]]; echo 2:YES:$? | ||
8 | [[ "$v" =~ "[$v]" ]]; echo 3:no:$? # hmm bash does return 1... why? | ||
9 | [[ "$v" =~ [^a] ]]; echo 4:YES:$? | ||
10 | # should work even without quotes: | ||
11 | [[ $v =~ . ]]; echo 2u:YES:$? | ||
12 | [[ $v =~ [$v] ]]; echo 3u:YES:$? | ||
13 | [[ $v =~ [^a] ]]; echo 4u:YES:$? | ||