Skip to content

Commit

Permalink
[spec/builtin-eval-source] Regression tests for issue #395.
Browse files Browse the repository at this point in the history
- spec/builtin-trap: Re-organize tests.
  • Loading branch information
Andy Chu committed Jul 6, 2019
1 parent 8441c65 commit 3596e72
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion osh/cmd_exec.py
Expand Up @@ -1244,7 +1244,7 @@ def MaybeRunExitTrap(self):
Whether we should use the status of the handler.
This is odd behavior, but all bash/dash/mksh seem to agree on it.
See cases 11 and 12 in builtin-trap.test.sh.
See cases 7-10 in builtin-trap.test.sh.
"""
handler = self.traps.get('EXIT')
if handler:
Expand Down
15 changes: 15 additions & 0 deletions spec/builtin-eval-source.test.sh
Expand Up @@ -167,3 +167,18 @@ echo status=$?
path
status=0
## END

#### exit within eval (regression)
eval 'exit 42'
echo 'should not get here'
## stdout-json: ""
## status: 42


#### exit within source (regression)
cd $TMP
echo 'exit 42' > lib.sh
. ./lib.sh
echo 'should not get here'
## stdout-json: ""
## status: 42
37 changes: 23 additions & 14 deletions spec/builtin-trap.test.sh
Expand Up @@ -50,7 +50,7 @@ echo status=$?
## BUG dash/bash status: 0
## BUG dash/bash stdout: status=0

#### trap EXIT
#### trap EXIT calling exit
cleanup() {
echo "cleanup [$@]"
exit 42
Expand All @@ -59,6 +59,28 @@ trap 'cleanup x y z' EXIT
## stdout: cleanup [x y z]
## status: 42

#### trap EXIT return status ignored
cleanup() {
echo "cleanup [$@]"
return 42
}
trap 'cleanup x y z' EXIT
## stdout: cleanup [x y z]
## status: 0

#### trap EXIT with PARSE error
trap 'echo FAILED' EXIT
for
## stdout: FAILED
## status: 2
## OK mksh status: 1

#### trap EXIT with PARSE error and explicit exit
trap 'echo FAILED; exit 0' EXIT
for
## stdout: FAILED
## status: 0

#### trap DEBUG
debuglog() {
echo "debuglog [$@]"
Expand Down Expand Up @@ -142,19 +164,6 @@ err [x y] 1
3
## END

#### trap with PARSE error (implicit exit)
trap 'echo FAILED' EXIT
for
## stdout: FAILED
## status: 2
## OK mksh status: 1

#### trap with PARSE error with explicit exit
trap 'echo FAILED; exit 0' EXIT
for
## stdout: FAILED
## status: 0

#### trap 0 is equivalent to EXIT
# not sure why this is, but POSIX wants it.
trap 'echo EXIT' 0
Expand Down

0 comments on commit 3596e72

Please sign in to comment.