summaryrefslogtreecommitdiffstats
path: root/tests/func.tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 06:17:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 06:17:24 +0000
commit9d8085074991d5c0a42d6fc96a2d1a3ee918aad1 (patch)
treec85bca1e6c11eb872edfc64c524d20f2b7e3307b /tests/func.tests
parentInitial commit. (diff)
downloadbash-70baf9b08adef67074da9e233fa847220a474b78.tar.xz
bash-70baf9b08adef67074da9e233fa847220a474b78.zip
Adding upstream version 5.1.upstream/5.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tests/func.tests192
1 files changed, 192 insertions, 0 deletions
diff --git a/tests/func.tests b/tests/func.tests
new file mode 100644
index 0000000..fffe3d2
--- /dev/null
+++ b/tests/func.tests
@@ -0,0 +1,192 @@
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+a()
+{
+ x=$((x - 1))
+ return 5
+}
+
+b()
+{
+ x=$((x - 1))
+ a
+ echo a returns $?
+ return 4
+}
+
+c()
+{
+ x=$((x - 1))
+ b
+ echo b returns $?
+ return 3
+}
+
+d()
+{
+ x=$((x - 1))
+ c
+ echo c returns $?
+ return 2
+}
+
+e()
+{
+ d
+ echo d returns $?
+ echo in e
+ x=$((x - 1))
+ return $x
+}
+
+f()
+{
+ e
+ echo e returned $?
+ echo x is $x
+ return 0
+}
+
+x=30
+f
+
+# make sure unsetting a local variable preserves the `local' attribute
+f1()
+{
+ local zz
+ zz=abcde
+ echo $zz
+ unset zz
+ zz=defghi
+ echo $zz
+}
+
+zz=ZZ
+echo $zz
+f1
+echo $zz
+
+unset -f f1
+f1()
+{
+ return 5
+}
+
+( f1 )
+echo $?
+
+unset -f f1
+f1()
+{
+ sleep 5
+ return 5
+}
+
+f1 &
+wait
+echo $?
+
+unset -f f1
+
+f1()
+{
+ echo $AVAR
+ printenv AVAR
+}
+
+AVAR=AVAR
+echo $AVAR
+f1
+AVAR=foo f1
+echo $AVAR
+
+unset -f f1
+# make sure subshells can do a `return' if we're executing in a function
+f1()
+{
+ ( return 5 )
+ status=$?
+ echo $status
+ return $status
+}
+
+f1
+echo $?
+
+declare -F f1 # should print just the name
+declare -f f1 # should print the definition, too
+
+# no functions should be exported, right?
+declare -xF
+declare -xf
+
+# FUNCNAME tests
+func2()
+{
+ echo FUNCNAME = $FUNCNAME
+}
+
+func()
+{
+ echo before: FUNCNAME = $FUNCNAME
+ func2
+ echo after: FUNCNAME = $FUNCNAME
+}
+
+echo before: try to assign to FUNCNAME
+FUNCNAME=7
+
+echo outside: FUNCNAME = $FUNCNAME
+func
+echo outside2: FUNCNAME = $FUNCNAME
+
+# test exported functions (and cached exportstr)
+zf()
+{
+ echo this is zf
+}
+export -f zf
+
+${THIS_SH} -c 'type -t zf'
+${THIS_SH} -c 'type zf'
+
+${THIS_SH} ./func1.sub
+
+# tests for functions whose bodies are not group commands, with and without
+# attached redirections
+${THIS_SH} ./func2.sub
+
+# test for some posix-specific function behavior
+${THIS_SH} ./func3.sub
+
+# FUNCNEST testing
+${THIS_SH} ./func4.sub
+
+unset -f myfunction
+myfunction() {
+ echo "bad shell function redirection"
+} >> /dev/null
+
+myfunction
+myfunction | cat
+
+segv()
+{
+ echo foo | return 5
+}
+
+segv
+echo $?
+
+exit 0