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

176 lines, 87 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 pid=$$; 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 pid=$$; trap "echo int" INT; sleep 5; echo last'
65
66 echo "$sh status=$?"
67}
68
69# ODD RESULTS in spec tests: the handler is NOT run in bash or other shells
70# The handler IS run in manual testing
71spec-sig() {
72 ### Run spec test outside the sh-spec framework
73
74 local sh=${1:-bin/osh}
75 local sig=${2:-int}
76
77 SH=$sh $sh spec/testdata/builtin-trap-$sig.sh
78}
79
80spec-sig-all() {
81 local sig=${1:-int}
82
83 # they all run usr1
84 # they differ with respect int - only zsh prints it, and bin/osh
85 #
86 # zsh prints 'int'
87
88 for sh in bin/osh bash dash mksh zsh; do
89 echo '-----'
90 echo "$sh"
91 echo
92
93 spec-sig $sh $sig
94 done
95}
96
97sigint-loop() {
98 local sh=${1:-bin/osh}
99
100 # Hm _bin/cxx-asan/osh behaves differently here -- it doesn't run it 5 times
101 # It quits the first time.
102 # bin/osh works like bash/dash/mksh/zsh - they all agree
103 $sh -c 'trap "echo int" INT; for i in 1 2 3 4 5; do sleep 1; done'
104}
105
106trap-with-errexit() {
107 local sh=${1:-bin/osh}
108
109 # This can't raise
110 $sh -x -c 'set -e; trap "echo false; false" INT; sleep 5'
111}
112
113two-traps-return() {
114 local sh=${1:-bin/osh}
115
116 set +o errexit
117
118 $sh -x -c '
119trap "echo int; return 44" INT
120trap "echo exit; return 55" EXIT
121sleep 5
122'
123 # bash gives 130?
124 echo "$sh status=$?"
125}
126
127two-traps-exit() {
128 local sh=${1:-bin/osh}
129
130 set +o errexit
131
132 $sh -x -c '
133trap "echo int; exit 44" INT
134trap "echo exit; exit 55" EXIT
135sleep 5
136'
137 # bash gives 130?
138 echo "$sh status=$?"
139}
140
141two-traps-status() {
142 local sh=${1:-bin/osh}
143
144 set +o errexit
145
146 $sh -x -c '
147trap "echo int; ( exit 44 )" INT
148trap "echo exit; ( exit 55 )" EXIT
149sleep 5
150'
151 # bash gives 130?
152 echo "$sh status=$?"
153}
154
155trap-line() {
156 echo outer line=$LINENO
157 trap 'echo "trap line=$LINENO"' INT # shows line 1
158 sleep 5
159 echo hi
160}
161
162bug-1853() {
163 local sh=${1:-bin/osh}
164
165 $sh -c 'trap "echo hi" EXIT; $(which true)'
166
167 echo --
168 # NEWLINE
169 $sh -c 'trap "echo hi" EXIT; $(which true)
170'
171
172 echo --
173 $sh -c 'trap "echo hi" EXIT; $(which true); echo last'
174}
175
176"$@"