Skip to content

Commit 48a84fa

Browse files
committed
Add minimal test for Ruby::Box mode
1 parent 367779c commit 48a84fa

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

test/irb/helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def teardown
139139
end
140140
end
141141

142-
def run_ruby_file(&block)
142+
def run_ruby_file(timeout: TIMEOUT_SEC, &block)
143143
cmd = [EnvUtil.rubybin, "-I", LIB, @ruby_file.to_path]
144144
tmp_dir = Dir.mktmpdir
145145

@@ -156,7 +156,7 @@ def run_ruby_file(&block)
156156
envs_for_spawn = @envs.merge('TERM' => 'dumb', 'TEST_IRB_FORCE_INTERACTIVE' => 'true')
157157

158158
PTY.spawn(envs_for_spawn, *cmd) do |read, write, pid|
159-
Timeout.timeout(TIMEOUT_SEC) do
159+
Timeout.timeout(timeout) do
160160
while line = safe_gets(read)
161161
lines << line
162162

test/irb/test_irb.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,4 +963,34 @@ def bar
963963
end
964964
end
965965
end
966+
967+
class ContextModeTest < TestIRB::IntegrationTestCase
968+
# RUBY_BOX=1 may need more time to start IRB
969+
TIMEOUT_SEC = TestIRB::IntegrationTestCase::TIMEOUT_SEC + 5
970+
971+
def test_context_mode_ruby_box
972+
omit if RUBY_VERSION < "4.0.0"
973+
@envs['RUBY_BOX'] = '1'
974+
975+
write_rc <<~'RUBY'
976+
IRB.conf[:CONTEXT_MODE] = 5
977+
RUBY
978+
979+
write_ruby <<~'RUBY'
980+
require 'irb'
981+
puts 'binding.irb' # Mark for breakpoint trigger
982+
IRB.start
983+
p answer2: 1 + 2
984+
RUBY
985+
986+
output = run_ruby_file(timeout: TIMEOUT_SEC) do
987+
type 'class Integer; def +(_other) = 42; end'
988+
type 'p answer1: 1 + 2'
989+
type 'exit'
990+
end
991+
992+
assert_include(output, '{answer1: 42}')
993+
assert_include(output, '{answer2: 3}')
994+
end
995+
end
966996
end

0 commit comments

Comments
 (0)