]> git.saurik.com Git - apple/shell_cmds.git/blob - sh/tests/builtins/trap2.0
shell_cmds-198.tar.gz
[apple/shell_cmds.git] / sh / tests / builtins / trap2.0
1 # $FreeBSD$
2 # This is really a test for outqstr(), which is readily accessible via trap.
3
4 runtest()
5 {
6 teststring=$1
7 trap -- "$teststring" USR1
8 traps=$(trap)
9 if [ "$teststring" != "-" ] && [ -z "$traps" ]; then
10 # One possible reading of POSIX requires the above to return an
11 # empty string because backquote commands are executed in a
12 # subshell and subshells shall reset traps. However, an example
13 # in the normative description of the trap builtin shows the
14 # same usage as here, it is useful and our /bin/sh allows it.
15 echo '$(trap) is broken'
16 exit 1
17 fi
18 trap - USR1
19 eval "$traps"
20 traps2=$(trap)
21 if [ "$traps" != "$traps2" ]; then
22 echo "Mismatch for '$teststring'"
23 exit 1
24 fi
25 }
26
27 runtest 'echo'
28 runtest 'echo hi'
29 runtest "'echo' 'hi'"
30 runtest '"echo" $PATH'
31 runtest '\echo "$PATH"'
32 runtest ' 0'
33 runtest '0 '
34 runtest ' 1'
35 runtest '1 '
36 i=1
37 while [ $i -le 127 ]; do
38 c=$(printf \\"$(printf %o $i)")
39 if [ $i -lt 48 ] || [ $i -gt 57 ]; then
40 runtest "$c"
41 fi
42 runtest " $c$c"
43 runtest "a$c"
44 i=$((i+1))
45 done
46 IFS=,
47 runtest ' '
48 runtest ','
49 unset IFS
50 runtest ' '
51
52 exit 0