Skip to content

Commit 58a6842

Browse files
committed
[spec/builtin-trap] Add test case for ignored traps in subshells
POSIX specifies that if the action of trap is null the shell shall ignore each specified condition (with SIG_IGN). oils doesn't do it. POSIX also says: > When a subshell is entered, traps that are not being ignored shall > be set to the default actions, except in the case of a command > substitution containing only a single trap command, when the traps > need not be altered. `dash` and `bash` always reset traps (except ignored ones).
1 parent ad3cb1e commit 58a6842

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

spec/builtin-trap.test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ trap | cat
4747
bye
4848
## END
4949

50+
#### ignored signals are active inside subshells
51+
trap '' USR1
52+
subshell_result=$(
53+
trap '' USR2
54+
trap - USR2
55+
trap
56+
)
57+
58+
# NOT a subshell
59+
trap > traps.txt
60+
shell_result=$(cat traps.txt)
61+
62+
if test "$shell_result" = "$subshell_result"; then
63+
echo ok
64+
fi
65+
66+
## STDOUT:
67+
ok
68+
## END
5069

5170
#### trap accepts/ignores --
5271
trap -- 'echo hi' EXIT

0 commit comments

Comments
 (0)