From f204829a08c1941cf7cfafc6013830c581be2180 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Thu, 12 Oct 2023 22:55:41 +0900 Subject: [PATCH] Fix test runner exit bug (#728) * Remove useless test setup and teardown that sets MAIN_CONTEXT to nil * Avoid adding command methods to main object in test --- lib/irb/extend-command.rb | 2 +- test/irb/test_completion.rb | 9 --------- test/irb/test_irb.rb | 6 +++++- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb index cce7f8a4a..514293a43 100644 --- a/lib/irb/extend-command.rb +++ b/lib/irb/extend-command.rb @@ -22,7 +22,7 @@ module ExtendCommandBundle # # Same as IRB.CurrentContext.exit. def irb_exit(ret = 0) - irb_context&.exit(ret) + irb_context.exit(ret) end # Displays current configuration. diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index 2ef893826..840288940 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -6,15 +6,6 @@ module TestIRB class CompletionTest < TestCase - def setup - # make sure require completion candidates are not cached - IRB::BaseCompletor.class_variable_set(:@@files_from_load_path, nil) - end - - def teardown - IRB.conf[:MAIN_CONTEXT] = nil - end - def completion_candidates(target, bind) IRB::RegexpCompletor.new.completion_candidates('', target, '', bind: bind) end diff --git a/test/irb/test_irb.rb b/test/irb/test_irb.rb index e89f2a1c7..b32e857c1 100644 --- a/test/irb/test_irb.rb +++ b/test/irb/test_irb.rb @@ -733,9 +733,13 @@ def @irb.generate_prompt(opens, continue, line_offset) private + def build_binding + Object.new.instance_eval { binding } + end + def build_irb IRB.init_config(nil) - workspace = IRB::WorkSpace.new(TOPLEVEL_BINDING.dup) + workspace = IRB::WorkSpace.new(build_binding) IRB.conf[:VERBOSE] = false IRB::Irb.new(workspace, TestInputMethod.new)