From 85405c80a28509f2f36c0d4fda8693aac7652d9b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 3 Nov 2015 09:37:40 +0000 Subject: [PATCH] ash: copy function tests from hush testsuite Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash_test/ash-misc/func1.right | 6 ++++++ shell/ash_test/ash-misc/func1.tests | 16 ++++++++++++++++ shell/ash_test/ash-misc/func2.right | 5 +++++ shell/ash_test/ash-misc/func2.tests | 9 +++++++++ shell/ash_test/ash-misc/func3.right | 4 ++++ shell/ash_test/ash-misc/func3.tests | 8 ++++++++ shell/ash_test/ash-misc/func4.right | 2 ++ shell/ash_test/ash-misc/func4.tests | 7 +++++++ shell/ash_test/ash-misc/func5.right | 6 ++++++ shell/ash_test/ash-misc/func5.tests | 13 +++++++++++++ shell/ash_test/ash-misc/func_args1.right | 5 +++++ shell/ash_test/ash-misc/func_args1.tests | 9 +++++++++ shell/ash_test/ash-misc/func_local1.right | 3 +++ shell/ash_test/ash-misc/func_local1.tests | 5 +++++ shell/ash_test/ash-misc/func_local2.right | 14 ++++++++++++++ shell/ash_test/ash-misc/func_local2.tests | 7 +++++++ 16 files changed, 119 insertions(+) create mode 100644 shell/ash_test/ash-misc/func1.right create mode 100755 shell/ash_test/ash-misc/func1.tests create mode 100644 shell/ash_test/ash-misc/func2.right create mode 100755 shell/ash_test/ash-misc/func2.tests create mode 100644 shell/ash_test/ash-misc/func3.right create mode 100755 shell/ash_test/ash-misc/func3.tests create mode 100644 shell/ash_test/ash-misc/func4.right create mode 100755 shell/ash_test/ash-misc/func4.tests create mode 100644 shell/ash_test/ash-misc/func5.right create mode 100755 shell/ash_test/ash-misc/func5.tests create mode 100644 shell/ash_test/ash-misc/func_args1.right create mode 100755 shell/ash_test/ash-misc/func_args1.tests create mode 100644 shell/ash_test/ash-misc/func_local1.right create mode 100755 shell/ash_test/ash-misc/func_local1.tests create mode 100644 shell/ash_test/ash-misc/func_local2.right create mode 100755 shell/ash_test/ash-misc/func_local2.tests diff --git a/shell/ash_test/ash-misc/func1.right b/shell/ash_test/ash-misc/func1.right new file mode 100644 index 000000000..e21665aaf --- /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 000000000..ffb269fad --- /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 000000000..f2a041da7 --- /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 000000000..763203f15 --- /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 000000000..b6d73459a --- /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 000000000..fa6f26a23 --- /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 000000000..0c87e316a --- /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 000000000..74c1b9a46 --- /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 000000000..2c9d316b3 --- /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 000000000..e967208cc --- /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 000000000..2dfb9629b --- /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 000000000..7970795a9 --- /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 000000000..312178366 --- /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 000000000..1d594e20c --- /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 000000000..fe9343ac8 --- /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 000000000..1a9ae559d --- /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