-
Notifications
You must be signed in to change notification settings - Fork 141
Add --context-mode 5: evaluates inside Ruby::Box
#1142
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,15 @@ def initialize(*main) | |
| # Note that this will typically be IRB::TOPLEVEL_BINDING | ||
| # This is to avoid RubyGems' local variables (see issue #17623) | ||
| @binding = TOPLEVEL_BINDING.dup | ||
|
|
||
| when 5 # binding in Ruby::Box | ||
| unless defined?(Ruby::Box) | ||
| puts 'Context-mode 5 (binding in Ruby::Box) requires Ruby 4.0 or later.' | ||
| raise NameError, 'Ruby::Box not defined' | ||
| end | ||
|
|
||
| puts 'Context-mode 5 (binding in Ruby::Box) is experimental. It may be removed or changed without notice.' | ||
| @binding = Ruby::Box.new.eval('Kernel.binding') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about we include a check for the Ruby version?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be a constant defined check instead? If
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a There is one more error case. If Box is not enabled by |
||
| end | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -963,4 +963,34 @@ def bar | |||||
| end | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
| class ContextModeTest < TestIRB::IntegrationTestCase | ||||||
| # RUBY_BOX=1 may need more time to start IRB | ||||||
| TIMEOUT_SEC = TestIRB::IntegrationTestCase::TIMEOUT_SEC + 5 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be
Suggested change
class Foo
TIMEOUT = 10
end
class Bar < Foo
TIMEOUT = self::TIMEOUT + 10
end
puts Bar::TIMEOUT # 20
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it can be even shorter TIMEOUT = TIMEOUT + 5or TIMEOUT += 5but the visual of the code, especially the last one, looks like a constant reassignment. (It's not, though) |
||||||
|
|
||||||
| def test_context_mode_ruby_box | ||||||
| omit if RUBY_VERSION < "4.0.0" | ||||||
| @envs['RUBY_BOX'] = '1' | ||||||
|
|
||||||
| write_rc <<~'RUBY' | ||||||
| IRB.conf[:CONTEXT_MODE] = 5 | ||||||
| RUBY | ||||||
|
|
||||||
| write_ruby <<~'RUBY' | ||||||
| require 'irb' | ||||||
| puts 'binding.irb' # Mark for breakpoint trigger | ||||||
| IRB.start | ||||||
| p answer2: 1 + 2 | ||||||
| RUBY | ||||||
|
|
||||||
| output = run_ruby_file(timeout: TIMEOUT_SEC) do | ||||||
| type 'class Integer; def +(_other) = 42; end' | ||||||
| type 'p answer1: 1 + 2' | ||||||
| type 'exit' | ||||||
| end | ||||||
|
|
||||||
| assert_include(output, '{answer1: 42}') | ||||||
| assert_include(output, '{answer2: 3}') | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Immediate
exitwill makeIRB.start rescue do_somethingnot work as expected