зеркало из https://github.com/github/ruby.git
[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:
Родитель
20c561fe0c
Коммит
d4942546af
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче