1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Junk drawer of repros for bugs
|
4 | #
|
5 | # Usage:
|
6 | # test/bugs.sh <function name>
|
7 |
|
8 | set -o nounset
|
9 | set -o pipefail
|
10 | set -o errexit
|
11 |
|
12 | # bugs:
|
13 | # echo | tr
|
14 | # echo | cat
|
15 | # history | less
|
16 |
|
17 | esrch-code-1() {
|
18 | local n=$1
|
19 | for i in $(seq $n); do
|
20 | echo 'echo hi | tr a-z A-Z'
|
21 | #echo 'echo hi | cat'
|
22 | done
|
23 | }
|
24 |
|
25 | esrch-code-2() {
|
26 | local n=$1
|
27 | for i in $(seq $n); do
|
28 | echo 'history | less'
|
29 | done
|
30 | }
|
31 |
|
32 | esrch-test() {
|
33 | # I think
|
34 |
|
35 | local osh=bin/osh
|
36 |
|
37 | local osh=_bin/cxx-opt/osh
|
38 | ninja $osh
|
39 |
|
40 | esrch-code-1 1000 | $osh -i
|
41 | }
|
42 |
|
43 | #
|
44 | # Bug #1853 - trap and fork optimizations - also hit by Samuel
|
45 | #
|
46 |
|
47 | trap-1() {
|
48 | local sh=${1:-bin/osh}
|
49 |
|
50 | set +o errexit
|
51 |
|
52 | # This fails to run the trap
|
53 | $sh -x -c 'echo shell=$$; trap "echo int" INT; sleep 5'
|
54 |
|
55 | echo "$sh status=$?"
|
56 | }
|
57 |
|
58 | # Run with bin/ysh -x to show fork opts
|
59 | trap-2() {
|
60 | local sh=${1:-bin/osh}
|
61 | set +o errexit
|
62 |
|
63 | # This runs it
|
64 | $sh -x -c 'echo shell=$$; trap "echo int" INT; sleep 5; echo last'
|
65 |
|
66 | echo "$sh status=$?"
|
67 | }
|
68 |
|
69 | # Does Ctrl-C cause both signal handlers to run? Yes.
|
70 | sigint-parent-child() {
|
71 | local sh=${1:-bin/osh}
|
72 |
|
73 | cat > _tmp/sigint.py <<EOF
|
74 | import os
|
75 | import signal
|
76 | import time
|
77 |
|
78 | def SigInt(x, y):
|
79 | print('CHILD SIGINT')
|
80 |
|
81 | print("child=%d" % os.getpid())
|
82 | signal.signal(signal.SIGINT, SigInt)
|
83 | time.sleep(3)
|
84 | EOF
|
85 |
|
86 | $sh -c 'echo shell=$$; trap "echo SHELL SIGINT" INT; python2 _tmp/sigint.py; echo status=$?'
|
87 | }
|
88 |
|
89 | # ODD RESULTS in spec tests: the handler is NOT run in bash or other shells
|
90 | # The handler IS run in manual testing
|
91 | spec-sig() {
|
92 | ### Run spec test outside the sh-spec framework
|
93 |
|
94 | local sh=${1:-bin/osh}
|
95 | local sig=${2:-int}
|
96 |
|
97 | SH=$sh $sh spec/testdata/builtin-trap-$sig.sh
|
98 | }
|
99 |
|
100 | spec-sig-all() {
|
101 | local sig=${1:-int}
|
102 |
|
103 | # they all run usr1
|
104 | # they differ with respect int - only zsh prints it, and bin/osh
|
105 | #
|
106 | # zsh prints 'int'
|
107 |
|
108 | for sh in bin/osh bash dash mksh zsh; do
|
109 | echo '-----'
|
110 | echo "$sh"
|
111 | echo
|
112 |
|
113 | spec-sig $sh $sig
|
114 | done
|
115 | }
|
116 |
|
117 | sigint-loop() {
|
118 | local sh=${1:-bin/osh}
|
119 |
|
120 | # Hm _bin/cxx-asan/osh behaves differently here -- it doesn't run it 5 times
|
121 | # It quits the first time.
|
122 | # bin/osh works like bash/dash/mksh/zsh - they all agree
|
123 | $sh -c 'trap "echo int" INT; for i in 1 2 3 4 5; do sleep 1; done'
|
124 | }
|
125 |
|
126 | trap-with-errexit() {
|
127 | local sh=${1:-bin/osh}
|
128 |
|
129 | # This can't raise
|
130 | $sh -x -c 'set -e; trap "echo false; false" INT; sleep 5'
|
131 | }
|
132 |
|
133 | two-traps-return() {
|
134 | local sh=${1:-bin/osh}
|
135 |
|
136 | set +o errexit
|
137 |
|
138 | $sh -x -c '
|
139 | trap "echo int; return 44" INT
|
140 | trap "echo exit; return 55" EXIT
|
141 | sleep 5
|
142 | '
|
143 | # bash gives 130?
|
144 | echo "$sh status=$?"
|
145 | }
|
146 |
|
147 | two-traps-exit() {
|
148 | local sh=${1:-bin/osh}
|
149 |
|
150 | set +o errexit
|
151 |
|
152 | $sh -x -c '
|
153 | trap "echo int; exit 44" INT
|
154 | trap "echo exit; exit 55" EXIT
|
155 | sleep 5
|
156 | '
|
157 | # bash gives 130?
|
158 | echo "$sh status=$?"
|
159 | }
|
160 |
|
161 | two-traps-status() {
|
162 | local sh=${1:-bin/osh}
|
163 |
|
164 | set +o errexit
|
165 |
|
166 | $sh -x -c '
|
167 | trap "echo int; ( exit 44 )" INT
|
168 | trap "echo exit; ( exit 55 )" EXIT
|
169 | sleep 5
|
170 | '
|
171 | # bash gives 130?
|
172 | echo "$sh status=$?"
|
173 | }
|
174 |
|
175 | trap-line() {
|
176 | echo outer line=$LINENO
|
177 | trap 'echo "trap line=$LINENO"' INT # shows line 1
|
178 | sleep 5
|
179 | echo hi
|
180 | }
|
181 |
|
182 | bug-1853() {
|
183 | local sh=${1:-bin/osh}
|
184 |
|
185 | $sh -c 'trap "echo hi" EXIT; $(which true)'
|
186 |
|
187 | echo --
|
188 | # NEWLINE
|
189 | $sh -c 'trap "echo hi" EXIT; $(which true)
|
190 | '
|
191 |
|
192 | echo --
|
193 | $sh -c 'trap "echo hi" EXIT; $(which true); echo last'
|
194 | }
|
195 |
|
196 | bug-2078() {
|
197 | local n=${1:-160}
|
198 |
|
199 | { echo 'var x = {'
|
200 | for i in $(seq $n); do
|
201 | echo '"key'$i'": "val"'
|
202 | done
|
203 | echo '}
|
204 | = x
|
205 | = len(x)'
|
206 | } | _bin/cxx-asan/ysh
|
207 | }
|
208 |
|
209 | py-readline() {
|
210 | PYTHONPATH=.:vendor python2 frontend/py_readline.py "$@"
|
211 | }
|
212 |
|
213 | bug-2108() {
|
214 | ### Ctrl-C leads to I/O
|
215 |
|
216 | ./configure --without-readline
|
217 | ninja
|
218 |
|
219 | # Hit Ctrl-C
|
220 | # _bin/cxx-asan/osh
|
221 | }
|
222 |
|
223 | "$@"
|