summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2020-10-11 15:41:57 +0900
committernagachika <nagachika@ruby-lang.org>2020-10-11 15:41:57 +0900
commitd1ba5545513b68d39ca29b578a42bd8d48a7804e (patch)
treee080e3b8ee62eb1a84b1b9788e872d4004b58473
parent48ac73769772317d6c3f864f087ef930a47120d9 (diff)
downloadruby-d1ba5545513b68d39ca29b578a42bd8d48a7804e.tar.gz
merge revision(s) 9718ff62c12c07ecf7f0e234343dca76ee1aa51d,20ad1017017ea736667d86fa0250dc1a39daefa1: [Backport #17211]
Show stdout and stderr when history tests fail Remove system method for E2E testing because depends on ruby command
-rw-r--r--test/irb/test_history.rb146
-rw-r--r--version.h2
2 files changed, 84 insertions, 64 deletions
diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb
index 3591f88f59..392a6afa9a 100644
--- a/test/irb/test_history.rb
+++ b/test/irb/test_history.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: false
require 'test/unit'
require 'irb'
+require 'irb/ext/save-history'
require 'readline'
module TestIRB
@@ -13,133 +14,152 @@ module TestIRB
IRB.conf[:RC_NAME_GENERATOR] = nil
end
+ class TestInputMethod < ::IRB::InputMethod
+ HISTORY = Array.new
+
+ include IRB::HistorySavingAbility
+
+ attr_reader :list, :line_no
+
+ def initialize(list = [])
+ super("test")
+ @line_no = 0
+ @list = list
+ end
+
+ def gets
+ @list[@line_no]&.tap {@line_no += 1}
+ end
+
+ def eof?
+ @line_no >= @list.size
+ end
+
+ def encoding
+ Encoding.default_external
+ end
+
+ def reset
+ @line_no = 0
+ end
+
+ def winsize
+ [10, 20]
+ end
+ end
+
def test_history_save_1
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
- _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
- IRB.conf[:USE_READLINE] = true
- IRBRC
+ IRB.conf[:SAVE_HISTORY] = 1
+ assert_history(<<~EXPECTED_HISTORY, <<~INITIAL_HISTORY, <<~INPUT)
+ exit
+ EXPECTED_HISTORY
1
2
3
4
- IRB_HISTORY
- stdin.write("5\nexit\n")
- end
-
- assert_equal(<<~HISTORY_FILE, result_history_file)
+ INITIAL_HISTORY
+ 5
exit
- HISTORY_FILE
+ INPUT
end
def test_history_save_100
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
- _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] = 100
- IRB.conf[:USE_READLINE] = true
- IRBRC
+ IRB.conf[:SAVE_HISTORY] = 100
+ assert_history(<<~EXPECTED_HISTORY, <<~INITIAL_HISTORY, <<~INPUT)
1
2
3
4
- IRB_HISTORY
- stdin.write("5\nexit\n")
- end
-
- assert_equal(<<~HISTORY_FILE, result_history_file)
+ 5
+ exit
+ EXPECTED_HISTORY
1
2
3
4
+ INITIAL_HISTORY
5
exit
- HISTORY_FILE
+ INPUT
end
def test_history_save_bignum
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
- _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] = 10 ** 19
- IRB.conf[:USE_READLINE] = true
- IRBRC
+ IRB.conf[:SAVE_HISTORY] = 10 ** 19
+ assert_history(<<~EXPECTED_HISTORY, <<~INITIAL_HISTORY, <<~INPUT)
1
2
3
4
- IRB_HISTORY
- stdin.write("5\nexit\n")
- end
-
- assert_equal(<<~HISTORY_FILE, result_history_file)
+ 5
+ exit
+ EXPECTED_HISTORY
1
2
3
4
+ INITIAL_HISTORY
5
exit
- HISTORY_FILE
+ INPUT
end
def test_history_save_minus_as_infinity
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
- _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
- IRB.conf[:USE_READLINE] = true
- IRBRC
+ IRB.conf[:SAVE_HISTORY] = -1 # infinity
+ assert_history(<<~EXPECTED_HISTORY, <<~INITIAL_HISTORY, <<~INPUT)
1
2
3
4
- IRB_HISTORY
- stdin.write("5\nexit\n")
- end
-
- assert_equal(<<~HISTORY_FILE, result_history_file)
+ 5
+ exit
+ EXPECTED_HISTORY
1
2
3
4
+ INITIAL_HISTORY
5
exit
- HISTORY_FILE
+ INPUT
end
private
- def launch_irb_with_irbrc_and_irb_history(irbrc, irb_history)
- result = nil
- result_history = nil
- backup_irbrc = ENV.delete("IRBRC")
+ def assert_history(expected_history, initial_irb_history, input)
+ backup_verbose, $VERBOSE = $VERBOSE, nil
backup_home = ENV["HOME"]
+ IRB.conf[:LC_MESSAGES] = IRB::Locale.new
+ actual_history = nil
Dir.mktmpdir("test_irb_history_#{$$}") do |tmpdir|
ENV["HOME"] = tmpdir
- open(IRB.rc_file, "w") do |f|
- f.write(irbrc)
- end
open(IRB.rc_file("_history"), "w") do |f|
- f.write(irb_history)
+ f.write(initial_irb_history)
end
- with_temp_stdio do |stdin, stdout|
- yield(stdin, stdout)
- stdin.close
- stdout.flush
- system('ruby', '-Ilib', '-Itest', '-W0', '-rirb', '-e', 'IRB.start(__FILE__)', in: stdin.path, out: stdout.path)
- result = stdout.read
- stdout.close
- end
+ io = TestInputMethod.new
+ io.class::HISTORY.clear
+ io.load_history
+ io.class::HISTORY.concat(input.split)
+ io.save_history
+
+ io.load_history
open(IRB.rc_file("_history"), "r") do |f|
- result_history = f.read
+ actual_history = f.read
end
end
- [result, result_history]
+ assert_equal(expected_history, actual_history, <<~MESSAGE)
+ expected:
+ #{expected_history}
+ but actual:
+ #{actual_history}
+ MESSAGE
ensure
+ $VERBOSE = backup_verbose
ENV["HOME"] = backup_home
- ENV["IRBRC"] = backup_irbrc
end
def with_temp_stdio
diff --git a/version.h b/version.h
index 2882be26ff..e74f628b68 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 3
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 138
+#define RUBY_PATCHLEVEL 139
#define RUBY_RELEASE_YEAR 2020
#define RUBY_RELEASE_MONTH 10