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

125 lines, 63 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 '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 '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-status() {
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
104trap-line() {
105 echo outer line=$LINENO
106 trap 'echo "trap line=$LINENO"' INT # shows line 1
107 sleep 5
108 echo hi
109}
110
111bug-1853() {
112 local sh=${1:-bin/osh}
113
114 $sh -c 'trap "echo hi" EXIT; $(which true)'
115
116 echo --
117 # NEWLINE
118 $sh -c 'trap "echo hi" EXIT; $(which true)
119'
120
121 echo --
122 $sh -c 'trap "echo hi" EXIT; $(which true); echo last'
123}
124
125"$@"