Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple -e scripts should be executed to completion in turn #3674

Open
headius opened this issue Feb 16, 2016 · 0 comments
Open

Multiple -e scripts should be executed to completion in turn #3674

headius opened this issue Feb 16, 2016 · 0 comments
Labels

Comments

@headius
Copy link
Member

headius commented Feb 16, 2016

When you run a Ruby command with multiple -e arguments, those "inline scripts" should be executed to completion, each in turn.

The ordering of END and at_exit is also unexpected here. It appears that CRuby always splices END and at_exit to run at the termination of the top-level script...which in this case happens after both -e scripts have run:

$ ruby23 -e "
BEGIN { puts 0 }
puts :a
END { puts 1 }
at_exit { puts 2 }"
-e "
BEGIN { puts 3 }
puts :b
END { puts 4 }
at_exit { puts 5 }"
0
3
a
b
5
4
2
1

@enebo showed me some examples with required files that also show that END blocks are registered in the same process as at_exit blocks and run in reverse order the same way.

We match some of this ordering, but for cases where exceptional results come out of the scripts, things get a little weird:

$ ruby23 -e "END { raise '1' }; at_exit { raise '2' }" -e "raise 'b'; END { raise '4' }; at_exit { raise '5' }"
-e:1:in `block in <main>': 2 (RuntimeError)
-e:1:in `block in <main>': 1 (RuntimeError)
-e:2:in `<main>': b (RuntimeError)

Here, the second block of code does not get to the point of registering its END and at_exit blocks, so they don't run...ok. But the END and at_exit from the first block of code appear to run before the second block of code fails.

JRuby runs this differently, with the raises in END and at_exit coming after the raise in the second block of code:

$ jruby -e "END { raise '1' }; at_exit { raise '2' }" -e "raise 'b'; END { raise '4' }; at_exit { raise '5' }"
RuntimeError: b
  <top> at -e:2
RuntimeError: 2
  block in -e at -e:1
RuntimeError: 1
  block in -e at -e:1

These ordering behaviors and the multiple -e behavior probably need specs. I will be taking some MRI tests since I don't see these as common cases and they're nontrivial to fix right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant