[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
This commit is contained in:
tomoya ishida 2023-09-28 22:53:25 +09:00 коммит произвёл git
Родитель 20c561fe0c
Коммит d4942546af
3 изменённых файлов: 20 добавлений и 13 удалений

Просмотреть файл

@ -3,7 +3,11 @@ require 'io/wait'
class Reline::GeneralIO
def self.reset(encoding: nil)
@@pasting = false
@@encoding = encoding
if encoding
@@encoding = encoding
elsif defined?(@@encoding)
remove_class_variable(:@@encoding)
end
end
def self.encoding

Просмотреть файл

@ -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

Просмотреть файл

@ -3,6 +3,7 @@ require "reline"
class Reline::TestKey < Reline::TestCase
def setup
Reline.test_mode
end
def teardown