-
Notifications
You must be signed in to change notification settings - Fork 87
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
Properly restore Reline::IOGate in test teardown #593
Conversation
When I run
~/ghq/github.com/ruby/ruby master* ⇣
❯ git diff
diff --git a/test/reline/helper.rb b/test/reline/helper.rb
index bb23893187..0a09185f92 100644
--- a/test/reline/helper.rb
+++ b/test/reline/helper.rb
@@ -21,21 +21,23 @@
module Reline
class <<self
def test_mode(ansi: false)
- remove_const('IOGate') if const_defined?('IOGate')
- const_set('IOGate', ansi ? Reline::ANSI : Reline::GeneralIO)
- if ENV['RELINE_TEST_ENCODING']
- encoding = Encoding.find(ENV['RELINE_TEST_ENCODING'])
- else
- encoding = Encoding::UTF_8
- end
- Reline::GeneralIO.reset(encoding: encoding) unless ansi
- core.config.instance_variable_set(:@test_mode, true)
- core.config.reset
+ @original_iogate = IOGate
+ remove_const('IOGate')
+ const_set('IOGate', ansi ? Reline::ANSI : Reline::GeneralIO)
+ if ENV['RELINE_TEST_ENCODING']
+ encoding = Encoding.find(ENV['RELINE_TEST_ENCODING'])
+ else
+ encoding = Encoding::UTF_8
+ end
+ Reline::GeneralIO.reset(encoding: encoding) unless ansi
+ core.config.instance_variable_set(:@test_mode, true)
+ core.config.reset
end
def test_reset
- remove_const('IOGate') if const_defined?('IOGate')
- const_set('IOGate', Reline::GeneralIO)
+ remove_const('IOGate')
+ const_set('IOGate', @original_iogate)
+ Reline::GeneralIO.reset
Reline.instance_variable_set(:@core, nil)
end
diff --git a/test/reline/test_history.rb b/test/reline/test_history.rb
index ddf8fb1472..390962a633 100644
--- a/test/reline/test_history.rb
+++ b/test/reline/test_history.rb
@@ -3,7 +3,7 @@
class Reline::History::Test < Reline::TestCase
def setup
- Reline.send(:test_mode)
+ Reline.test_mode
end
def teardown
diff --git a/test/reline/test_reline_key.rb b/test/reline/test_reline_key.rb
index fb700a6f2e..7f9a11394a 100644
--- a/test/reline/test_reline_key.rb
+++ b/test/reline/test_reline_key.rb
@@ -3,6 +3,7 @@
class Reline::TestKey < Reline::TestCase
def setup
+ Reline.test_mode
end
def teardown |
I think GeneralIO.reset has a bug. def self.reset(encoding: nil)
@@pasting = false
@@encoding = encoding # if @@encoding is changed to nil
end
def self.encoding
if defined?(@@encoding) # @@encoding is still defined
@@encoding # GeneralIO.encoding returns nil
... It should do remove_class_variable. updated |
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.
Thanks!
(ruby/reline#593) * Properly restore Reline::IOGate in test teardown * GeneralIO.reset should reset class variable existence ruby/reline@c16d33dae5
make test-all TESTS="reline/test_reline.rb irb/test_cmd.rb"
was failing. Pager is shown and test will stop until you enterq
.The reason of the failure is:
This pull request fixes test teardown to restore IOGate correctly.
show-source's test is also fixed in ruby/irb#720