ash: copy function tests from hush testsuite

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Ron Yorston 2015-11-03 09:37:40 +00:00 committed by Denys Vlasenko
parent 2cf4591413
commit 85405c80a2
16 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,6 @@
Hello
Zero: 0
One: 1 Param1: World
Zero: 0 Param1: Restored
Multi line function
One: 1

View File

@ -0,0 +1,16 @@
f() { echo Hello; }
g () { echo One: $# Param1: $1; }
h ( )
{
echo -n 'Multi ' && echo -n 'line '
echo function
false
}
f
echo Zero: $?
set -- Restored
{ g World; }
echo Zero: $? Param1: $1
( h )
echo One: $?

View File

@ -0,0 +1,5 @@
First 0
Second 0
First 1
Second 1
Done

View File

@ -0,0 +1,9 @@
i=0
while test $i != 2; do
f() { echo First $i; }
f
f() { echo Second $i; }
f
: $((i++))
done
echo Done

View File

@ -0,0 +1,4 @@
One:1
Zero:0
One:1
Five:5

View File

@ -0,0 +1,8 @@
f() { false; return; echo BAD; };
{ f; echo One:$?; }; echo Zero:$?
f() { false; return; };
f; echo One:$?
f() { return 5; };
f; echo Five:$?

View File

@ -0,0 +1,2 @@
24
Done

View File

@ -0,0 +1,7 @@
func() {
eval "echo \"\${val_${1}}\""
}
val_x=24
(func x)
echo Done

View File

@ -0,0 +1,6 @@
1
2
3
1
2
3

View File

@ -0,0 +1,13 @@
f() { echo $1; }
f 1
f() ( echo $1; )
f 2
f() ( echo $1 )
f 3
f() for i in 1 2 3; do
echo $i
done
f

View File

@ -0,0 +1,5 @@
params: a b c
'f 1 2 3' called
params: a b c
'f 1 2 3' called
params: a b c

View File

@ -0,0 +1,9 @@
f() { echo "'f $1 $2 $3' called"; }
set -- a b c
echo "params: $1 $2 $3"
f 1 2 3
echo "params: $1 $2 $3"
true | f 1 2 3
echo "params: $1 $2 $3"

View File

@ -0,0 +1,3 @@
z=a
z=z
Done

View File

@ -0,0 +1,5 @@
export z=z
f() { local z=a; env | grep ^z; }
f
env | grep ^z
echo Done

View File

@ -0,0 +1,14 @@
1
2
1
2
1
1
2
2
3
2
2
3
1
Done

View File

@ -0,0 +1,7 @@
x=1
f() { echo $x; local x=$((x+1)); echo $x; }
g() { f; echo $x; f; local x=$((x+1)); f; echo $x; f; }
f
g
echo $x
echo Done