Code Monkey home page Code Monkey logo

Comments (3)

mgree avatar mgree commented on May 26, 2024

Thanks for the bug report! (Quick tip: saying someone's software "doesn't actually work" when you've found a single bug isn't the nicest way to say hello.)

I suspect this is an issue with exit-code carryover; I'll take a look soon.

from smoosh.

tucak avatar tucak commented on May 26, 2024

I took a look, it is. When run_command returns with a Call to step_eval, the error code is still set to 1 and the error checking makes it fail. As far as I can tell, keeping the error code is the right thing to do:

$ tests/cmp/test.sh 'pe() { echo 0; }; false; pe'
      smoosh: OUT [1] ERR [] EC [0]
  bash-posix: OUT [1] ERR [] EC [0]
        bash: OUT [1] ERR [] EC [0]
        dash: OUT [1] ERR [] EC [0]
   zsh-posix: OUT [1] ERR [] EC [0]
         zsh: OUT [1] ERR [] EC [0]
         osh: OUT [1] ERR [] EC [0]
        mksh: OUT [1] ERR [] EC [0]
         ksh: OUT [1] ERR [] EC [0]
  yash-posix: OUT [1] ERR [] EC [0]
        yash: OUT [1] ERR [] EC [0]

Making Call a special case works and does not seem to break any of the working tests:

diff --git a/src/semantics.lem b/src/semantics.lem
index d838ca4..e8a221f 100644
--- a/src/semantics.lem
+++ b/src/semantics.lem
@@ -894,13 +894,18 @@ and step_eval s0 checked stmt =
         not opts.force_simple_command && 
         not (is_interactive s1)) (* per table in 2.8.1 *)
      in
+     let is_call stms =
+       match stms with
+       | Call _ _ _ _ _ -> true
+       | _ -> false
+     end in
      (* load exported variables, perform assignments *)
      let env = Map.fromList assigns in
      match run_command s1 opts checked prog args env with
      | Right (s2, stmt', restore) -> 
         (XSSimple ("ran " ^ string_of_symbolic_string prog), 
          s2, 
-         if catching_errors && s2.sh.exit_code <> 0
+         if catching_errors && s2.sh.exit_code <> 0 && not (is_call stmt')
          then Exit
          else if restore 
          then pushredir stmt' saved_fds 

But maybe there's a better way to fix this.

from smoosh.

mgree avatar mgree commented on May 26, 2024

It's not just functions: the Wait that gets generated from actual commands also causes early exit.

$ set -e
$ false && true; /usr/bin/true
[EXIT]

I think the right solution is to only do the exit code test when stmt' is Done (and maybe other terminating control... will need to test).

from smoosh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.