Skip to content

Commit

Permalink
Properly restore Reline::IOGate in test teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Sep 26, 2023
1 parent 7d2084b commit 307c551
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
26 changes: 14 additions & 12 deletions test/reline/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions test/reline/test_reline_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class Reline::TestKey < Reline::TestCase
def setup
Reline.test_mode
end

def teardown
Expand Down

0 comments on commit 307c551

Please sign in to comment.