]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/func.tests
Bash-4.3 patch 7
[thirdparty/bash.git] / tests / func.tests
CommitLineData
d166f048
JA
1a()
2{
3 x=$((x - 1))
4 return 5
5}
6
7b()
8{
9 x=$((x - 1))
10 a
11 echo a returns $?
12 return 4
13}
14
15c()
16{
17 x=$((x - 1))
18 b
19 echo b returns $?
20 return 3
21}
22
23d()
24{
25 x=$((x - 1))
26 c
27 echo c returns $?
28 return 2
29}
30
31e()
32{
33 d
34 echo d returns $?
35 echo in e
36 x=$((x - 1))
37 return $x
38}
39
40f()
41{
42 e
43 echo e returned $?
44 echo x is $x
45 return 0
46}
47
48x=30
49f
50
51# make sure unsetting a local variable preserves the `local' attribute
52f1()
53{
54 local zz
55 zz=abcde
56 echo $zz
57 unset zz
58 zz=defghi
59 echo $zz
60}
61
62zz=ZZ
63echo $zz
64f1
65echo $zz
66
67unset -f f1
68f1()
69{
70 return 5
71}
72
73( f1 )
74echo $?
75
76unset -f f1
77f1()
78{
79 sleep 5
80 return 5
81}
82
83f1 &
84wait
85echo $?
86
87unset -f f1
88
89f1()
90{
91 echo $AVAR
92 printenv AVAR
93}
94
95AVAR=AVAR
96echo $AVAR
97f1
98AVAR=foo f1
99echo $AVAR
100
101unset -f f1
102# make sure subshells can do a `return' if we're executing in a function
103f1()
104{
105 ( return 5 )
106 status=$?
107 echo $status
108 return $status
109}
110
111f1
112echo $?
113
114declare -F f1 # should print just the name
115declare -f f1 # should print the definition, too
116
117# no functions should be exported, right?
118declare -xF
119declare -xf
bb70624e
JA
120
121# FUNCNAME tests
122func2()
123{
124 echo FUNCNAME = $FUNCNAME
125}
126
127func()
128{
129 echo before: FUNCNAME = $FUNCNAME
130 func2
131 echo after: FUNCNAME = $FUNCNAME
132}
133
134echo before: try to assign to FUNCNAME
0628567a 135FUNCNAME=7
bb70624e
JA
136
137echo outside: FUNCNAME = $FUNCNAME
138func
139echo outside2: FUNCNAME = $FUNCNAME
140
141# test exported functions (and cached exportstr)
142zf()
143{
144 echo this is zf
145}
146export -f zf
147
148${THIS_SH} -c 'type -t zf'
149${THIS_SH} -c 'type zf'
150
151${THIS_SH} ./func1.sub
152
28ef6c31
JA
153# tests for functions whose bodies are not group commands, with and without
154# attached redirections
155${THIS_SH} ./func2.sub
156
157# test for some posix-specific function behavior
158${THIS_SH} ./func3.sub
159
495aee44
CR
160# FUNCNEST testing
161${THIS_SH} ./func4.sub
162
95732b49
JA
163unset -f myfunction
164myfunction() {
165 echo "bad shell function redirection"
166} >> /dev/null
167
168myfunction
169myfunction | cat
170
0628567a
JA
171segv()
172{
173 echo foo | return 5
174}
175
176segv
177echo $?
178
bb70624e 179exit 0