sh testsuite: create hush-redir/* and move files around

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2016-10-02 17:55:51 +02:00
parent 1b73f8471a
commit c4cf542c57
30 changed files with 143 additions and 0 deletions

View File

@@ -1,12 +0,0 @@
Test 0: var:ok
File created:ok
Test 1: var:ok
File created:ok
Test 2: var:ok
File created:ok
Test 3: var:ok
File created:ok
Test 4: var:ok
File created:ok
Test 5: var:ok
File created:ok

View File

@@ -1,40 +0,0 @@
rm shell_test_$$ 2>/dev/null
var=bad
>shell_test_$$ var=ok
echo "Test 0: var:$var"
test -f shell_test_$$ && echo "File created:ok"
rm shell_test_$$ 2>/dev/null
var=bad
var=ok >shell_test_$$
echo "Test 1: var:$var"
test -f shell_test_$$ && echo "File created:ok"
rm shell_test_$$ 2>/dev/null
var=ok
true | var=bad >shell_test_$$
echo "Test 2: var:$var"
test -f shell_test_$$ && echo "File created:ok"
rm shell_test_$$ 2>/dev/null
var=bad
{ var=ok >shell_test_$$; }
echo "Test 3: var:$var"
test -f shell_test_$$ && echo "File created:ok"
rm shell_test_$$ 2>/dev/null
var=ok
{ var=bad >shell_test_$$; } &
# cant use usleep as it isnt standard in $PATH --
# we fail when testing busybox compiled solely as "hush"
wait
echo "Test 4: var:$var"
test -f shell_test_$$ && echo "File created:ok"
rm shell_test_$$ 2>/dev/null
var=ok
( var=bad >shell_test_$$ )
echo "Test 5: var:$var"
test -f shell_test_$$ && echo "File created:ok"
rm shell_test_$$ 2>/dev/null

View File

@@ -1 +0,0 @@
Ok

View File

@@ -1,2 +0,0 @@
echo NOT SHOWN \2>/dev/null
echo Ok

View File

@@ -1,14 +0,0 @@
hush: can't open '/does/not/exist': No such file or directory
One:1
hush: can't open '/cant/be/created': No such file or directory
One:1
Ok
hush: can't open '/cant/be/created': No such file or directory
Zero:0
hush: can't open '/cant/be/created': No such file or directory
One:1
hush: can't open '/cant/be/created': No such file or directory
One:1
hush: can't open '/cant/be/created': No such file or directory
Zero:0
Done

View File

@@ -1,9 +0,0 @@
echo Error >/does/not/exist; echo One:$?
t=BAD
t=Ok >>/cant/be/created; echo One:$?
echo $t
! >/cant/be/created; echo Zero:$?
exec >/cant/be/created; echo One:$?
exec /bin/true >/cant/be/created; echo One:$?
! exec /bin/true >/cant/be/created; echo Zero:$?
echo Done

View File

@@ -1,18 +0,0 @@
shell_test
\shell_test
\shell_test
\shell_test
Here1
Ok1
Here2
Ok2
Here3
Ok3
Here4
Ok4
Now with variable refs
shell_test_1
\shell_test_1
\shell_test_1
\shell_test_1
Done

View File

@@ -1,85 +0,0 @@
rm *shell_test* 2>/dev/null
>\shell_test
echo *shell_test*
rm *shell_test*
>\\shell_test
echo *shell_test*
rm *shell_test*
>"\shell_test"
echo *shell_test*
rm *shell_test*
>"\\shell_test"
echo *shell_test*
rm *shell_test*
cat <<\shell_test
Here1
shell_test
echo Ok1
cat <<\\shell_test
Here2
\shell_test
echo Ok2
cat <<"\shell_test"
Here3
\shell_test
echo Ok3
cat <<"\\shell_test"
Here4
\shell_test
echo Ok4
echo Now with variable refs
i=1
>\shell_test_$i
echo *shell_test*
rm *shell_test*
>\\shell_test_$i
echo *shell_test*
rm *shell_test*
>"\shell_test_$i"
echo *shell_test*
rm *shell_test*
>"\\shell_test_$i"
echo *shell_test*
rm *shell_test*
echo Done;exit
# UNFIXED BUG. bash apparently will expand $i even in terminating delimiter.
# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
# does not mandate this behavior.
# This is not likely to be used much in real-world.
cat <<\shell_test_$i
Here1
shell_test_$i
echo Ok1
cat <<\\shell_test_$i
Here2
\shell_test_$i
echo Ok2
cat <<"\shell_test_$i"
Here3
\shell_test_$i
echo Ok3
cat <<"\\shell_test_$i"
Here4
\shell_test_$i
echo Ok4

View File

@@ -1,4 +0,0 @@
Backgrounded pipes shall have their stdin redirected to /dev/null
Zero:0
Zero:0
Done

View File

@@ -1,13 +0,0 @@
echo "Backgrounded pipes shall have their stdin redirected to /dev/null"
# 1. bash does not redirect stdin to /dev/null if it is interactive.
# hush does it always (this is allowed by standards).
# 2. Failure will result in this script hanging
cat & wait; echo Zero:$?
# This does not work for bash! bash bug?
cat | cat & wait; echo Zero:$?
echo Done

View File

@@ -1,4 +0,0 @@
Testing multiple redirections to same fd
Hello
Done1
Done2

View File

@@ -1,5 +0,0 @@
echo "Testing multiple redirections to same fd"
# bug was making us lose fd #1 after this:
echo Hello >/dev/null 1>&2
echo Done1
echo Done2 >&2

View File

@@ -1 +0,0 @@
Ok: script fd is not closed

View File

@@ -1,29 +0,0 @@
# Builds a " 3>&- 4>&-" string.
# Note: one of these fds is a directory opened to /proc/self/fd
# for globbing. It is unwanted, but I don't know how to filter it out.
find_fds() {
fds=""
for f in /proc/self/fd/*; do
test "$f" = "/proc/self/fd/0" && continue
test "$f" = "/proc/self/fd/1" && continue
test "$f" = "/proc/self/fd/2" && continue
fds="$fds ${f##*/}>&-"
done
}
find_fds
fds1="$fds"
# One of the fds is open to the script body
# Close it while executing something.
eval "find_fds $fds"
# Shell should not lose that fd. Did it?
find_fds
test x"$fds1" = x"$fds" && { echo "Ok: script fd is not closed"; exit 0; }
echo "Bug: script fd is closed"
echo "fds1:$fds1"
echo "fds2:$fds"
exit 1