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

139 lines, 69 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
69trap-with-errexit() {
70 local sh=${1:-bin/osh}
71
72 # This can't raise
73 $sh -x -c 'set -e; trap "echo false; false" INT; sleep 5'
74}
75
76two-traps-return() {
77 local sh=${1:-bin/osh}
78
79 set +o errexit
80
81 $sh -x -c '
82trap "echo int; return 44" INT
83trap "echo exit; return 55" EXIT
84sleep 5
85'
86 # bash gives 130?
87 echo "$sh status=$?"
88}
89
90two-traps-exit() {
91 local sh=${1:-bin/osh}
92
93 set +o errexit
94
95 $sh -x -c '
96trap "echo int; exit 44" INT
97trap "echo exit; exit 55" EXIT
98sleep 5
99'
100 # bash gives 130?
101 echo "$sh status=$?"
102}
103
104two-traps-status() {
105 local sh=${1:-bin/osh}
106
107 set +o errexit
108
109 $sh -x -c '
110trap "echo int; ( exit 44 )" INT
111trap "echo exit; ( exit 55 )" EXIT
112sleep 5
113'
114 # bash gives 130?
115 echo "$sh status=$?"
116}
117
118trap-line() {
119 echo outer line=$LINENO
120 trap 'echo "trap line=$LINENO"' INT # shows line 1
121 sleep 5
122 echo hi
123}
124
125bug-1853() {
126 local sh=${1:-bin/osh}
127
128 $sh -c 'trap "echo hi" EXIT; $(which true)'
129
130 echo --
131 # NEWLINE
132 $sh -c 'trap "echo hi" EXIT; $(which true)
133'
134
135 echo --
136 $sh -c 'trap "echo hi" EXIT; $(which true); echo last'
137}
138
139"$@"