OILS / test / bugs.sh View on Github | oilshell.org

196 lines, 92 significant
1#!/usr/bin/env bash
2#
3# Junk drawer of repros for bugs
4#
5# Usage:
6# test/bugs.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12# bugs:
13# echo | tr
14# echo | cat
15# history | less
16
17esrch-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
25esrch-code-2() {
26 local n=$1
27 for i in $(seq $n); do
28 echo 'history | less'
29 done
30}
31
32esrch-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
47trap-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
59trap-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.
70sigint-parent-child() {
71 local sh=${1:-bin/osh}
72
73 cat > _tmp/sigint.py <<EOF
74import os
75import signal
76import time
77
78def SigInt(x, y):
79 print('CHILD SIGINT')
80
81print("child=%d" % os.getpid())
82signal.signal(signal.SIGINT, SigInt)
83time.sleep(3)
84EOF
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
91spec-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
100spec-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
117sigint-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
126trap-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
133two-traps-return() {
134 local sh=${1:-bin/osh}
135
136 set +o errexit
137
138 $sh -x -c '
139trap "echo int; return 44" INT
140trap "echo exit; return 55" EXIT
141sleep 5
142'
143 # bash gives 130?
144 echo "$sh status=$?"
145}
146
147two-traps-exit() {
148 local sh=${1:-bin/osh}
149
150 set +o errexit
151
152 $sh -x -c '
153trap "echo int; exit 44" INT
154trap "echo exit; exit 55" EXIT
155sleep 5
156'
157 # bash gives 130?
158 echo "$sh status=$?"
159}
160
161two-traps-status() {
162 local sh=${1:-bin/osh}
163
164 set +o errexit
165
166 $sh -x -c '
167trap "echo int; ( exit 44 )" INT
168trap "echo exit; ( exit 55 )" EXIT
169sleep 5
170'
171 # bash gives 130?
172 echo "$sh status=$?"
173}
174
175trap-line() {
176 echo outer line=$LINENO
177 trap 'echo "trap line=$LINENO"' INT # shows line 1
178 sleep 5
179 echo hi
180}
181
182bug-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"$@"