1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/irb] Make history infinite if set SAVE_HISTORY to negative

https://github.com/ruby/irb/commit/824473e880
This commit is contained in:
aycabta 2020-08-08 20:48:23 +09:00
parent ef498a016b
commit 126e1fc296
2 changed files with 25 additions and 2 deletions

View file

@ -89,7 +89,7 @@ module IRB
def save_history def save_history
return unless self.class.const_defined?(:HISTORY) return unless self.class.const_defined?(:HISTORY)
history = self.class::HISTORY history = self.class::HISTORY
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0 if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) != 0
if history_file = IRB.conf[:HISTORY_FILE] if history_file = IRB.conf[:HISTORY_FILE]
history_file = File.expand_path(history_file) history_file = File.expand_path(history_file)
end end
@ -110,7 +110,7 @@ module IRB
open(history_file, "w:#{IRB.conf[:LC_MESSAGES].encoding}", 0600) do |f| open(history_file, "w:#{IRB.conf[:LC_MESSAGES].encoding}", 0600) do |f|
hist = history.map{ |l| l.split("\n").join("\\\n") } hist = history.map{ |l| l.split("\n").join("\\\n") }
begin begin
hist = hist.last(num) if hist.size > num hist = hist.last(num) if hist.size > num and num > 0
rescue RangeError # bignum too big to convert into `long' rescue RangeError # bignum too big to convert into `long'
# Do nothing because the bignum should be treated as inifinity # Do nothing because the bignum should be treated as inifinity
end end

View file

@ -75,6 +75,29 @@ module TestIRB
HISTORY_FILE HISTORY_FILE
end end
def test_history_save_minus_as_infinity
result_output, result_history_file = launch_irb_with_irbrc_and_irb_history(<<~IRBRC, <<~IRB_HISTORY) do |stdin|
IRB.conf[:USE_READLINE] = true
IRB.conf[:SAVE_HISTORY] = -1 # infinity
IRBRC
1
2
3
4
IRB_HISTORY
stdin.write("5\nexit\n")
end
assert_equal(<<~HISTORY_FILE, result_history_file)
1
2
3
4
5
exit
HISTORY_FILE
end
private private
def launch_irb_with_irbrc_and_irb_history(irbrc, irb_history) def launch_irb_with_irbrc_and_irb_history(irbrc, irb_history)