Skip to content
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

Improve history test's encoding setting #1022

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions test/irb/test_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
module TestIRB
class HistoryTest < TestCase
def setup
@conf_backup = IRB.conf.dup
@original_verbose, $VERBOSE = $VERBOSE, nil
@tmpdir = Dir.mktmpdir("test_irb_history_")
setup_envs(home: @tmpdir)
@backup_default_external = Encoding.default_external
IRB.conf[:LC_MESSAGES] = IRB::Locale.new
save_encodings
IRB.instance_variable_set(:@existing_rc_name_generators, nil)
end

def teardown
IRB.conf.replace(@conf_backup)
IRB.instance_variable_set(:@existing_rc_name_generators, nil)
teardown_envs
Encoding.default_external = @backup_default_external
restore_encodings
$VERBOSE = @original_verbose
FileUtils.rm_rf(@tmpdir)
end
Expand Down Expand Up @@ -146,7 +149,6 @@ def test_history_concurrent_use_readline
end

def test_history_concurrent_use_not_present
IRB.conf[:LC_MESSAGES] = IRB::Locale.new
IRB.conf[:SAVE_HISTORY] = 1
io = TestInputMethodWithRelineHistory.new
io.class::HISTORY.clear
Expand All @@ -163,9 +165,9 @@ def test_history_concurrent_use_not_present

def test_history_different_encodings
IRB.conf[:SAVE_HISTORY] = 2
Encoding.default_external = Encoding::US_ASCII
locale = IRB::Locale.new("en_US.ASCII")
assert_history(<<~EXPECTED_HISTORY.encode(Encoding::US_ASCII), <<~INITIAL_HISTORY.encode(Encoding::UTF_8), <<~INPUT, locale: locale)
IRB.conf[:LC_MESSAGES] = IRB::Locale.new("en_US.ASCII")
IRB.__send__(:set_encoding, Encoding::US_ASCII.name, override: false)
assert_history(<<~EXPECTED_HISTORY.encode(Encoding::US_ASCII), <<~INITIAL_HISTORY.encode(Encoding::UTF_8), <<~INPUT)
????
exit
EXPECTED_HISTORY
Expand Down Expand Up @@ -234,8 +236,7 @@ def history_concurrent_use_for_input_method(input_method)
end
end

def assert_history(expected_history, initial_irb_history, input, input_method = TestInputMethodWithRelineHistory, locale: IRB::Locale.new)
IRB.conf[:LC_MESSAGES] = locale
def assert_history(expected_history, initial_irb_history, input, input_method = TestInputMethodWithRelineHistory)
actual_history = nil
history_file = IRB.rc_file("_history")
ENV["HOME"] = @tmpdir
Expand Down
Loading