xref: /titanic_50/usr/src/lib/libshell/common/tests/functions.sh (revision 1da7e59911a9f3f267c3ef294dc342767dee7952)
1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#          Copyright (c) 1982-2008 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
31tmp=/tmp/kshtf$$
32function cleanup
33{
34	rm -rf $tmp
35}
36mkdir $tmp || err_exit "mkdir $tmp failed"
37
38integer foo=33
39bar=bye
40# check for global variables and $0
41function foobar
42{
43	case $1 in
44	1) 	print -r - "$foo" "$bar";;
45	2)	print -r - "$0";;
46	3)	typeset foo=foo
47		integer bar=10
48	 	print -r - "$foo" "$bar";;
49	4)	trap 'foo=36' EXIT
50		typeset foo=20;;
51	esac
52}
53function print
54{
55	command print hi
56}
57if	[[ $(print) != hi ]]
58then	err_exit "command print not working inside print function"
59fi
60unset -f print
61
62if	[[ $(foobar 1) != '33 bye' ]]
63then	err_exit 'global variables not correct'
64fi
65
66if	[[ $(foobar 2) != 'foobar' ]]
67then	err_exit '$0  not correct'
68fi
69
70if	[[ $(bar=foo foobar 1) != '33 foo' ]]
71then	err_exit 'environment override not correct'
72fi
73if	[[ $bar == foo ]]
74then	err_exit 'scoping error'
75fi
76
77if	[[ $(foobar 3) != 'foo 10' ]]
78then	err_exit non-local variables
79fi
80
81foobar 4
82if	[[ $foo != 36 ]]
83then	err_exit EXIT trap in wrong scope
84fi
85unset -f foobar || err_exit "cannot unset function foobar"
86typeset -f foobar>/dev/null  && err_exit "typeset -f has incorrect exit status"
87
88function foobar
89{
90	(return 0)
91}
92> $tmp/shtests$$.1
93{
94foobar
95if	[ -r $tmp/shtests$$.1 ]
96then	rm -r $tmp/shtests$$.1
97else	err_exit 'return within subshell inside function error'
98fi
99}
100abc() print hi
101if	[[ $(abc) != hi ]]
102then	err_exit 'abc() print hi not working'
103fi
104( unset -f abc )
105if	[[ $(abc 2>/dev/null) != hi ]]
106then	err_exit 'abc() print hi not working after subshell unset'
107fi
108(
109	function f
110	{
111		exit 1
112	}
113	f
114	err_exit 'exit from function not working'
115)
116unset -f foo
117function foo
118{
119	x=2
120	(
121		x=3
122		cd $tmp
123		print bar
124	)
125	if	[[ $x != 2 ]]
126	then	err_exit 'value of x not restored after subshell inside function'
127	fi
128}
129x=1
130dir=$PWD
131if	[[ $(foo) != bar ]]
132then	err_exit 'cd inside nested subshell not working'
133fi
134if	[[ $PWD != "$dir" ]]
135then	err_exit 'cd inside nested subshell changes $PWD'
136fi
137fun() /bin/echo hello
138if	[[ $(fun) != hello ]]
139then	err_exit one line functions not working
140fi
141trap cleanup EXIT
142cat > $tmp/script$$ <<-\!
143	print -r -- "$1"
144!
145chmod +x $tmp/script$$
146function passargs
147{
148	$tmp/script$$ "$@"
149}
150if	[[ $(passargs one) != one ]]
151then	err_exit 'passing args from functions to scripts not working'
152fi
153cat > $tmp/script$$ <<-\!
154	trap 'exit 0' EXIT
155	function foo
156	{
157		/tmp > /dev/null  2>&1
158	}
159	foo
160!
161if	! $tmp/script$$
162then	err_exit 'exit trap incorrectly triggered'
163fi
164if	! $SHELL -c $tmp/script$$
165then	err_exit 'exit trap incorrectly triggered when invoked with -c'
166fi
167$SHELL -c "trap 'rm $tmp/script$$' EXIT"
168if	[[ -f $tmp/script$$ ]]
169then	err_exit 'exit trap not triggered when invoked with -c'
170fi
171cat > $tmp/script$$ <<- \EOF
172	foobar()
173	{
174		return
175	}
176	shift
177	foobar
178	print -r -- "$1"
179EOF
180chmod +x $tmp/script$$
181if	[[ $( $SHELL $tmp/script$$ arg1 arg2) != arg2 ]]
182then	err_exit 'arguments not restored by posix functions'
183fi
184function foo
185{
186	print hello
187}
188(
189	function foo
190	{
191		print bar
192	}
193	if [[ $(foo) != bar ]]
194	then	err_exit 'function definitions inside subshells not working'
195	fi
196)
197if [[ $(foo) != hello ]]
198then	err_exit 'function definitions inside subshells not restored'
199fi
200unset -f foo bar
201function bar
202{
203        print "$y"
204}
205
206function foo
207{
208        typeset x=3
209        y=$x bar
210}
211x=1
212if	[[ $(foo) != 3 ]]
213then	err_exit 'variable assignment list not using parent scope'
214fi
215unset -f foo$$
216#trap "rm -f $tmp/foo$$" EXIT INT
217cat > $tmp/foo$$ <<!
218function foo$$
219{
220	print foo
221}
222!
223chmod +x $tmp/foo$$
224FPATH=$tmp
225autoload foo$$
226if	[[ $(foo$$ 2>/dev/null) != foo ]]
227then	err_exit 'autoload not working'
228fi
229unset -f foobar
230function foobar
231{
232	typeset -r x=3
233	return 0
234}
235( foobar ) 2> /dev/null || err_exit "cannot unset readonly variable in function"
236if	$SHELL -n 2> /dev/null <<-!
237	abc()
238	!
239then	err_exit 'abc() without a function body is not a syntax error'
240fi
241function winpath
242{
243	usage='q pathname ...'
244	typeset var format=s
245	while   getopts  "$usage" var
246	do      case $var in
247		q)      format=q;;
248	        esac
249	done
250	print done
251}
252if	[[ $( (winpath --man 2>/dev/null); print ok) != ok ]]
253then	err_exit 'getopts --man in functions not working'
254fi
255if	[[ $( (winpath -z 2>/dev/null); print ok) != ok ]]
256then	err_exit 'getopts with bad option in functions not working'
257fi
258unset -f x
259function x
260{
261        print "$@"
262}
263typeset -ft x
264if      [[ $(x x=y 2>/dev/null) != x=y ]]
265then    err_exit 'name=value pair args not passed to traced functions'
266fi
267function bad
268{
269	false
270}
271trap 'val=false' ERR
272val=true
273bad
274if	[[ $val != false ]]
275then	err_exit 'set -e not working for functions'
276fi
277function bad
278{
279	false
280	return 0
281}
282val=true
283bad
284if	[[ $val != true ]]
285then	err_exit 'set -e not disabled for functions'
286fi
287bad()
288{
289	false
290	return 0
291}
292val=true
293bad
294if	[[ $val != false ]]
295then	err_exit 'set -e not inherited for posix functions'
296fi
297trap - ERR
298
299function myexport
300{
301	nameref var=$1
302	if	(( $# > 1 ))
303	then	export	$1=$2
304	fi
305	if	(( $# > 2 ))
306	then	print $(myexport "$1" "$3" )
307		return
308	fi
309	typeset val
310	val=$(export | grep "^$1=")
311	print ${val#"$1="}
312
313}
314export dgk=base
315val=$(myexport dgk fun)
316if	[[ $val != fun ]]
317then	err_exit "export inside function not working -- expected 'fun', got '$val'"
318fi
319val=$(export | sed -e '/^dgk=/!d' -e 's/^dgk=//')
320if	[[ $val != base ]]
321then	err_exit "export not restored after function call -- expected 'base', got '$val'"
322fi
323val=$(myexport dgk fun fun2)
324if	[[ $val != fun2 ]]
325then	err_exit "export inside function not working with recursive function -- expected 'fun2', got '$val'"
326fi
327val=$(export | sed -e '/^dgk=/!d' -e 's/^dgk=//')
328if	[[ $val != base ]]
329then	err_exit "export not restored after recursive function call -- expected 'base', got '$val'"
330fi
331val=$(dgk=try3 myexport dgk)
332if	[[ $val != try3 ]]
333then	err_exit "name=value not added to export list with function call -- expected 'try3', got '$val'"
334fi
335val=$(export | sed -e '/^dgk=/!d' -e 's/^dgk=//')
336if	[[ $val != base ]]
337then	err_exit "export not restored name=value function call -- expected 'base', got '$val'"
338fi
339unset zzz
340val=$(myexport zzz fun)
341if	[[ $val != fun ]]
342then	err_exit "export inside function not working -- expected 'fun', got '$val'"
343fi
344val=$(export | sed -e '/^zzz=/!d' -e 's/^zzz=//')
345if	[[ $val ]]
346then	err_exit "unset varaible exported after function call -- expected '', got '$val'"
347fi
348
349unset zzz
350typeset -u zzz
351function foo
352{
353	zzz=abc
354	print $zzz
355}
356if	[[ $(foo)$(foo) != ABCABC ]]
357then	err_exit 'attributes on unset variables not saved/restored'
358fi
359function xpd {
360	typeset i j=$1
361                for i
362                        do print i=$i j=$j
363                        [[ $i == a ]] && xpd b
364                        done
365                }
366if	[[ $(xpd a c) != $'i=a j=a\ni=b j=b\ni=c j=a' ]]
367then	err_exit 'for loop function optimization error'
368fi
369
370typeset -A visited
371integer level=0
372function closure
373{
374	(( $# > 5 )) && return 1
375	((level < 2)) && ((level++))
376	typeset tmp r=0
377	visited[$1]=1
378
379	for tmp in $level _$level
380	do
381		[[ ${visited[$tmp]} == 1 ]] && continue
382		closure $tmp $* || r=1
383	done
384	return $r
385}
386closure 0 || err_exit -u2 'for loop function optimization bug2'
387mkdir  $tmp/ksh$$ || err_exit "mkdir $tmp/ksh$$ failed"
388cd $tmp/ksh$$ || err_exit "cd $tmp/ksh$$ failed"
389print 'false' > try
390chmod +x try
391cat > tst <<- EOF
392	function ignore
393	{
394		./try
395		return 0
396	}
397	trap "print error; exit 1" ERR
398	ignore
399EOF
400if	[[ $($SHELL < tst)  == error ]]
401then	err_exit 'ERR trap not cleared'
402fi
403FPATH=$tmp/ksh$$
404print ': This does nothing' > $tmp/ksh$$/foobar
405chmod +x $tmp/ksh$$/foobar
406unset -f  foobar
407{ foobar;} 2> /dev/null
408if	[[ $? != 126 ]]
409then	err_exit 'function file without function definition processes wrong error'
410fi
411print 'set a b c' > dotscript
412[[ $(PATH=$PATH: $SHELL -c '. dotscript;print $#') == 3 ]] || err_exit 'positional parameters not preserved with . script without arguments'
413cd ~- || err_exit "cd back failed"
414cd /; rm -r $tmp/ksh$$ || err_exit "rm -r $tmp/ksh$$ failed"
415function errcheck
416{
417	trap 'print ERR; return 1' ERR
418	false
419	print ok
420}
421err=$(errcheck)
422[[ $err == ERR ]] || err_exit 'trap on ERR not working in a function'
423x="$(
424	function foobar
425	{
426		print ok
427	}
428	typeset -f foobar
429)"
430eval "$x"  || err_exit 'typeset -f generates syntax error'
431[[ $(foobar) != ok ]] && err_exit 'typeset -f not generating function'
432unset -f a b c
433a()
434{
435        b
436        b
437        print ${.sh.fun}
438}
439b() { : ;}
440[[ $(a) == a ]] || err_exit '.sh.fun not set correctly in a function'
441print $'a(){\ndate\n}'  | $SHELL 2> /dev/null || err_exit 'parser error in a(){;date;}'
442cat > $tmp/data$$.1 << '++EOF'
443     1  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
444     2  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
445     3  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
446     4  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
447     5  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
448     6  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
449     7  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
450     8  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
451     9  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
452    10  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
453    11  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
454    12  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
455    13  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XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
724# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
725
726f()
727{
728cat <<\M
729++EOF
730cat $tmp/data$$.1 >> $tmp/script$$
731printf 'M\n}\n\nf\n\n' >> $tmp/script$$
732$SHELL -c $tmp/script$$  > $tmp/data$$.2
733cmp -s $tmp/data$$.[12] || err_exit 'error with long functions'
734v=1
735function f
736{
737	typeset i
738	for i in 0 1
739	do	typeset v
740		v=$i
741		[[ $v == $i ]] || return 1
742	done
743}
744f || err_exit "typeset optimization bug"
745function f
746{
747	print -r -- "$foo$bar"
748}
749function g
750{
751	print -r -- $(bar=bam f)
752}
753unset foo bar
754[[ $(foo=hello g) == hellobam ]] || err_exit 'function exports not passed on'
755[[ $(bar=hello g) == bam ]] || err_exit 'function exports not overridden'
756unset -f foo
757function foo
758{
759	typeset line=$1
760	set +n
761	while	[[ $line ]]
762	do	if	[[ ! $varname ]]
763		then	varname=${line%% *}
764			line=${line##"$varname"?( )}
765			[[ $line ]] && continue
766		else	print ok
767			return
768		fi
769		varname=
770	done
771}
772[[ $(foo 'NUMBERED RECORDSIZE') == ok ]] || err_exit 'optimization error with undefined variable'
773unset x
774x=$(
775	set -e
776	integer count=0
777	function err_f
778	{
779		if	((count++==3))
780		then	print failed
781		else	false
782		fi
783	}
784	trap 'err_f' ERR
785	false
786)
787[[ $x == failed ]] && err_exit 'ERR trap executed multiple times'
788trap cleanup EXIT
789export environment
790typeset global
791function f
792{
793	typeset i t local
794
795	for i
796	do	case $i in
797		[-+]*)	set "$@"
798			continue
799			;;
800		local)	local=f
801			t=$(typeset +f $local)
802			;;
803		global)	global=f
804			t=$(typeset +f $global)
805			;;
806		environment)
807			environment=f
808			t=$(typeset +f $environment)
809			;;
810		literal)t=$(typeset +f f)
811			;;
812		positional)
813			set -- f
814			t=$(typeset +f $1)
815			;;
816		esac
817		[[ $t ]] || err_exit "typeset +f \$$i failed"
818	done
819}
820f local global environment literal positional
821$SHELL -c '
822	print exit 0 > '$tmp'/script$$
823	chmod +x '$tmp'/script$$
824	unset var
825	var=( ident=1 )
826	function fun
827	{
828		PATH='$tmp' script$$
829	}
830	fun
831' || err_exit "compound variable cleanup before script exec failed"
832( $SHELL << \++EOF++
833function main
834{
835 	typeset key
836 	typeset -A entry
837 	entry[a]=( value=aaa )
838}
839main
840++EOF++
841) 2> /dev/null || err_exit 'function main fails'
842optind=$OPTIND
843sub()
844{
845        (
846                OPTIND=1
847                while getopts :abc OPTION "$@"
848                do      print OPTIND=$OPTIND
849                done
850        )
851}
852[[ $(sub -a) == OPTIND=2 ]] || err_exit 'OPTIND should be 2'
853[[ $(sub -a) == OPTIND=2 ]] || err_exit 'OPTIND should be 2 again'
854[[ $OPTIND == "$optind" ]] || err_exit 'OPTIND should be 1'
855
856function bar
857{
858	[[ -o nounset ]] && err_exit  'nounset option should not be inherited'
859}
860function foo
861{
862	set -o nounset
863	bar
864}
865set +o nounset
866foo
867function red
868{
869	integer -S d=0
870	printf 'red_one %d\n' d
871	(( d++ ))
872	return 0
873}
874[[ ${ red } != 'red_one 0' ]] && err_exit 'expected red_one 0'
875[[ ${ red } != 'red_one 1' ]] && err_exit 'expected red_one 1'
876xyz=$0
877function traceback
878{
879	integer .level=.sh.level
880	while((--.level>=0))
881	do
882		((.sh.level = .level))
883		[[ $xyz == "$0" ]] || err_exit "\$xyz=$xyz does not match $0 on level ${.level}"
884		[[ ${.sh.lineno} == "$1" ]] || err_exit "\${.sh.lineno}=${.sh.lineno} does not match $1 on level ${.level}"
885	done
886}
887
888function foo
889{
890	typeset xyz=foo
891	set -- $((LINENO+1))
892	bar $LINENO "$1"
893}
894
895function bar
896{
897    	typeset xyz=bar
898	set -- $((LINENO+2))
899	trap 'traceback $LINENO' DEBUG
900	: $LINENO "$1"
901}
902
903set -- $((LINENO+1))
904foo $LINENO
905function .sh.fun.set
906{
907	print -r -- "${.sh.value}"
908}
909function abc
910{
911	:
912}
913def()
914{
915	:
916}
917[[ $(abc) == abc ]] || err_exit '.sh.fun.set not capturing function name'
918[[ $(def) == def ]] || err_exit '.sh.fun.set not capturing name()'
919unset -f .sh.fun.set
920
921# tests for debug functions
922basefile=${.sh.file}
923integer baseline
924cleanup
925trap 'rm $tmp' EXIT
926tmp=${TMPDIR:-/tmp}/ksh$$.1
927cat > $tmp << \+++
928	: line 1
929
930	: line 3
931+++
932# Print one line in a call stack
933function _Dbg_print_frame
934{
935	typeset -i pos=$1
936	typeset fn=$2
937	typeset filename="$3"
938	typeset -i line=$4
939	typeset  arg=$5
940	shift 5
941	if	((pos==0))
942	then	[[ $filename == "$basefile" ]] || err_exit "filename for level 0 is $filename not $basename"
943		[[ $arg == DEBUG  ]] && ((baseline++))
944		[[ $line == "$baseline" ]] || err_exit "line number for level 0 is $line not $baseline"
945	elif	((pos==1))
946	then	[[ $filename == "$tmp" ]] ||  err_exit "filename for level 1 is $filename not $tmp"
947		[[ $* == 'foo bar' ]] || err_exit "args are '$*', not 'foo bar'"
948		[[ $line == $arg ]] || err_exit "line number for level 1 is $line not $arg"
949	else	err_exit "level should be 0 or 1 but is $pos"
950	fi
951}
952
953function _Dbg_debug_trap_handler
954{
955
956	integer .level=.sh.level .max=.sh.level-1
957	while((--.level>=0))
958	do
959		((.sh.level = .level))
960      		_Dbg_print_frame  "${.level}" "$0" "${.sh.file}" "${.sh.lineno}" "${.sh.command##* }" "$@"
961	done
962}
963
964((baseline=LINENO+2))
965trap '_Dbg_debug_trap_handler' DEBUG
966.  $tmp  foo bar
967trap '' DEBUG
968
969caller() {
970  integer .level=.sh.level .max=.sh.level-1
971  while((--.level>=0))
972  do
973      ((.sh.level = .level))
974      print -r -- "${.sh.lineno}"
975  done
976}
977bar() { caller;}
978set -- $(bar)
979[[ $1 == $2 ]] && err_exit ".sh.inline optimization bug"
980( $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'
981exit $((Errors))
982