diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-09-14 10:15:32 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-09-14 10:15:45 +0900 |
commit | 9299db49f567025e28082be698e1f624b3e3f3ed (patch) | |
tree | 4486c06fdb1c0eb555cb6d54e317e667ba40adaa /test/irb/test_history.rb | |
parent | b876230e5cad02523105d517dce38e1bf1eec5b5 (diff) | |
download | ruby-9299db49f567025e28082be698e1f624b3e3f3ed.tar.gz |
[ruby/irb] Fix history file saving with concurrent irb sessions when history file doesn't exist
If history file didn't exist when irb was started, @loaded_history_mtime
would be nil. However, if the history file didn't exist before, but it
exists when saving history, that means the history file was modified,
and we should handle it the same way as we handle the other case where
the history file was modified.
Fixes #388
https://github.com/ruby/irb/commit/8d277aafcb
Diffstat (limited to 'test/irb/test_history.rb')
-rw-r--r-- | test/irb/test_history.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index 81b7fe8679..38a002d319 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -158,6 +158,28 @@ module TestIRB end end + def test_history_concurrent_use_not_present + backup_home = ENV["HOME"] + backup_xdg_config_home = ENV.delete("XDG_CONFIG_HOME") + IRB.conf[:SAVE_HISTORY] = 1 + Dir.mktmpdir("test_irb_history_#{$$}") do |tmpdir| + ENV["HOME"] = tmpdir + io = TestInputMethod.new + io.class::HISTORY.clear + io.load_history + io.class::HISTORY.concat(%w"line1 line2") + + history_file = IRB.rc_file("_history") + assert !File.file?(history_file) + File.write(history_file, "line0\n") + io.save_history + assert_equal(%w"line0 line1 line2", File.read(history_file).split) + end + ensure + ENV["HOME"] = backup_home + ENV["XDG_CONFIG_HOME"] = backup_xdg_config_home + end + private def assert_history(expected_history, initial_irb_history, input) |