| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Junk drawer of repros for bugs
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # test/bugs.sh <function name>
|
| 7 |
|
| 8 | set -o nounset
|
| 9 | set -o pipefail
|
| 10 | set -o errexit
|
| 11 |
|
| 12 | # bugs:
|
| 13 | # echo | tr
|
| 14 | # echo | cat
|
| 15 | # history | less
|
| 16 |
|
| 17 | esrch-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 |
|
| 25 | esrch-code-2() {
|
| 26 | local n=$1
|
| 27 | for i in $(seq $n); do
|
| 28 | echo 'history | less'
|
| 29 | done
|
| 30 | }
|
| 31 |
|
| 32 | esrch-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 |
|
| 47 | trap-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
|
| 59 | trap-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 | spec-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 |
|
| 78 | spec-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 |
|
| 95 | sigint-loop() {
|
| 96 | local sh=${1:-bin/osh}
|
| 97 |
|
| 98 | # Hm _bin/cxx-asan/osh behaves differently here -- it doesn't run it 5 times
|
| 99 | # It quits the first time.
|
| 100 | # bin/osh works like bash/dash/mksh/zsh - they all agree
|
| 101 | $sh -c 'trap "echo int" INT; for i in 1 2 3 4 5; do sleep 1; done'
|
| 102 | }
|
| 103 |
|
| 104 | trap-with-errexit() {
|
| 105 | local sh=${1:-bin/osh}
|
| 106 |
|
| 107 | # This can't raise
|
| 108 | $sh -x -c 'set -e; trap "echo false; false" INT; sleep 5'
|
| 109 | }
|
| 110 |
|
| 111 | two-traps-return() {
|
| 112 | local sh=${1:-bin/osh}
|
| 113 |
|
| 114 | set +o errexit
|
| 115 |
|
| 116 | $sh -x -c '
|
| 117 | trap "echo int; return 44" INT
|
| 118 | trap "echo exit; return 55" EXIT
|
| 119 | sleep 5
|
| 120 | '
|
| 121 | # bash gives 130?
|
| 122 | echo "$sh status=$?"
|
| 123 | }
|
| 124 |
|
| 125 | two-traps-exit() {
|
| 126 | local sh=${1:-bin/osh}
|
| 127 |
|
| 128 | set +o errexit
|
| 129 |
|
| 130 | $sh -x -c '
|
| 131 | trap "echo int; exit 44" INT
|
| 132 | trap "echo exit; exit 55" EXIT
|
| 133 | sleep 5
|
| 134 | '
|
| 135 | # bash gives 130?
|
| 136 | echo "$sh status=$?"
|
| 137 | }
|
| 138 |
|
| 139 | two-traps-status() {
|
| 140 | local sh=${1:-bin/osh}
|
| 141 |
|
| 142 | set +o errexit
|
| 143 |
|
| 144 | $sh -x -c '
|
| 145 | trap "echo int; ( exit 44 )" INT
|
| 146 | trap "echo exit; ( exit 55 )" EXIT
|
| 147 | sleep 5
|
| 148 | '
|
| 149 | # bash gives 130?
|
| 150 | echo "$sh status=$?"
|
| 151 | }
|
| 152 |
|
| 153 | trap-line() {
|
| 154 | echo outer line=$LINENO
|
| 155 | trap 'echo "trap line=$LINENO"' INT # shows line 1
|
| 156 | sleep 5
|
| 157 | echo hi
|
| 158 | }
|
| 159 |
|
| 160 | bug-1853() {
|
| 161 | local sh=${1:-bin/osh}
|
| 162 |
|
| 163 | $sh -c 'trap "echo hi" EXIT; $(which true)'
|
| 164 |
|
| 165 | echo --
|
| 166 | # NEWLINE
|
| 167 | $sh -c 'trap "echo hi" EXIT; $(which true)
|
| 168 | '
|
| 169 |
|
| 170 | echo --
|
| 171 | $sh -c 'trap "echo hi" EXIT; $(which true); echo last'
|
| 172 | }
|
| 173 |
|
| 174 | "$@"
|