Skip to content

Commit

Permalink
Add return the last status to if statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
buty4649 committed Jan 16, 2021
1 parent 27d8756 commit 37bcce5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bintest/07_if_statement.rb
Expand Up @@ -53,4 +53,16 @@
assert_equal("tp2\n", File.read(tp2), command)
end
end

command = "if true; then echo FOO; fi && echo BAR"
assert_equal("FOO\nBAR\n", run(command)[0], command)

command = "if true; then echo FOO; false; fi && echo BAR"
assert_equal("FOO\n", run(command)[0], command)

command = "if false; then echo NG; fi || echo OK"
assert_equal("OK\n", run(command)[0], command)

command = "if true; then echo OK; fi | cat"
assert_equal("OK\n", run(command)[0], command)
end
3 changes: 3 additions & 0 deletions mrblib/reddish/executor.rb
Expand Up @@ -165,6 +165,9 @@ def if_statement(statement)
elsif statement.cmd2
exec(statement.cmd2)
end

# return last status
$?
end
end

Expand Down

0 comments on commit 37bcce5

Please sign in to comment.