ruby-changes:62610
From: aycabta <ko1@a...>
Date: Tue, 18 Aug 2020 18:57:05 +0900 (JST)
Subject: [ruby-changes:62610] 126e1fc296 (master): [ruby/irb] Make history infinite if set SAVE_HISTORY to negative
https://git.ruby-lang.org/ruby.git/commit/?id=126e1fc296 From 126e1fc2961150a7026b9911a1ed82dbf9557af7 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sat, 8 Aug 2020 20:48:23 +0900 Subject: [ruby/irb] Make history infinite if set SAVE_HISTORY to negative https://github.com/ruby/irb/commit/824473e880 diff --git a/lib/irb/ext/save-history.rb b/lib/irb/ext/save-history.rb index 2d98082..3a0703a 100644 --- a/lib/irb/ext/save-history.rb +++ b/lib/irb/ext/save-history.rb @@ -89,7 +89,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/ext/save-history.rb#L89 def save_history return unless self.class.const_defined?(: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] history_file = File.expand_path(history_file) end @@ -110,7 +110,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/ext/save-history.rb#L110 open(history_file, "w:#{IRB.conf[:LC_MESSAGES].encoding}", 0600) do |f| hist = history.map{ |l| l.split("\n").join("\\\n") } 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' # Do nothing because the bignum should be treated as inifinity end diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index a2554fa..bd03217 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -75,6 +75,29 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_history.rb#L75 HISTORY_FILE 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 def launch_irb_with_irbrc_and_irb_history(irbrc, irb_history) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/