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

165 lines, 83 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
69spec-sig() {
70 ### Run spec test outside the sh-spec framework
71
72 local sh=${1:-bin/osh}
73 local sig=${2:-int}
74
75 SH=$sh $sh spec/testdata/builtin-trap-$sig.sh
76}
77
78spec-sig-all() {
79 local sig=${1:-int}
80
81 # they all run usr1
82 # they differ with respect int - only zsh prints it, and bin/osh
83 #
84 # zsh prints 'int'
85
86 for sh in bin/osh bash dash mksh zsh; do
87 echo '-----'
88 echo "$sh"
89 echo
90
91 spec-sig $sh $sig
92 done
93}
94
95trap-with-errexit() {
96 local sh=${1:-bin/osh}
97
98 # This can't raise
99 $sh -x -c 'set -e; trap "echo false; false" INT; sleep 5'
100}
101
102two-traps-return() {
103 local sh=${1:-bin/osh}
104
105 set +o errexit
106
107 $sh -x -c '
108trap "echo int; return 44" INT
109trap "echo exit; return 55" EXIT
110sleep 5
111'
112 # bash gives 130?
113 echo "$sh status=$?"
114}
115
116two-traps-exit() {
117 local sh=${1:-bin/osh}
118
119 set +o errexit
120
121 $sh -x -c '
122trap "echo int; exit 44" INT
123trap "echo exit; exit 55" EXIT
124sleep 5
125'
126 # bash gives 130?
127 echo "$sh status=$?"
128}
129
130two-traps-status() {
131 local sh=${1:-bin/osh}
132
133 set +o errexit
134
135 $sh -x -c '
136trap "echo int; ( exit 44 )" INT
137trap "echo exit; ( exit 55 )" EXIT
138sleep 5
139'
140 # bash gives 130?
141 echo "$sh status=$?"
142}
143
144trap-line() {
145 echo outer line=$LINENO
146 trap 'echo "trap line=$LINENO"' INT # shows line 1
147 sleep 5
148 echo hi
149}
150
151bug-1853() {
152 local sh=${1:-bin/osh}
153
154 $sh -c 'trap "echo hi" EXIT; $(which true)'
155
156 echo --
157 # NEWLINE
158 $sh -c 'trap "echo hi" EXIT; $(which true)
159'
160
161 echo --
162 $sh -c 'trap "echo hi" EXIT; $(which true); echo last'
163}
164
165"$@"