freebsd-nq/bin/sh/tests/builtins/trap16.0
Bryan Drewery a59f817491 sh: Fix the trap builtin to be POSIX-compliant for 'trap exit SIG' and 'trap n n...'.
The parser considered 'trap exit INT' to reset the default for both EXIT and
INT. This beahvior is not POSIX compliant. This was avoided if a value was
specified for 'exit', but then disallows exiting with the signal received. A
possible workaround is using ' exit'.

However POSIX does allow this type of behavior if the parameters are all
integers. Fix the handling for this and clarify its support in the manpage
since it is specifically allowed by POSIX.

Differential Revision:	https://reviews.freebsd.org/D2325
Reviewed by:	jilles
MFC after:	2 weeks
2015-04-18 23:49:57 +00:00

21 lines
823 B
Plaintext

# $FreeBSD$
traps=$(${SH} -c 'trap "echo bad" 0; trap - 0; trap')
[ -z "$traps" ] || exit 1
traps=$(${SH} -c 'trap "echo bad" 0; trap "" 0; trap')
expected_traps=$(${SH} -c 'trap "" EXIT; trap')
[ "$traps" = "$expected_traps" ] || exit 2
traps=$(${SH} -c 'trap "echo bad" 0; trap 0; trap')
[ -z "$traps" ] || exit 3
traps=$(${SH} -c 'trap "echo bad" 0; trap -- 0; trap')
[ -z "$traps" ] || exit 4
traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap - 0 1 2; trap')
[ -z "$traps" ] || exit 5
traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap "" 0 1 2; trap')
expected_traps=$(${SH} -c 'trap "" EXIT HUP INT; trap')
[ "$traps" = "$expected_traps" ] || exit 6
traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap 0 1 2; trap')
[ -z "$traps" ] || exit 7
traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap -- 0 1 2; trap')
[ -z "$traps" ] || exit 8