blob: c4a4a90a701ce47d3762038a749b44ea5c9af10e (
plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# $OpenBSD: trap.t,v 1.6 2022/10/16 10:44:06 kn Exp $
#
# Check that I/O redirection failure triggers the ERR trap.
# stderr patterns are minimal to match all of bash, ksh and ksh93.
# Try writing the root directory to guarantee EISDIR.
#
name: failed-redirect-triggers-ERR-restricted
description:
Check that restricted mode prevents valid redirections that may write.
arguments: !-r!
stdin:
trap 'echo ERR' ERR
true >/dev/null
expected-stdout:
ERR
expected-stderr-pattern:
/restricted/
expected-exit: e != 0
---
name: failed-redirect-triggers-ERR-command
description:
Redirect standard output for a single command.
stdin:
trap 'echo ERR' ERR
true >/
expected-stdout:
ERR
expected-stderr-pattern:
/Is a directory/
expected-exit: e != 0
---
name: failed-redirect-triggers-ERR-permanent
description:
Permanently redirect standard output of the shell without execution.
stdin:
trap 'echo ERR' ERR
exec >/
expected-stdout:
ERR
expected-stderr-pattern:
/Is a directory/
expected-exit: e != 0
---
#
# Check that the errexit option
# a) does not interfere with running traps and
# b) propagates a non-zero exit status from traps.
# Check that traps are run in the same order in which they were triggered.
#
name: failed-ERR-runs-EXIT
# XXX remove once bin/ksh/main.c r1.52 is backed out *AND* a new fix is in
# XXX enable once bin/ksh/main.c r1.52 is backed out
#expected-fail: yes
description:
Check that EXIT runs under errexit even if ERR failed.
arguments: !-e!
stdin:
trap 'echo ERR ; false' ERR
trap 'echo EXIT' EXIT
false
expected-stdout:
ERR
EXIT
expected-exit: e != 0
---
name: errexit-aborts-EXIT
# XXX remove once bin/ksh/main.c r1.52 is backed out
expected-fail: yes
description:
Check that errexit makes EXIT exit early.
arguments: !-e!
stdin:
trap 'echo ERR' ERR
trap 'false ; echo EXIT' EXIT
expected-stdout:
ERR
expected-exit: e != 0
---
name: EXIT-triggers-ERR
# XXX remove once bin/ksh/main.c r1.52 is backed out
expected-fail: yes
description:
Check that ERR runs under errexit if EXIT failed.
arguments: !-e!
stdin:
trap 'echo ERR' ERR
trap 'echo EXIT ; false' EXIT
true
expected-stdout:
EXIT
ERR
expected-exit: e != 0
---
#
# Check that the errexit option does not interfere with signal handler traps.
#
name: handled-signal-is-no-error
description:
Check that gracefully handling a signal is not treated as error.
arguments: !-e!
stdin:
trap 'echo ERR' ERR
trap 'echo EXIT' EXIT
trap 'echo USR1' USR1
kill -USR1 $$
expected-stdout:
USR1
EXIT
expected-exit: e == 0
---
name: failed-INTR-runs-EXIT
description:
Check that EXIT runs under errexit even if interrupt handling failed.
SIGINT, SIGQUIT, SIGTERM and SIGHUP are handled specially.
XXX Find/explain the difference if the busy loop runs directly, i.e. not
inside a subshell or process ($PROG -c "...").
# XXX should always be passed like PROG
arguments: !-e!
env-setup: !ARGS=-e!
stdin:
exec timeout --preserve-status -s INT -- 0.1s $PROG $ARGS -c '
trap "echo EXIT" EXIT
trap "echo INT ; false" INT
(while : ; do : ; done)
'
expected-stdout:
INT
EXIT
expected-exit: e != 0
---
|