From 3596e725f458bb77c3d5e6c670ba79f3c8d5ae8d Mon Sep 17 00:00:00 2001 From: Andy Chu Date: Fri, 5 Jul 2019 11:25:39 -0700 Subject: [PATCH] [spec/builtin-eval-source] Regression tests for issue #395. - spec/builtin-trap: Re-organize tests. --- osh/cmd_exec.py | 2 +- spec/builtin-eval-source.test.sh | 15 +++++++++++++ spec/builtin-trap.test.sh | 37 ++++++++++++++++++++------------ 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/osh/cmd_exec.py b/osh/cmd_exec.py index 1bebd54376..9feae26878 100755 --- a/osh/cmd_exec.py +++ b/osh/cmd_exec.py @@ -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: diff --git a/spec/builtin-eval-source.test.sh b/spec/builtin-eval-source.test.sh index c9f26fab05..b7f9b04277 100755 --- a/spec/builtin-eval-source.test.sh +++ b/spec/builtin-eval-source.test.sh @@ -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 diff --git a/spec/builtin-trap.test.sh b/spec/builtin-trap.test.sh index ac71920298..a2054b17d8 100644 --- a/spec/builtin-trap.test.sh +++ b/spec/builtin-trap.test.sh @@ -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 @@ -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 [$@]" @@ -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