summary refs log tree commit diff
path: root/bin/1sh/tests/builtins/trap2.0
blob: eb17a03ee2d51eec8e4914f67ef9750e55854a79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# $FreeBSD: releng/12.1/bin/sh/tests/builtins/trap2.0 194517 2009-06-19 22:15:59Z jilles $
# This is really a test for outqstr(), which is readily accessible via trap.

runtest()
{
	teststring=$1
	trap -- "$teststring" USR1
	traps=$(trap)
	if [ "$teststring" != "-" ] && [ -z "$traps" ]; then
		# One possible reading of POSIX requires the above to return an
		# empty string because backquote commands are executed in a
		# subshell and subshells shall reset traps. However, an example
		# in the normative description of the trap builtin shows the
		# same usage as here, it is useful and our /bin/sh allows it.
		echo '$(trap) is broken'
		exit 1
	fi
	trap - USR1
	eval "$traps"
	traps2=$(trap)
	if [ "$traps" != "$traps2" ]; then
		echo "Mismatch for '$teststring'"
		exit 1
	fi
}

runtest 'echo'
runtest 'echo hi'
runtest "'echo' 'hi'"
runtest '"echo" $PATH'
runtest '\echo "$PATH"'
runtest ' 0'
runtest '0 '
runtest ' 1'
runtest '1 '
i=1
while [ $i -le 127 ]; do
	c=$(printf \\"$(printf %o $i)")
	if [ $i -lt 48 ] || [ $i -gt 57 ]; then
		runtest "$c"
	fi
	runtest " $c$c"
	runtest "a$c"
	i=$((i+1))
done
IFS=,
runtest ' '
runtest ','
unset IFS
runtest ' '

exit 0