ash: copy function tests from hush testsuite
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/shell/ash_test/ash-misc/func1.right b/shell/ash_test/ash-misc/func1.right
new file mode 100644
index 0000000..e21665a
--- /dev/null
+++ b/shell/ash_test/ash-misc/func1.right
@@ -0,0 +1,6 @@
+Hello
+Zero: 0
+One: 1 Param1: World
+Zero: 0 Param1: Restored
+Multi line function
+One: 1
diff --git a/shell/ash_test/ash-misc/func1.tests b/shell/ash_test/ash-misc/func1.tests
new file mode 100755
index 0000000..ffb269f
--- /dev/null
+++ b/shell/ash_test/ash-misc/func1.tests
@@ -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: $?
diff --git a/shell/ash_test/ash-misc/func2.right b/shell/ash_test/ash-misc/func2.right
new file mode 100644
index 0000000..f2a041d
--- /dev/null
+++ b/shell/ash_test/ash-misc/func2.right
@@ -0,0 +1,5 @@
+First 0
+Second 0
+First 1
+Second 1
+Done
diff --git a/shell/ash_test/ash-misc/func2.tests b/shell/ash_test/ash-misc/func2.tests
new file mode 100755
index 0000000..763203f
--- /dev/null
+++ b/shell/ash_test/ash-misc/func2.tests
@@ -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
diff --git a/shell/ash_test/ash-misc/func3.right b/shell/ash_test/ash-misc/func3.right
new file mode 100644
index 0000000..b6d7345
--- /dev/null
+++ b/shell/ash_test/ash-misc/func3.right
@@ -0,0 +1,4 @@
+One:1
+Zero:0
+One:1
+Five:5
diff --git a/shell/ash_test/ash-misc/func3.tests b/shell/ash_test/ash-misc/func3.tests
new file mode 100755
index 0000000..fa6f26a
--- /dev/null
+++ b/shell/ash_test/ash-misc/func3.tests
@@ -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:$?
diff --git a/shell/ash_test/ash-misc/func4.right b/shell/ash_test/ash-misc/func4.right
new file mode 100644
index 0000000..0c87e31
--- /dev/null
+++ b/shell/ash_test/ash-misc/func4.right
@@ -0,0 +1,2 @@
+24
+Done
diff --git a/shell/ash_test/ash-misc/func4.tests b/shell/ash_test/ash-misc/func4.tests
new file mode 100755
index 0000000..74c1b9a
--- /dev/null
+++ b/shell/ash_test/ash-misc/func4.tests
@@ -0,0 +1,7 @@
+func() {
+ eval "echo \"\${val_${1}}\""
+}
+
+val_x=24
+(func x)
+echo Done
diff --git a/shell/ash_test/ash-misc/func5.right b/shell/ash_test/ash-misc/func5.right
new file mode 100644
index 0000000..2c9d316
--- /dev/null
+++ b/shell/ash_test/ash-misc/func5.right
@@ -0,0 +1,6 @@
+1
+2
+3
+1
+2
+3
diff --git a/shell/ash_test/ash-misc/func5.tests b/shell/ash_test/ash-misc/func5.tests
new file mode 100755
index 0000000..e967208
--- /dev/null
+++ b/shell/ash_test/ash-misc/func5.tests
@@ -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
diff --git a/shell/ash_test/ash-misc/func_args1.right b/shell/ash_test/ash-misc/func_args1.right
new file mode 100644
index 0000000..2dfb962
--- /dev/null
+++ b/shell/ash_test/ash-misc/func_args1.right
@@ -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
diff --git a/shell/ash_test/ash-misc/func_args1.tests b/shell/ash_test/ash-misc/func_args1.tests
new file mode 100755
index 0000000..7970795
--- /dev/null
+++ b/shell/ash_test/ash-misc/func_args1.tests
@@ -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"
diff --git a/shell/ash_test/ash-misc/func_local1.right b/shell/ash_test/ash-misc/func_local1.right
new file mode 100644
index 0000000..3121783
--- /dev/null
+++ b/shell/ash_test/ash-misc/func_local1.right
@@ -0,0 +1,3 @@
+z=a
+z=z
+Done
diff --git a/shell/ash_test/ash-misc/func_local1.tests b/shell/ash_test/ash-misc/func_local1.tests
new file mode 100755
index 0000000..1d594e2
--- /dev/null
+++ b/shell/ash_test/ash-misc/func_local1.tests
@@ -0,0 +1,5 @@
+export z=z
+f() { local z=a; env | grep ^z; }
+f
+env | grep ^z
+echo Done
diff --git a/shell/ash_test/ash-misc/func_local2.right b/shell/ash_test/ash-misc/func_local2.right
new file mode 100644
index 0000000..fe9343a
--- /dev/null
+++ b/shell/ash_test/ash-misc/func_local2.right
@@ -0,0 +1,14 @@
+1
+2
+1
+2
+1
+1
+2
+2
+3
+2
+2
+3
+1
+Done
diff --git a/shell/ash_test/ash-misc/func_local2.tests b/shell/ash_test/ash-misc/func_local2.tests
new file mode 100755
index 0000000..1a9ae55
--- /dev/null
+++ b/shell/ash_test/ash-misc/func_local2.tests
@@ -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