Skip to content

Commit e32bcc4

Browse files
committed
[WIP] Polish previous test and added two more
The tests results are quite cute: ``` case line dash bash mksh ash osh 0 4 FAIL pass FAIL pass FAIL signals aren't reset in subshells if not trapping 1 16 pass pass pass pass pass signals are reset in subshells if trapping 2 41 pass pass pass pass FAIL ignored signals aren't reset in subshells ``` More spec tests on the behavior of signal ignoring can be done. Both `dash` and `mksh` aren't POSIX compliant due to them failing `case 0`. In the case of `osh`, `case 2` is failed because it doesn't give special treatment to `trap '' USR1`. All the other sells set the signals to SIG_IGN, which is different from an empty handler. This also affects the behavior of `exec`, but that's painful to test.
1 parent bd59789 commit e32bcc4

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

spec/builtin-trap.test.sh

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,62 @@
11
## compare_shells: dash bash mksh ash
22
## oils_failures_allowed: 3
33

4-
#### resest signal inside subshell
4+
#### signals aren't reset in subshells if not trapping
5+
trap foo USR1
6+
7+
# just 'trap' doesn't modify the current traps
8+
if test -n "$(trap)"; then
9+
echo ok
10+
fi
11+
12+
## STDOUT:
13+
ok
14+
## END
15+
16+
#### signals are reset in subshells if trapping
17+
trap foo USR1
18+
subshell_result=$(
19+
trap foo USR2
20+
trap
21+
)
22+
trap - USR1
23+
trap foo USR2
24+
25+
# We need to store in order to avoid using subshell expansion.
26+
# We would be comparing subshell against subshell instead of
27+
# parent shell against subshell otherwise.
28+
tmpfile=$(mktemp)
29+
trap > "$tmpfile"
30+
shell_result=$(cat "$tmpfile")
31+
rm "$tmpfile"
32+
33+
if test "$shell_result" = "$subshell_result"; then
34+
echo ok
35+
fi
36+
37+
## STDOUT:
38+
ok
39+
## END
40+
41+
#### ignored signals aren't reset in subshells
542
trap '' USR1
6-
trap foo INT
7-
(
43+
subshell_result=$(
844
trap '' USR2
45+
trap - USR2
946
trap
1047
)
1148

49+
tmpfile=$(mktemp)
50+
trap > "$tmpfile"
51+
shell_result=$(cat "$tmpfile")
52+
rm "$tmpfile"
53+
54+
if test "$shell_result" = "$subshell_result"; then
55+
echo ok
56+
fi
57+
1258
## STDOUT:
13-
trap -- '' SIGUSR1
14-
trap -- '' SIGUSR2
59+
ok
1560
## END
1661

1762
#### trap accepts/ignores --

0 commit comments

Comments
 (0)