aboutsummaryrefslogtreecommitdiff
path: root/shell/hush_test/hush-redir
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-02 17:55:51 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-02 17:55:51 +0200
commitc4cf542c575068d55368e771abf6c358bfebf5d3 (patch)
treeb916ff4bea0671437b80257fa82283ad8e09faab /shell/hush_test/hush-redir
parent1b73f8471a3694d2e6b035bb7f04e1f4df943f03 (diff)
downloadbusybox-w32-c4cf542c575068d55368e771abf6c358bfebf5d3.tar.gz
busybox-w32-c4cf542c575068d55368e771abf6c358bfebf5d3.tar.bz2
busybox-w32-c4cf542c575068d55368e771abf6c358bfebf5d3.zip
sh testsuite: create hush-redir/* and move files around
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush_test/hush-redir')
-rw-r--r--shell/hush_test/hush-redir/redir1.right12
-rwxr-xr-xshell/hush_test/hush-redir/redir1.tests40
-rw-r--r--shell/hush_test/hush-redir/redir2.right1
-rwxr-xr-xshell/hush_test/hush-redir/redir2.tests2
-rw-r--r--shell/hush_test/hush-redir/redir3.right14
-rwxr-xr-xshell/hush_test/hush-redir/redir3.tests9
-rw-r--r--shell/hush_test/hush-redir/redir4.right18
-rwxr-xr-xshell/hush_test/hush-redir/redir4.tests85
-rw-r--r--shell/hush_test/hush-redir/redir5.right4
-rwxr-xr-xshell/hush_test/hush-redir/redir5.tests13
-rw-r--r--shell/hush_test/hush-redir/redir6.right4
-rwxr-xr-xshell/hush_test/hush-redir/redir6.tests5
-rw-r--r--shell/hush_test/hush-redir/redir7.right3
-rwxr-xr-xshell/hush_test/hush-redir/redir7.tests12
-rw-r--r--shell/hush_test/hush-redir/redir8.right3
-rwxr-xr-xshell/hush_test/hush-redir/redir8.tests15
-rw-r--r--shell/hush_test/hush-redir/redir9.right2
-rwxr-xr-xshell/hush_test/hush-redir/redir9.tests4
-rw-r--r--shell/hush_test/hush-redir/redirA.right2
-rwxr-xr-xshell/hush_test/hush-redir/redirA.tests11
-rw-r--r--shell/hush_test/hush-redir/redir_script.right1
-rwxr-xr-xshell/hush_test/hush-redir/redir_script.tests29
-rw-r--r--shell/hush_test/hush-redir/redir_space.right3
-rwxr-xr-xshell/hush_test/hush-redir/redir_space.tests6
24 files changed, 298 insertions, 0 deletions
diff --git a/shell/hush_test/hush-redir/redir1.right b/shell/hush_test/hush-redir/redir1.right
new file mode 100644
index 000000000..15515d1af
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir1.right
@@ -0,0 +1,12 @@
1Test 0: var:ok
2File created:ok
3Test 1: var:ok
4File created:ok
5Test 2: var:ok
6File created:ok
7Test 3: var:ok
8File created:ok
9Test 4: var:ok
10File created:ok
11Test 5: var:ok
12File created:ok
diff --git a/shell/hush_test/hush-redir/redir1.tests b/shell/hush_test/hush-redir/redir1.tests
new file mode 100755
index 000000000..ef2fbfb77
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir1.tests
@@ -0,0 +1,40 @@
1rm shell_test_$$ 2>/dev/null
2var=bad
3>shell_test_$$ var=ok
4echo "Test 0: var:$var"
5test -f shell_test_$$ && echo "File created:ok"
6
7rm shell_test_$$ 2>/dev/null
8var=bad
9var=ok >shell_test_$$
10echo "Test 1: var:$var"
11test -f shell_test_$$ && echo "File created:ok"
12
13rm shell_test_$$ 2>/dev/null
14var=ok
15true | var=bad >shell_test_$$
16echo "Test 2: var:$var"
17test -f shell_test_$$ && echo "File created:ok"
18
19rm shell_test_$$ 2>/dev/null
20var=bad
21{ var=ok >shell_test_$$; }
22echo "Test 3: var:$var"
23test -f shell_test_$$ && echo "File created:ok"
24
25rm shell_test_$$ 2>/dev/null
26var=ok
27{ var=bad >shell_test_$$; } &
28# cant use usleep as it isnt standard in $PATH --
29# we fail when testing busybox compiled solely as "hush"
30wait
31echo "Test 4: var:$var"
32test -f shell_test_$$ && echo "File created:ok"
33
34rm shell_test_$$ 2>/dev/null
35var=ok
36( var=bad >shell_test_$$ )
37echo "Test 5: var:$var"
38test -f shell_test_$$ && echo "File created:ok"
39
40rm shell_test_$$ 2>/dev/null
diff --git a/shell/hush_test/hush-redir/redir2.right b/shell/hush_test/hush-redir/redir2.right
new file mode 100644
index 000000000..7326d9603
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir2.right
@@ -0,0 +1 @@
Ok
diff --git a/shell/hush_test/hush-redir/redir2.tests b/shell/hush_test/hush-redir/redir2.tests
new file mode 100755
index 000000000..81983cae2
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir2.tests
@@ -0,0 +1,2 @@
1echo NOT SHOWN \2>/dev/null
2echo Ok
diff --git a/shell/hush_test/hush-redir/redir3.right b/shell/hush_test/hush-redir/redir3.right
new file mode 100644
index 000000000..3d20bbf68
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir3.right
@@ -0,0 +1,14 @@
1hush: can't open '/does/not/exist': No such file or directory
2One:1
3hush: can't open '/cant/be/created': No such file or directory
4One:1
5Ok
6hush: can't open '/cant/be/created': No such file or directory
7Zero:0
8hush: can't open '/cant/be/created': No such file or directory
9One:1
10hush: can't open '/cant/be/created': No such file or directory
11One:1
12hush: can't open '/cant/be/created': No such file or directory
13Zero:0
14Done
diff --git a/shell/hush_test/hush-redir/redir3.tests b/shell/hush_test/hush-redir/redir3.tests
new file mode 100755
index 000000000..7c28e4324
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir3.tests
@@ -0,0 +1,9 @@
1echo Error >/does/not/exist; echo One:$?
2t=BAD
3t=Ok >>/cant/be/created; echo One:$?
4echo $t
5! >/cant/be/created; echo Zero:$?
6exec >/cant/be/created; echo One:$?
7exec /bin/true >/cant/be/created; echo One:$?
8! exec /bin/true >/cant/be/created; echo Zero:$?
9echo Done
diff --git a/shell/hush_test/hush-redir/redir4.right b/shell/hush_test/hush-redir/redir4.right
new file mode 100644
index 000000000..ead25f603
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir4.right
@@ -0,0 +1,18 @@
1shell_test
2\shell_test
3\shell_test
4\shell_test
5Here1
6Ok1
7Here2
8Ok2
9Here3
10Ok3
11Here4
12Ok4
13Now with variable refs
14shell_test_1
15\shell_test_1
16\shell_test_1
17\shell_test_1
18Done
diff --git a/shell/hush_test/hush-redir/redir4.tests b/shell/hush_test/hush-redir/redir4.tests
new file mode 100755
index 000000000..c50b8cedf
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir4.tests
@@ -0,0 +1,85 @@
1rm *shell_test* 2>/dev/null
2
3>\shell_test
4echo *shell_test*
5rm *shell_test*
6
7>\\shell_test
8echo *shell_test*
9rm *shell_test*
10
11>"\shell_test"
12echo *shell_test*
13rm *shell_test*
14
15>"\\shell_test"
16echo *shell_test*
17rm *shell_test*
18
19
20cat <<\shell_test
21Here1
22shell_test
23echo Ok1
24
25cat <<\\shell_test
26Here2
27\shell_test
28echo Ok2
29
30cat <<"\shell_test"
31Here3
32\shell_test
33echo Ok3
34
35cat <<"\\shell_test"
36Here4
37\shell_test
38echo Ok4
39
40
41echo Now with variable refs
42i=1
43
44
45>\shell_test_$i
46echo *shell_test*
47rm *shell_test*
48
49>\\shell_test_$i
50echo *shell_test*
51rm *shell_test*
52
53>"\shell_test_$i"
54echo *shell_test*
55rm *shell_test*
56
57>"\\shell_test_$i"
58echo *shell_test*
59rm *shell_test*
60
61echo Done;exit
62# UNFIXED BUG. bash apparently will expand $i even in terminating delimiter.
63# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
64# does not mandate this behavior.
65# This is not likely to be used much in real-world.
66
67cat <<\shell_test_$i
68Here1
69shell_test_$i
70echo Ok1
71
72cat <<\\shell_test_$i
73Here2
74\shell_test_$i
75echo Ok2
76
77cat <<"\shell_test_$i"
78Here3
79\shell_test_$i
80echo Ok3
81
82cat <<"\\shell_test_$i"
83Here4
84\shell_test_$i
85echo Ok4
diff --git a/shell/hush_test/hush-redir/redir5.right b/shell/hush_test/hush-redir/redir5.right
new file mode 100644
index 000000000..52cce4feb
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir5.right
@@ -0,0 +1,4 @@
1Backgrounded pipes shall have their stdin redirected to /dev/null
2Zero:0
3Zero:0
4Done
diff --git a/shell/hush_test/hush-redir/redir5.tests b/shell/hush_test/hush-redir/redir5.tests
new file mode 100755
index 000000000..957f9c81f
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir5.tests
@@ -0,0 +1,13 @@
1echo "Backgrounded pipes shall have their stdin redirected to /dev/null"
2
3# 1. bash does not redirect stdin to /dev/null if it is interactive.
4# hush does it always (this is allowed by standards).
5
6# 2. Failure will result in this script hanging
7
8cat & wait; echo Zero:$?
9
10# This does not work for bash! bash bug?
11cat | cat & wait; echo Zero:$?
12
13echo Done
diff --git a/shell/hush_test/hush-redir/redir6.right b/shell/hush_test/hush-redir/redir6.right
new file mode 100644
index 000000000..a97c4bdf1
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir6.right
@@ -0,0 +1,4 @@
1Testing multiple redirections to same fd
2Hello
3Done1
4Done2
diff --git a/shell/hush_test/hush-redir/redir6.tests b/shell/hush_test/hush-redir/redir6.tests
new file mode 100755
index 000000000..c639ebb2d
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir6.tests
@@ -0,0 +1,5 @@
1echo "Testing multiple redirections to same fd"
2# bug was making us lose fd #1 after this:
3echo Hello >/dev/null 1>&2
4echo Done1
5echo Done2 >&2
diff --git a/shell/hush_test/hush-redir/redir7.right b/shell/hush_test/hush-redir/redir7.right
new file mode 100644
index 000000000..6430b0211
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir7.right
@@ -0,0 +1,3 @@
1Ok
2Ok
3Done
diff --git a/shell/hush_test/hush-redir/redir7.tests b/shell/hush_test/hush-redir/redir7.tests
new file mode 100755
index 000000000..e873a4622
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir7.tests
@@ -0,0 +1,12 @@
1# Chars above 0x7f are used as special codes.
2# 0x81 is CTLESC (see ash.c).
3# The bug was that quoting and unquoting of them
4# was out of sync for redirect filenames.
5
6>unicode.sh
7printf 'echo Ok >uni\x81code\n' >>unicode.sh
8printf 'cat uni\x81code\n' >>unicode.sh
9printf 'cat uni?code\n' >>unicode.sh
10. ./unicode.sh
11rm uni*code*
12echo Done
diff --git a/shell/hush_test/hush-redir/redir8.right b/shell/hush_test/hush-redir/redir8.right
new file mode 100644
index 000000000..6430b0211
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir8.right
@@ -0,0 +1,3 @@
1Ok
2Ok
3Done
diff --git a/shell/hush_test/hush-redir/redir8.tests b/shell/hush_test/hush-redir/redir8.tests
new file mode 100755
index 000000000..2bd386749
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir8.tests
@@ -0,0 +1,15 @@
1# Chars above 0x7f are used as special codes.
2# 0x81 is CTLESC (see ash.c).
3# The bug was that quoting and unquoting of them
4# was out of sync for redirect filenames.
5
6# Subcase when redirect filename is specified in a variable.
7
8>unicode.sh
9printf 'v=uni\x81code\n' >>unicode.sh
10printf 'echo Ok >"$v"\n' >>unicode.sh
11printf 'cat uni\x81code\n' >>unicode.sh
12printf 'cat uni?code\n' >>unicode.sh
13. ./unicode.sh
14rm uni*code*
15echo Done
diff --git a/shell/hush_test/hush-redir/redir9.right b/shell/hush_test/hush-redir/redir9.right
new file mode 100644
index 000000000..34c2512e4
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir9.right
@@ -0,0 +1,2 @@
1Ok
2Done:0
diff --git a/shell/hush_test/hush-redir/redir9.tests b/shell/hush_test/hush-redir/redir9.tests
new file mode 100755
index 000000000..8befa611c
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir9.tests
@@ -0,0 +1,4 @@
1echo Ok >file.tmp
2cat 0<>file.tmp
3echo Done:$?
4rm file.tmp
diff --git a/shell/hush_test/hush-redir/redirA.right b/shell/hush_test/hush-redir/redirA.right
new file mode 100644
index 000000000..31406e336
--- /dev/null
+++ b/shell/hush_test/hush-redir/redirA.right
@@ -0,0 +1,2 @@
1tmp11
2tmp11
diff --git a/shell/hush_test/hush-redir/redirA.tests b/shell/hush_test/hush-redir/redirA.tests
new file mode 100755
index 000000000..56833f938
--- /dev/null
+++ b/shell/hush_test/hush-redir/redirA.tests
@@ -0,0 +1,11 @@
1x="tmp11:tmp22"
2
3# Bug was incorrectly expanding variables in >redir
4echo "${x%:*}" >"${x%:*}"
5echo tmp1*
6rm tmp1*
7
8# Also try unquoted
9echo "${x%:*}" >${x%:*}
10echo tmp1*
11rm tmp1*
diff --git a/shell/hush_test/hush-redir/redir_script.right b/shell/hush_test/hush-redir/redir_script.right
new file mode 100644
index 000000000..6694ed334
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir_script.right
@@ -0,0 +1 @@
Ok: script fd is not closed
diff --git a/shell/hush_test/hush-redir/redir_script.tests b/shell/hush_test/hush-redir/redir_script.tests
new file mode 100755
index 000000000..ccc497d7b
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir_script.tests
@@ -0,0 +1,29 @@
1# Builds a " 3>&- 4>&-" string.
2# Note: one of these fds is a directory opened to /proc/self/fd
3# for globbing. It is unwanted, but I don't know how to filter it out.
4find_fds() {
5 fds=""
6 for f in /proc/self/fd/*; do
7 test "$f" = "/proc/self/fd/0" && continue
8 test "$f" = "/proc/self/fd/1" && continue
9 test "$f" = "/proc/self/fd/2" && continue
10 fds="$fds ${f##*/}>&-"
11 done
12}
13
14find_fds
15fds1="$fds"
16
17# One of the fds is open to the script body
18# Close it while executing something.
19eval "find_fds $fds"
20
21# Shell should not lose that fd. Did it?
22find_fds
23test x"$fds1" = x"$fds" && { echo "Ok: script fd is not closed"; exit 0; }
24
25echo "Bug: script fd is closed"
26echo "fds1:$fds1"
27echo "fds2:$fds"
28exit 1
29
diff --git a/shell/hush_test/hush-redir/redir_space.right b/shell/hush_test/hush-redir/redir_space.right
new file mode 100644
index 000000000..084295204
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir_space.right
@@ -0,0 +1,3 @@
1z1.tmp: 1
2z2.tmp: 1
3"z1.tmp z2.tmp": TEST 0
diff --git a/shell/hush_test/hush-redir/redir_space.tests b/shell/hush_test/hush-redir/redir_space.tests
new file mode 100755
index 000000000..c0b543098
--- /dev/null
+++ b/shell/hush_test/hush-redir/redir_space.tests
@@ -0,0 +1,6 @@
1v='z1.tmp z2.tmp'
2echo TEST >$v
3echo 'z1.tmp:' `cat 'z1.tmp' 2>/dev/null; echo $?`
4echo 'z2.tmp:' `cat 'z2.tmp' 2>/dev/null; echo $?`
5echo '"z1.tmp z2.tmp":' `cat 'z1.tmp z2.tmp' 2>/dev/null; echo $?`
6rm z*.tmp