summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2023-09-28 22:53:25 +0900
committergit <svn-admin@ruby-lang.org>2023-09-28 13:53:30 +0000
commitd4942546af0e2c0a4b53eaf5d2aeec36187fa5ba (patch)
tree9deaee7c5a2ee81fa2a45f87720aa1f152bcb9bb /test
parent20c561fe0c1194ad4dca265d79f7f8afc0469f3c (diff)
[ruby/reline] Properly restore Reline::IOGate in test teardown
(https://github.com/ruby/reline/pull/593) * Properly restore Reline::IOGate in test teardown * GeneralIO.reset should reset class variable existence https://github.com/ruby/reline/commit/c16d33dae5
Diffstat (limited to 'test')
-rw-r--r--test/reline/helper.rb26
-rw-r--r--test/reline/test_reline_key.rb1
2 files changed, 15 insertions, 12 deletions
diff --git a/test/reline/helper.rb b/test/reline/helper.rb
index bb23893187..fb2262e7f5 100644
--- a/test/reline/helper.rb
+++ b/test/reline/helper.rb
@@ -21,21 +21,23 @@ end
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_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 @@ require "reline"
class Reline::TestKey < Reline::TestCase
def setup
+ Reline.test_mode
end
def teardown