trap2.0 revision 194517
1126288Smtm# $FreeBSD: head/tools/regression/bin/sh/builtins/trap2.0 194517 2009-06-19 22:15:59Z jilles $
298186Sgordon# This is really a test for outqstr(), which is readily accessible via trap.
378344Sobrien
498186Sgordonruntest()
578344Sobrien{
678344Sobrien	teststring=$1
778344Sobrien	trap -- "$teststring" USR1
878344Sobrien	traps=$(trap)
978344Sobrien	if [ "$teststring" != "-" ] && [ -z "$traps" ]; then
1078344Sobrien		# One possible reading of POSIX requires the above to return an
1178344Sobrien		# empty string because backquote commands are executed in a
1278344Sobrien		# subshell and subshells shall reset traps. However, an example
1378344Sobrien		# in the normative description of the trap builtin shows the
1478344Sobrien		# same usage as here, it is useful and our /bin/sh allows it.
1578344Sobrien		echo '$(trap) is broken'
1678344Sobrien		exit 1
1778344Sobrien	fi
1878344Sobrien	trap - USR1
1978344Sobrien	eval "$traps"
2078344Sobrien	traps2=$(trap)
2178344Sobrien	if [ "$traps" != "$traps2" ]; then
2278344Sobrien		echo "Mismatch for '$teststring'"
2378344Sobrien		exit 1
2478344Sobrien	fi
2578344Sobrien}
2678344Sobrien
2778344Sobrienruntest 'echo'
2878344Sobrienruntest 'echo hi'
2978344Sobrienruntest "'echo' 'hi'"
3078344Sobrienruntest '"echo" $PATH'
3178344Sobrienruntest '\echo "$PATH"'
3278344Sobrienruntest ' 0'
3378344Sobrienruntest '0 '
3478344Sobrienruntest ' 1'
3578344Sobrienruntest '1 '
3678344Sobrieni=1
3778344Sobrienwhile [ $i -le 127 ]; do
3878344Sobrien	c=$(printf \\"$(printf %o $i)")
3978344Sobrien	if [ $i -lt 48 ] || [ $i -gt 57 ]; then
4078344Sobrien		runtest "$c"
4178344Sobrien	fi
4278344Sobrien	runtest " $c$c"
4398186Sgordon	runtest "a$c"
4498186Sgordon	i=$((i+1))
4598186Sgordondone
4698186SgordonIFS=,
4798186Sgordonruntest ' '
4898186Sgordonruntest ','
49103018Sgordonunset IFS
50124832Smtmruntest ' '
51124832Smtm
5298186Sgordonexit 0
53103018Sgordon