xref: /titanic_41/usr/src/lib/libshell/common/tests/functions.sh (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#          Copyright (c) 1982-2010 AT&T Intellectual Property          #
5#                      and is licensed under the                       #
6#                  Common Public License, Version 1.0                  #
7#                    by AT&T Intellectual Property                     #
8#                                                                      #
9#                A copy of the License is available at                 #
10#            http://www.opensource.org/licenses/cpl1.0.txt             #
11#         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         #
12#                                                                      #
13#              Information and Software Systems Research               #
14#                            AT&T Research                             #
15#                           Florham Park NJ                            #
16#                                                                      #
17#                  David Korn <dgk@research.att.com>                   #
18#                                                                      #
19########################################################################
20function err_exit
21{
22	print -u2 -n "\t"
23	print -u2 -r ${Command}[$1]: "${@:2}"
24	let Errors+=1
25}
26alias err_exit='err_exit $LINENO'
27
28integer Errors=0
29Command=${0##*/}
30
31ulimit -c 0
32
33tmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; }
34trap "cd /; rm -rf $tmp" EXIT
35
36integer foo=33
37bar=bye
38# check for global variables and $0
39function foobar
40{
41	case $1 in
42	1) 	print -r - "$foo" "$bar";;
43	2)	print -r - "$0";;
44	3)	typeset foo=foo
45		integer bar=10
46	 	print -r - "$foo" "$bar";;
47	4)	trap 'foo=36' EXIT
48		typeset foo=20;;
49	esac
50}
51function print
52{
53	command print hi
54}
55if	[[ $(print) != hi ]]
56then	err_exit "command print not working inside print function"
57fi
58unset -f print
59
60if	[[ $(foobar 1) != '33 bye' ]]
61then	err_exit 'global variables not correct'
62fi
63
64if	[[ $(foobar 2) != 'foobar' ]]
65then	err_exit '$0  not correct'
66fi
67
68if	[[ $(bar=foo foobar 1) != '33 foo' ]]
69then	err_exit 'environment override not correct'
70fi
71if	[[ $bar == foo ]]
72then	err_exit 'scoping error'
73fi
74
75if	[[ $(foobar 3) != 'foo 10' ]]
76then	err_exit non-local variables
77fi
78
79foobar 4
80if	[[ $foo != 36 ]]
81then	err_exit EXIT trap in wrong scope
82fi
83unset -f foobar || err_exit "cannot unset function foobar"
84typeset -f foobar>/dev/null  && err_exit "typeset -f has incorrect exit status"
85
86function foobar
87{
88	(return 0)
89}
90> $tmp/test1
91{
92foobar
93if	[ -r $tmp/test1 ]
94then	rm -r $tmp/test1
95else	err_exit 'return within subshell inside function error'
96fi
97}
98abc() print hi
99if	[[ $(abc) != hi ]]
100then	err_exit 'abc() print hi not working'
101fi
102( unset -f abc )
103if	[[ $(abc 2>/dev/null) != hi ]]
104then	err_exit 'abc() print hi not working after subshell unset'
105fi
106(
107	function f
108	{
109		exit 1
110	}
111	f
112	err_exit 'exit from function not working'
113)
114unset -f foo
115function foo
116{
117	x=2
118	(
119		x=3
120		cd $tmp
121		print bar
122	)
123	if	[[ $x != 2 ]]
124	then	err_exit 'value of x not restored after subshell inside function'
125	fi
126}
127x=1
128dir=$PWD
129if	[[ $(foo) != bar ]]
130then	err_exit 'cd inside nested subshell not working'
131fi
132if	[[ $PWD != "$dir" ]]
133then	err_exit 'cd inside nested subshell changes $PWD'
134fi
135fun() /bin/echo hello
136if	[[ $(fun) != hello ]]
137then	err_exit one line functions not working
138fi
139cat > $tmp/script <<-\!
140	print -r -- "$1"
141!
142chmod +x $tmp/script
143function passargs
144{
145	$tmp/script "$@"
146}
147if	[[ $(passargs one) != one ]]
148then	err_exit 'passing args from functions to scripts not working'
149fi
150cat > $tmp/script <<-\!
151	trap 'exit 0' EXIT
152	function foo
153	{
154		/tmp > /dev/null 2>&1
155	}
156	foo
157!
158if	! $tmp/script
159then	err_exit 'exit trap incorrectly triggered'
160fi
161if	! $SHELL -c $tmp/script
162then	err_exit 'exit trap incorrectly triggered when invoked with -c'
163fi
164$SHELL -c "trap 'rm $tmp/script' EXIT"
165if	[[ -f $tmp/script ]]
166then	err_exit 'exit trap not triggered when invoked with -c'
167fi
168cat > $tmp/script <<- \EOF
169	foobar()
170	{
171		return
172	}
173	shift
174	foobar
175	print -r -- "$1"
176EOF
177chmod +x $tmp/script
178if	[[ $( $SHELL $tmp/script arg1 arg2) != arg2 ]]
179then	err_exit 'arguments not restored by posix functions'
180fi
181function foo
182{
183	print hello
184}
185(
186	function foo
187	{
188		print bar
189	}
190	if [[ $(foo) != bar ]]
191	then	err_exit 'function definitions inside subshells not working'
192	fi
193)
194if [[ $(foo) != hello ]]
195then	err_exit 'function definitions inside subshells not restored'
196fi
197unset -f foo bar
198function bar
199{
200        print "$y"
201}
202
203function foo
204{
205        typeset x=3
206        y=$x bar
207}
208x=1
209if	[[ $(foo) != 3 ]]
210then	err_exit 'variable assignment list not using parent scope'
211fi
212unset -f foobar
213cat > $tmp/foobar <<!
214function foobar
215{
216	print foo
217}
218!
219chmod +x $tmp/foobar
220FPATH=$tmp
221autoload foobar
222if	[[ $(foobar 2>/dev/null) != foo ]]
223then	err_exit 'autoload not working'
224fi
225unset -f foobar
226function foobar
227{
228	typeset -r x=3
229	return 0
230}
231( foobar ) 2> /dev/null || err_exit "cannot unset readonly variable in function"
232if	$SHELL -n 2> /dev/null <<-!
233	abc()
234	!
235then	err_exit 'abc() without a function body is not a syntax error'
236fi
237function winpath
238{
239	usage='q pathname ...'
240	typeset var format=s
241	while   getopts  "$usage" var
242	do      case $var in
243		q)      format=q;;
244	        esac
245	done
246	print done
247}
248if	[[ $( (winpath --man 2>/dev/null); print ok) != ok ]]
249then	err_exit 'getopts --man in functions not working'
250fi
251if	[[ $( (winpath -z 2>/dev/null); print ok) != ok ]]
252then	err_exit 'getopts with bad option in functions not working'
253fi
254unset -f x
255function x
256{
257        print "$@"
258}
259typeset -ft x
260if      [[ $(x x=y 2>/dev/null) != x=y ]]
261then    err_exit 'name=value pair args not passed to traced functions'
262fi
263function bad
264{
265	false
266}
267trap 'val=false' ERR
268val=true
269bad
270if	[[ $val != false ]]
271then	err_exit 'set -e not working for functions'
272fi
273function bad
274{
275	false
276	return 0
277}
278val=true
279bad
280if	[[ $val != true ]]
281then	err_exit 'set -e not disabled for functions'
282fi
283bad()
284{
285	false
286	return 0
287}
288val=true
289bad
290if	[[ $val != false ]]
291then	err_exit 'set -e not inherited for posix functions'
292fi
293trap - ERR
294
295function myexport
296{
297	nameref var=$1
298	if	(( $# > 1 ))
299	then	export	$1=$2
300	fi
301	if	(( $# > 2 ))
302	then	print $(myexport "$1" "$3" )
303		return
304	fi
305	typeset val
306	val=$(export | grep "^$1=")
307	print ${val#"$1="}
308}
309export dgk=base
310val=$(myexport dgk fun)
311if	[[ $val != fun ]]
312then	err_exit "export inside function not working -- expected 'fun', got '$val'"
313fi
314val=$(export | sed -e '/^dgk=/!d' -e 's/^dgk=//')
315if	[[ $val != base ]]
316then	err_exit "export not restored after function call -- expected 'base', got '$val'"
317fi
318val=$(myexport dgk fun fun2)
319if	[[ $val != fun2 ]]
320then	err_exit "export inside function not working with recursive function -- expected 'fun2', got '$val'"
321fi
322val=$(export | sed -e '/^dgk=/!d' -e 's/^dgk=//')
323if	[[ $val != base ]]
324then	err_exit "export not restored after recursive function call -- expected 'base', got '$val'"
325fi
326val=$(dgk=try3 myexport dgk)
327if	[[ $val != try3 ]]
328then	err_exit "name=value not added to export list with function call -- expected 'try3', got '$val'"
329fi
330val=$(export | sed -e '/^dgk=/!d' -e 's/^dgk=//')
331if	[[ $val != base ]]
332then	err_exit "export not restored name=value function call -- expected 'base', got '$val'"
333fi
334unset zzz
335val=$(myexport zzz fun)
336if	[[ $val != fun ]]
337then	err_exit "export inside function not working -- expected 'fun', got '$val'"
338fi
339val=$(export | sed -e '/^zzz=/!d' -e 's/^zzz=//')
340if	[[ $val ]]
341then	err_exit "unset varaible exported after function call -- expected '', got '$val'"
342fi
343
344unset zzz
345typeset -u zzz
346function foo
347{
348	zzz=abc
349	print $zzz
350}
351if	[[ $(foo)$(foo) != ABCABC ]]
352then	err_exit 'attributes on unset variables not saved/restored'
353fi
354function xpd {
355	typeset i j=$1
356                for i
357                        do print i=$i j=$j
358                        [[ $i == a ]] && xpd b
359                        done
360                }
361if	[[ $(xpd a c) != $'i=a j=a\ni=b j=b\ni=c j=a' ]]
362then	err_exit 'for loop function optimization error'
363fi
364
365typeset -A visited
366integer level=0
367function closure
368{
369	(( $# > 5 )) && return 1
370	((level < 2)) && ((level++))
371	typeset tmp r=0
372	visited[$1]=1
373
374	for tmp in $level _$level
375	do
376		[[ ${visited[$tmp]} == 1 ]] && continue
377		closure $tmp $* || r=1
378	done
379	return $r
380}
381closure 0 || err_exit -u2 'for loop function optimization bug2'
382dir=$tmp/dir
383mkdir $dir
384cd $dir || { err_exit "cd $dir failed"; exit 1; }
385
386(
387	function a {
388		print a
389	}
390	function b {
391		print 1
392		a
393		print 2
394	} > /dev/null
395	typeset -ft a b
396	PS4=X
397	b
398) > file 2>&1
399[[ $(<file) == *'Xprint 2'* ]] ||  err_exit 'function trace disabled by function call'
400rm -f file
401
402print 'false' > try
403chmod +x try
404cat > tst <<- EOF
405	function ignore
406	{
407		./try
408		return 0
409	}
410	trap "print error; exit 1" ERR
411	ignore
412EOF
413if	[[ $($SHELL < tst)  == error ]]
414then	err_exit 'ERR trap not cleared'
415fi
416FPATH=$dir
417print ': This does nothing' > foobar
418chmod +x foobar
419unset -f foobar
420{ foobar; } 2>/dev/null
421got=$?
422exp=126
423if	[[ $got != $exp ]]
424then	err_exit "function file without function definition processes wrong error -- expected '$exp', got '$got'"
425fi
426print 'set a b c' > dotscript
427[[ $(PATH=$PATH: $SHELL -c '. dotscript;print $#') == 3 ]] || err_exit 'positional parameters not preserved with . script without arguments'
428cd ~- || err_exit "cd back failed"
429function errcheck
430{
431	trap 'print ERR; return 1' ERR
432	false
433	print ok
434}
435err=$(errcheck)
436[[ $err == ERR ]] || err_exit 'trap on ERR not working in a function'
437x="$(
438	function foobar
439	{
440		print ok
441	}
442	typeset -f foobar
443)"
444eval "$x"  || err_exit 'typeset -f generates syntax error'
445[[ $(foobar) != ok ]] && err_exit 'typeset -f not generating function'
446unset -f a b c
447a()
448{
449        b
450        b
451        print ${.sh.fun}
452}
453b() { : ;}
454[[ $(a) == a ]] || err_exit '.sh.fun not set correctly in a function'
455print $'a(){\ndate\n}'  | $SHELL 2> /dev/null || err_exit 'parser error in a(){;date;}'
456cat > $tmp/data1 << '++EOF'
457     1  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
458     2  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
459     3  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
460     4  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
461     5  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
462     6  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
463     7  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
464     8  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
465     9  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
466    10  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
467    11  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
468    12  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
469    13  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX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XXXXXXXXXXXXXXXXXXXXX
738# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
739
740f()
741{
742cat <<\M
743++EOF
744cat $tmp/data1 >> $tmp/script
745printf 'M\n}\n\nf\n\n' >> $tmp/script
746$SHELL -c $tmp/script  > $tmp/data2
747cmp -s $tmp/data[12] || err_exit 'error with long functions'
748v=1
749function f
750{
751	typeset i
752	for i in 0 1
753	do	typeset v
754		v=$i
755		[[ $v == $i ]] || return 1
756	done
757}
758f || err_exit "typeset optimization bug"
759function f
760{
761	print -r -- "$foo$bar"
762}
763function g
764{
765	print -r -- $(bar=bam f)
766}
767unset foo bar
768[[ $(foo=hello g) == hellobam ]] || err_exit 'function exports not passed on'
769[[ $(bar=hello g) == bam ]] || err_exit 'function exports not overridden'
770unset -f foo
771function foo
772{
773	typeset line=$1
774	set +n
775	while	[[ $line ]]
776	do	if	[[ ! $varname ]]
777		then	varname=${line%% *}
778			line=${line##"$varname"?( )}
779			[[ $line ]] && continue
780		else	print ok
781			return
782		fi
783		varname=
784	done
785}
786[[ $(foo 'NUMBERED RECORDSIZE') == ok ]] || err_exit 'optimization error with undefined variable'
787unset x
788x=$(
789	set -e
790	integer count=0
791	function err_f
792	{
793		if	((count++==3))
794		then	print failed
795		else	false
796		fi
797	}
798	trap 'err_f' ERR
799	false
800)
801[[ $x == failed ]] && err_exit 'ERR trap executed multiple times'
802export environment
803typeset global
804function f
805{
806	typeset i t local
807
808	for i
809	do	case $i in
810		[-+]*)	set "$@"
811			continue
812			;;
813		local)	local=f
814			t=$(typeset +f $local)
815			;;
816		global)	global=f
817			t=$(typeset +f $global)
818			;;
819		environment)
820			environment=f
821			t=$(typeset +f $environment)
822			;;
823		literal)t=$(typeset +f f)
824			;;
825		positional)
826			set -- f
827			t=$(typeset +f $1)
828			;;
829		esac
830		[[ $t ]] || err_exit "typeset +f \$$i failed"
831	done
832}
833f local global environment literal positional
834$SHELL -c '
835	print exit 0 > '$tmp'/script
836	chmod +x '$tmp'/script
837	unset var
838	var=( ident=1 )
839	function fun
840	{
841		PATH='$tmp' script
842	}
843	fun
844' || err_exit "compound variable cleanup before script exec failed"
845( $SHELL << \++EOF++
846function main
847{
848 	typeset key
849 	typeset -A entry
850 	entry[a]=( value=aaa )
851}
852main
853++EOF++
854) 2> /dev/null || err_exit 'function main fails'
855optind=$OPTIND
856sub()
857{
858        (
859                OPTIND=1
860                while getopts :abc OPTION "$@"
861                do      print OPTIND=$OPTIND
862                done
863        )
864}
865[[ $(sub -a) == OPTIND=2 ]] || err_exit 'OPTIND should be 2'
866[[ $(sub -a) == OPTIND=2 ]] || err_exit 'OPTIND should be 2 again'
867[[ $OPTIND == "$optind" ]] || err_exit 'OPTIND should be 1'
868
869function bar
870{
871	[[ -o nounset ]] && err_exit  'nounset option should not be inherited'
872}
873function foo
874{
875	set -o nounset
876	bar
877}
878set +o nounset
879foo
880function red
881{
882	integer -S d=0
883	printf 'red_one %d\n' d
884	(( d++ ))
885	return 0
886}
887[[ ${ red } != 'red_one 0' ]] && err_exit 'expected red_one 0'
888[[ ${ red } != 'red_one 1' ]] && err_exit 'expected red_one 1'
889xyz=$0
890function traceback
891{
892	integer .level=.sh.level
893	while((--.level>=0))
894	do
895		((.sh.level = .level))
896		[[ $xyz == "$0" ]] || err_exit "\$xyz=$xyz does not match $0 on level ${.level}"
897		[[ ${.sh.lineno} == "$1" ]] || err_exit "\${.sh.lineno}=${.sh.lineno} does not match $1 on level ${.level}"
898	done
899}
900
901function foo
902{
903	typeset xyz=foo
904	set -- $((LINENO+1))
905	bar $LINENO "$1"
906}
907
908function bar
909{
910    	typeset xyz=bar
911	set -- $((LINENO+2))
912	trap 'traceback $LINENO' DEBUG
913	: $LINENO "$1"
914}
915
916set -- $((LINENO+1))
917foo $LINENO
918function .sh.fun.set
919{
920	print -r -- "${.sh.value}"
921}
922function abc
923{
924	:
925}
926def()
927{
928	:
929}
930[[ $(abc) == abc ]] || err_exit '.sh.fun.set not capturing function name'
931[[ $(def) == def ]] || err_exit '.sh.fun.set not capturing name()'
932unset -f .sh.fun.set
933
934# tests for debug functions
935basefile=${.sh.file}
936integer baseline
937cat > $tmp/debug << \+++
938	: line 1
939
940	: line 3
941+++
942# Print one line in a call stack
943function _Dbg_print_frame
944{
945	typeset -i pos=$1
946	typeset fn=$2
947	typeset filename="$3"
948	typeset -i line=$4
949	typeset  arg=$5
950	shift 5
951	if	((pos==0))
952	then	[[ $filename == "$basefile" ]] || err_exit "filename for level 0 is $filename not $basename"
953		[[ $arg == DEBUG  ]] && ((baseline++))
954		[[ $line == "$baseline" ]] || err_exit "line number for level 0 is $line not $baseline"
955	elif	((pos==1))
956	then	[[ $filename == "$tmp/debug" ]] ||  err_exit "filename for level 1 is $filename not $tmp/debug"
957		[[ $* == 'foo bar' ]] || err_exit "args are '$*', not 'foo bar'"
958		[[ $line == $arg ]] || err_exit "line number for level 1 is $line not $arg"
959	else	err_exit "level should be 0 or 1 but is $pos"
960	fi
961}
962
963function _Dbg_debug_trap_handler
964{
965
966	integer .level=.sh.level .max=.sh.level-1
967	while((--.level>=0))
968	do
969		((.sh.level = .level))
970      		_Dbg_print_frame  "${.level}" "$0" "${.sh.file}" "${.sh.lineno}" "${.sh.command##* }" "$@"
971	done
972}
973
974((baseline=LINENO+2))
975trap '_Dbg_debug_trap_handler' DEBUG
976.  $tmp/debug foo bar
977trap '' DEBUG
978
979caller() {
980  integer .level=.sh.level .max=.sh.level-1
981  while((--.level>=0))
982  do
983      ((.sh.level = .level))
984      print -r -- "${.sh.lineno}"
985  done
986}
987bar() { caller;}
988set -- $(bar)
989[[ $1 == $2 ]] && err_exit ".sh.inline optimization bug"
990( $SHELL  -c ' function foo { typeset x=$1;print $1;};z=();z=($(foo bar)) ') 2> /dev/null ||  err_exit 'using a function to set an array in a command sub  fails'
991
992{
993got=$(
994s=$(ulimit -s)
995if	[[ $s == +([[:digit:]]) ]] && (( s < 16384 ))
996then	ulimit -s 16384 2>/dev/null
997fi
998$SHELL << \+++
999f()
1000{
1001	if	(($1>1))
1002	then	x=$(f $(($1-1))) || exit 1
1003	fi
1004	return 0
1005}
1006f 257 && print ok
1007+++
1008)
1009} 2>/dev/null
1010[[ $got == ok ]] || err_exit 'cannot handle comsub depth > 256 in function'
1011
1012tmp1=$tmp/job.1
1013tmp2=$tmp/job.2
1014cat > $tmp1 << +++
1015#! $SHELL
1016print \$\$
1017+++
1018chmod +x $tmp1
1019function foo
1020{
1021	typeset pid
1022	$tmp1 > $tmp2 & pid=$!
1023	wait $!
1024	[[ $(< $tmp2) == $pid ]] || err_exit 'wrong pid for & job in function'
1025}
1026foo
1027# make sure compiled functions work
1028[[ $(tmp=$tmp $SHELL <<- \++++
1029	cat > $tmp/functions <<- \EOF
1030	 	function bar
1031	 	{
1032	 		print foo
1033	 	}
1034	 	function foobar
1035	 	{
1036	 		bar
1037	 	}
1038	EOF
1039	${SHCOMP:-${SHELL%/*}/shcomp} $tmp/functions > $tmp/foobar
1040	rm -f "$tmp/functions"
1041	chmod +x $tmp/foobar
1042	rm $tmp/!(dir|foobar)
1043	FPATH=$tmp
1044	PATH=$FPATH:$PATH
1045	foobar
1046++++
1047) == foo ]] > /dev/null  || err_exit 'functions compiled with shcomp not working'
1048# test for functions in shell having side effects.
1049unset -f foo foobar bar
1050cd "$tmp"
1051FPATH=$PWD
1052PATH=$FPATH:$PATH
1053cat > foo <<- \EOF
1054	function bar
1055	{
1056		print foobar
1057	}
1058	function foo
1059	{
1060		bar
1061	}
1062EOF
1063chmod +x foo
1064: $(foo)
1065[[ $(typeset +f) == *foo* ]] &&  err_exit 'function in subshell leaving side effect of function foo'
1066unset -f foo bar
1067:  $(foo)
1068[[ $(typeset +f) == *foo* ]] && err_exit 'function in subshell leaving side effects of function foo after reload'
1069[[ $(typeset +f) == *bar* ]] && err_exit 'function in subshell leaving side effects of function bar after reload'
1070
1071unset -f foo
1072typeset -A bar
1073function foo
1074{
1075	typeset -i bar[$1].x
1076	bar[$1].x=5
1077}
1078foo sub
1079[[ ${!bar[@]} == sub ]] || err_exit 'scoping problem with compound array variables'
1080
1081function A
1082{
1083        trap "> /dev/null;print TRAP A" EXIT
1084	# (( stderr )) && print >&2
1085}
1086
1087function B
1088{
1089        trap "> /dev/null;print TRAP B" EXIT
1090        A
1091}
1092
1093x=$(B)
1094[[ $x == $'TRAP A\nTRAP B' ]] || err_exit "trap from funtions in subshells fails got" $x
1095
1096exit $((Errors))
1097